You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/11/13 22:00:08 UTC

[lucy-commits] svn commit: r1201512 - in /incubator/lucy/trunk/perl/lib/LucyX/Remote: ClusterSearcher.pm SearchClient.pm SearchServer.pm

Author: marvin
Date: Sun Nov 13 21:00:08 2011
New Revision: 1201512

URL: http://svn.apache.org/viewvc?rev=1201512&view=rev
Log:
Change to syswrite/sysread.

Change from Perl-buffered IO to syswrite/sysread on sockets.  Proper error
handling and retries are left as TODOs.

Modified:
    incubator/lucy/trunk/perl/lib/LucyX/Remote/ClusterSearcher.pm
    incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchClient.pm
    incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchServer.pm

Modified: incubator/lucy/trunk/perl/lib/LucyX/Remote/ClusterSearcher.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/LucyX/Remote/ClusterSearcher.pm?rev=1201512&r1=1201511&r2=1201512&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/LucyX/Remote/ClusterSearcher.pm (original)
+++ incubator/lucy/trunk/perl/lib/LucyX/Remote/ClusterSearcher.pm Sun Nov 13 21:00:08 2011
@@ -138,7 +138,8 @@ sub _serialize_request {
 sub _send_request_to_shard {
     my ( $self, $shard_num, $request ) = @_;
     my $sock = $socks{$$self}[$shard_num];
-    print $sock $$request;
+    my $check_val = $sock->syswrite($$request);
+    confess $! unless $check_val == length($$request);
 }
 
 # Retrieve the response from a shard.
@@ -147,11 +148,11 @@ sub _retrieve_response_from_shard {
     my $sock = $socks{$$self}[$shard_num];
     my $packed_len;
     my $serialized;
-    $sock->read( $packed_len, 4 );
+    my $check_val = $sock->sysread( $packed_len, 4 );
+    confess $! unless $check_val == 4;
     my $arg_len = unpack( 'N', $packed_len );
-    my $check_val = read( $sock, $serialized, $arg_len );
-    confess("Tried to read $arg_len bytes, got $check_val")
-        unless ( defined $arg_len and $check_val == $arg_len );
+    $check_val = $sock->sysread( $serialized, $arg_len );
+    confess $! unless $check_val == $arg_len;
     return thaw($serialized);
 }
 

Modified: incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchClient.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchClient.pm?rev=1201512&r1=1201511&r2=1201512&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchClient.pm (original)
+++ incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchClient.pm Sun Nov 13 21:00:08 2011
@@ -78,18 +78,21 @@ sub _rpc {
 
     my $serialized = nfreeze($args);
     my $packed_len = pack( 'N', length($serialized) );
-    print $sock $packed_len, $serialized;
+    my $check_val = $sock->syswrite("$packed_len$serialized");
+    confess $! if $check_val != length($serialized) + 4;
 
     # Bail out if we're either closing or shutting down the server remotely.
     return if $args->{_action} eq 'done';
     return if $args->{_action} eq 'terminate';
 
     # Decode response.
-    $sock->read( $packed_len, 4 );
+    $check_val = $sock->sysread( $packed_len, 4 );
+    confess("Failed to read 4 bytes: $!")
+        unless $check_val == 4;
     my $arg_len = unpack( 'N', $packed_len );
-    my $check_val = read( $sock, $serialized, $arg_len );
-    confess("Tried to read $arg_len bytes, got $check_val")
-        unless ( defined $arg_len and $check_val == $arg_len );
+    $check_val = $sock->sysread( $serialized, $arg_len );
+    confess("Failed to read $arg_len bytes")
+        unless $check_val == $arg_len;
     my $response = thaw($serialized);
     if ( exists $response->{retval} ) {
         return $response->{retval};

Modified: incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchServer.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchServer.pm?rev=1201512&r1=1201511&r2=1201512&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchServer.pm (original)
+++ incubator/lucy/trunk/perl/lib/LucyX/Remote/SearchServer.pm Sun Nov 13 21:00:08 2011
@@ -102,10 +102,11 @@ sub serve {
             else {
                 my $client_sock = $readhandle;
                 my ( $check_val, $buf, $len );
-                $check_val = $client_sock->read( $buf, 4 );
-                confess unless $check_val == 4;
+                $check_val = $client_sock->sysread( $buf, 4 );
+                confess $! unless $check_val == 4;
                 $len = unpack( 'N', $buf );
-                $check_val = $client_sock->read( $buf, $len );
+                $check_val = $client_sock->sysread( $buf, $len );
+                confess $! unless $check_val == $len;
                 my $args = eval { thaw($buf) };
                 confess $@ if $@;
                 confess "Not a hashref" unless reftype($args) eq 'HASH';
@@ -134,7 +135,8 @@ sub serve {
                 my $response   = $dispatch{$method}->( $self, $args );
                 my $frozen     = nfreeze($response);
                 my $packed_len = pack( 'N', length($frozen) );
-                print $client_sock $packed_len . $frozen;
+                $check_val = $client_sock->syswrite("$packed_len$frozen");
+                confess $! unless $check_val == length($frozen) + 4;
             }
         }
     }