From: minima <minima>
Date: Fri, 30 Mar 2001 14:46:29 +0000 (+0000)
Subject: fix non-blocking so that it actually doesn't block!
X-Git-Tag: R_1_47~72
X-Git-Url: http://dxspider.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=503b6b1f503860def06f4e2121b0367e856081cd;p=spider.git

fix non-blocking so that it actually doesn't block!
---

diff --git a/Changes b/Changes
index 85abff6e..166b28ea 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 30Mar01=======================================================================
 1. fix errors on accept in ExtMsg and in Msg
+2. fix the non-blocking problems of connects (and other things in general).
 29Mar01=======================================================================
 1. add better tracking of AGW circuits (possibly)
 2. add set and unset/agwmonitor (ing) [for all the notice it seems to take]
diff --git a/perl/ExtMsg.pm b/perl/ExtMsg.pm
index be21d958..ae6c8a4c 100644
--- a/perl/ExtMsg.pm
+++ b/perl/ExtMsg.pm
@@ -126,6 +126,8 @@ sub new_client {
 	if ($sock) {
 		my $conn = $server_conn->new($server_conn->{rproc});
 		$conn->{sock} = $sock;
+		Msg::blocking($sock, 0);
+		$conn->{blocking} = 0;
 		
 		my ($rproc, $eproc) = &{$server_conn->{rproc}} ($conn, $conn->{peerhost} = $sock->peerhost(), $conn->{peerport} = $sock->peerport());
 		if ($eproc) {
diff --git a/perl/Msg.pm b/perl/Msg.pm
index 1ed5377c..aa5edc48 100644
--- a/perl/Msg.pm
+++ b/perl/Msg.pm
@@ -16,7 +16,7 @@ use IO::Socket;
 use DXDebug;
 use Timer;
 
-use vars qw(%rd_callbacks %wt_callbacks %er_callbacks $rd_handles $wt_handles $er_handles $now %conns $noconns);
+use vars qw(%rd_callbacks %wt_callbacks %er_callbacks $rd_handles $wt_handles $er_handles $now %conns $noconns $blocking_supported);
 
 %rd_callbacks = ();
 %wt_callbacks = ();
@@ -26,14 +26,19 @@ $wt_handles   = IO::Select->new();
 $er_handles   = IO::Select->new();
 
 $now = time;
-my $blocking_supported = 0;
 
 BEGIN {
     # Checks if blocking is supported
     eval {
-        require POSIX; POSIX->import(qw (F_SETFL F_GETFL O_NONBLOCK));
+        require POSIX; POSIX->import(qw(O_NONBLOCK F_SETFL F_GETFL))
     };
-    $blocking_supported = 1 unless $@;
+	if ($@) {
+		print STDERR "POSIX Blocking *** NOT *** supported $@\n";
+	} else {
+		$blocking_supported = 1;
+		print STDERR "POSIX Blocking enabled\n";
+	}
+
 
 	# import as many of these errno values as are available
 	eval {
@@ -155,10 +160,8 @@ sub connect {
 	my $proto = getprotobyname('tcp');
 	$sock->socket(AF_INET, SOCK_STREAM, $proto) or return undef;
 	
-	if ($conn->{blocking}) {
-		blocking($sock, 0);
-		$conn->{blocking} = 0;
-	}
+	blocking($sock, 0);
+	$conn->{blocking} = 0;
 
 	my $ip = gethostbyname($to_host);
 #	my $r = $sock->connect($to_port, $ip);
@@ -394,6 +397,8 @@ sub new_client {
 	if ($sock) {
 		my $conn = $server_conn->new($server_conn->{rproc});
 		$conn->{sock} = $sock;
+		blocking($sock, 0);
+		$conn->{blocking} = 0;
 		my ($rproc, $eproc) = &{$server_conn->{rproc}} ($conn, $conn->{peerhost} = $sock->peerhost(), $conn->{peerport} = $sock->peerport());
 		$conn->{sort} = 'Incoming';
 		if ($eproc) {