reduce unnecessary calls to fcntl() while reading from the socket
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 28 Jul 2009 20:27:42 +0000 (20:27 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 28 Jul 2009 20:27:42 +0000 (20:27 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1729 9efc2488-bf62-4759-914b-345cdb29e865

src/perl/lib/OpenSRF/Transport/SlimJabber/XMPPReader.pm

index 7630635..c2d5cbb 100644 (file)
@@ -208,13 +208,15 @@ sub wait {
     # now slurp the data off the socket
     my $buf;
     my $read_size = 1024;
+    my $nonblock = 0;
     while(my $n = sysread($socket, $buf, $read_size)) {
         $self->{parser}->parse_more($buf) if $buf;
         if($n < $read_size or $self->peek_msg) {
-            set_block($socket);
+            set_block($socket) if $nonblock;
             last;
         }
-        set_nonblock($socket);
+        set_nonblock($socket) unless $nonblock;
+        $nonblock = 1;
     }
 
     return $self->next_msg;