add eval blocks around the ivalid key deletes in export_user
[spider.git] / perl / Msg.pm
index c9ad34338952888b03fa4c563bae15cef172c993..834d2087e7bf71bae6132695146a9fc30ff53d92 100644 (file)
@@ -37,6 +37,7 @@ $now = time;
 BEGIN {
     # Checks if blocking is supported
     eval {
+               local $^W;
         require POSIX; POSIX->import(qw(O_NONBLOCK F_SETFL F_GETFL))
     };
        if ($@ || $main::is_win) {
@@ -50,8 +51,22 @@ BEGIN {
 
        # import as many of these errno values as are available
        eval {
+               local $^W;
                require Errno; Errno->import(qw(EAGAIN EINPROGRESS EWOULDBLOCK));
        };
+
+       unless ($^O eq 'MSWin32') {
+               if ($] >= 5.6) {
+                       eval {
+                               local $^W;
+                               require Socket; Socket->import(qw(IPPROTO_TCP TCP_NODELAY));
+                       };
+               } else {
+                       dbg("IPPROTO_TCP and TCP_NODELAY manually defined");
+                       eval 'sub IPPROTO_TCP {     6 };';
+                       eval 'sub TCP_NODELAY {     1 };';
+               }
+       }
        # http://support.microsoft.com/support/kb/articles/Q150/5/37.asp
        # defines EINPROGRESS as 10035.  We provide it here because some
        # Win32 users report POSIX::EINPROGRESS is not vendor-supported.
@@ -60,7 +75,9 @@ BEGIN {
                eval '*EWOULDBLOCK = *EAGAIN = sub { 10035 };';
                eval '*F_GETFL     = sub {     0 };';
                eval '*F_SETFL     = sub {     0 };';
-               $blocking_supported = 1;
+               eval '*IPPROTO_TCP     = sub {     6 };';
+               eval '*TCP_NODELAY     = sub {     1 };';
+               $blocking_supported = 0;   # it appears that this DOESN'T work :-(
        } 
 }
 
@@ -375,36 +392,31 @@ sub new_server {
        return $self;
 }
 
-eval "use Socket qw(IPPROTO_TCP TCP_NODELAY)";
-if ($@ && !$main::is_win) {
-       sub IPPROTO_TCP {6;}
-       sub TCP_NODELAY {1;};
-}
 
 sub nolinger
 {
        my $conn = shift;
 
-       if (isdbg('sock')) {
-               my ($l, $t) = unpack "ll", getsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER); 
-               my $k = unpack 'l', getsockopt($conn->{sock}, SOL_SOCKET, SO_KEEPALIVE);
-               my $n = unpack "l", getsockopt($conn->{sock}, IPPROTO_TCP, TCP_NODELAY);
-               dbg("Linger is: $l $t, keepalive: $k, nagle: $n");
-       }
-
-       setsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER, pack("ll", 0, 0)) or confess "setsockopt linger: $!";
-       setsockopt($conn->{sock}, SOL_SOCKET, SO_KEEPALIVE, 1) or confess "setsockopt keepalive: $!";
        unless ($main::is_win) {
-               setsockopt($conn->{sock}, IPPROTO_TCP, TCP_NODELAY, 1) or confess "setsockopt: $!";
+               if (isdbg('sock')) {
+                       my ($l, $t) = unpack "ll", getsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER); 
+                       my $k = unpack 'l', getsockopt($conn->{sock}, SOL_SOCKET, SO_KEEPALIVE);
+                       my $n = $main::is_win ? 0 : unpack "l", getsockopt($conn->{sock}, IPPROTO_TCP, TCP_NODELAY);
+                       dbg("Linger is: $l $t, keepalive: $k, nagle: $n");
+               }
+               
+               eval {setsockopt($conn->{sock}, SOL_SOCKET, SO_KEEPALIVE, 1)} or dbg("setsockopt keepalive: $!");
+               eval {setsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER, pack("ll", 0, 0))} or dbg("setsockopt linger: $!");
+               eval {setsockopt($conn->{sock}, IPPROTO_TCP, TCP_NODELAY, 1)} or eval {setsockopt($conn->{sock}, SOL_SOCKET, TCP_NODELAY, 1)} or dbg("setsockopt tcp_nodelay: $!");
+               $conn->{sock}->autoflush(0);
+
+               if (isdbg('sock')) {
+                       my ($l, $t) = unpack "ll", getsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER); 
+                       my $k = unpack 'l', getsockopt($conn->{sock}, SOL_SOCKET, SO_KEEPALIVE);
+                       my $n = $main::is_win ? 0 : unpack "l", getsockopt($conn->{sock}, IPPROTO_TCP, TCP_NODELAY);
+                       dbg("Linger is: $l $t, keepalive: $k, nagle: $n");
+               }
        } 
-       $conn->{sock}->autoflush(0);
-       
-       if (isdbg('sock')) {
-               my ($l, $t) = unpack "ll", getsockopt($conn->{sock}, SOL_SOCKET, SO_LINGER); 
-               my $k = unpack 'l', getsockopt($conn->{sock}, SOL_SOCKET, SO_KEEPALIVE);
-               my $n = unpack "l", getsockopt($conn->{sock}, IPPROTO_TCP, TCP_NODELAY);
-               dbg("Linger is: $l $t, keepalive: $k, nagle: $n");
-       }
 }
 
 sub dequeue
@@ -573,24 +585,35 @@ sub set_event_handler {
 }
 
 sub event_loop {
-    my ($pkg, $loop_count, $timeout) = @_; # event_loop(1) to process events once
+    my ($pkg, $loop_count, $timeout, $wronly) = @_; # event_loop(1) to process events once
     my ($conn, $r, $w, $e, $rset, $wset, $eset);
     while (1) {
  
        # Quit the loop if no handles left to process
-        last unless ($rd_handles->count() || $wt_handles->count());
+               if ($wronly) {
+                       last unless $wt_handles->count();
         
-               ($rset, $wset, $eset) = IO::Select->select($rd_handles, $wt_handles, $er_handles, $timeout);
-               
-        foreach $e (@$eset) {
-            &{$er_callbacks{$e}}($e) if exists $er_callbacks{$e};
-        }
-        foreach $r (@$rset) {
-            &{$rd_callbacks{$r}}($r) if exists $rd_callbacks{$r};
-        }
-        foreach $w (@$wset) {
-            &{$wt_callbacks{$w}}($w) if exists $wt_callbacks{$w};
-        }
+                       ($rset, $wset, $eset) = IO::Select->select(undef, $wt_handles, undef, $timeout);
+                       
+                       foreach $w (@$wset) {
+                               &{$wt_callbacks{$w}}($w) if exists $wt_callbacks{$w};
+                       }
+               } else {
+                       
+                       last unless ($rd_handles->count() || $wt_handles->count());
+        
+                       ($rset, $wset, $eset) = IO::Select->select($rd_handles, $wt_handles, $er_handles, $timeout);
+                       
+                       foreach $e (@$eset) {
+                               &{$er_callbacks{$e}}($e) if exists $er_callbacks{$e};
+                       }
+                       foreach $r (@$rset) {
+                               &{$rd_callbacks{$r}}($r) if exists $rd_callbacks{$r};
+                       }
+                       foreach $w (@$wset) {
+                               &{$wt_callbacks{$w}}($w) if exists $wt_callbacks{$w};
+                       }
+               }
 
                Timer::handler;