Change 14330 by jhi@alpha on 2002/01/18 15:07:49

        Try to make the connect/read/write timeouting.

Affected files ...

.... //depot/perl/ext/Socket/Socket.t#8 edit

Differences ...

==== //depot/perl/ext/Socket/Socket.t#8 (xtext) ====
Index: perl/ext/Socket/Socket.t
--- perl/ext/Socket/Socket.t.~1~        Fri Jan 18 08:15:05 2002
+++ perl/ext/Socket/Socket.t    Fri Jan 18 08:15:05 2002
@@ -9,69 +9,99 @@
        print "1..0\n";
        exit 0;
     }
+    $has_alarm = $Config{d_alarm};
 }
        
 use Socket;
 
 print "1..16\n";
 
+$alarmed = 0;
+sub arm      { $alarmed = 0; alarm(shift) if $has_alarm }
+sub alarmed  { $alarmed = 1 }
+$SIG{ALRM} = 'alarmed'                    if $has_alarm;
+
 if (socket(T,PF_INET,SOCK_STREAM,6)) {
   print "ok 1\n";
+  
+  arm(5);
+  if (connect(T,pack_sockaddr_in(7,inet_aton("localhost")))){
+       arm(0);
 
-  if (connect(T,pack_sockaddr_in(7,inet_aton("localhost")))){
        print "ok 2\n";
 
        print "# Connected to " .
                inet_ntoa((unpack_sockaddr_in(getpeername(T)))[1])."\n";
 
+       arm(5);
        syswrite(T,"hello",5);
+       arm(0);
+
+       arm(5);
        $read = sysread(T,$buff,10);    # Connection may be granted, then closed!
+       arm(0);
+
        while ($read > 0 && length($buff) < 5) {
            # adjust for fact that TCP doesn't guarantee size of reads/writes
+           arm(5);
            $read = sysread(T,$buff,10,length($buff));
+           arm(0);
        }
        print(($read == 0 || $buff eq "hello") ? "ok 3\n" : "not ok 3\n");
   }
   else {
        print "# You're allowed to fail tests 2 and 3 if\n";
        print "# the echo service has been disabled.\n";
-       print "# $!\n";
-       print "ok 2\n";
-       print "ok 3\n";
+       print "# 'Interrupted system call' indicates a hanging echo service.\n";
+       print "# Error: $!\n";
+       print "ok 2 - skipped\n";
+       print "ok 3 - skipped\n";
   }
 }
 else {
-       print "# $!\n";
+       print "# Error: $!\n";
        print "not ok 1\n";
 }
 
 if( socket(S,PF_INET,SOCK_STREAM,6) ){
   print "ok 4\n";
 
+  arm(5);
   if (connect(S,pack_sockaddr_in(7,INADDR_LOOPBACK))){
+        arm(0);
+
        print "ok 5\n";
 
        print "# Connected to " .
                inet_ntoa((unpack_sockaddr_in(getpeername(S)))[1])."\n";
 
+       arm(5);
        syswrite(S,"olleh",5);
+       arm(0);
+
+       arm(5);
        $read = sysread(S,$buff,10);    # Connection may be granted, then closed!
+       arm(0);
+
        while ($read > 0 && length($buff) < 5) {
            # adjust for fact that TCP doesn't guarantee size of reads/writes
+           arm(5);
            $read = sysread(S,$buff,10,length($buff));
+           arm(0);
        }
        print(($read == 0 || $buff eq "olleh") ? "ok 6\n" : "not ok 6\n");
   }
   else {
        print "# You're allowed to fail tests 5 and 6 if\n";
        print "# the echo service has been disabled.\n";
-       print "# $!\n";
-       print "ok 5\n";
-       print "ok 6\n";
+       print "# 'Interrupted system call' indicates a hanging echo service.\n";
+       print "# Error: $!\n";
+       print "ok 5 - skipped\n";
+       print "ok 6 - skipped\n";
   }
 }
 else {
-       print "# $!\n";
+       print "# Error: $!\n";
        print "not ok 4\n";
 }
 
End of Patch.

Reply via email to