develooper Front page | perl.perl5.porters | Postings from December 2001

[PATCH] because (sys)?read doesn't reset buffers

Thread Next
From:
Nicholas Clark
Date:
December 27, 2001 16:48
Subject:
[PATCH] because (sys)?read doesn't reset buffers
Message ID:
20011228004301.B23373@Bagpuss.unfortu.net
The order of doing things in read and sysread means that on a closed file
handle the buffer is never reset. oops. patch fixes a sloppy test which assumes
that they did

Nicholas Clark

--- ./ext/Socket/socketpair.t.orig	Mon Dec 24 17:44:54 2001
+++ ./ext/Socket/socketpair.t	Fri Dec 28 00:36:06 2001
@@ -60,9 +60,11 @@
 # stream socket, so our writes will become joined:
 my ($buffer, $expect);
 $expect = join '', @right;
+undef $buffer;
 is (read (LEFT, $buffer, length $expect), length $expect, "read on left");
 is ($buffer, $expect, "content what we expected?");
 $expect = join '', @left;
+undef $buffer;
 is (read (RIGHT, $buffer, length $expect), length $expect, "read on right");
 is ($buffer, $expect, "content what we expected?");
 
@@ -97,6 +99,7 @@
 ok (!eof LEFT, "left is not at EOF");
 
 $expect = join '', @gripping;
+undef $buffer;
 is (read (LEFT, $buffer, length $expect), length $expect, "read on left");
 is ($buffer, $expect, "content what we expected?");
 
@@ -124,11 +127,13 @@
 my ($total);
 $total = join '', @right;
 foreach $expect (@right) {
+  undef $buffer;
   is (sysread (LEFT, $buffer, length $total), length $expect, "read on left");
   is ($buffer, $expect, "content what we expected?");
 }
 $total = join '', @left;
 foreach $expect (@left) {
+  undef $buffer;
   is (sysread (RIGHT, $buffer, length $total), length $expect, "read on right");
   is ($buffer, $expect, "content what we expected?");
 }
@@ -142,6 +147,7 @@
   local $SIG{ALRM} = sub { $alarmed = 1; };
   print "# Approximate forever as 3 seconds. Wait 'forever'...\n";
   alarm 3;
+  undef $buffer;
   is (sysread (RIGHT, $buffer, 1), undef,
       "read on right should be interrupted");
   is ($alarmed, 1, "alarm should have fired");
@@ -156,6 +162,7 @@
 
 $total = join '', @gripping;
 foreach $expect (@gripping) {
+  undef $buffer;
   is (sysread (LEFT, $buffer, length $total), length $expect, "read on left");
   is ($buffer, $expect, "content what we expected?");
 }

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About