Lots of things said in the first reply is actually wrong. select does not have the magic to redirect standard output.
Shocking! pg is usually right, but the first reply is completely accurate and highly educational! Here is a version of the original program with timestamps added:
$queuelength=1;
use Socket;
socket(HANDLE, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
$addr = sockaddr_in(80, INADDR_ANY);
bind(HANDLE, $addr);
listen(HANDLE,$queuelength);
while(true)
{
print "hallo1\n";
print STDERR "before accept ", scalar(localtime), "\n";
accept(NEW_HANDLE, HANDLE);
print STDERR "after accept ", scalar(localtime), "\n";
select(NEW_HANDLE);
print STDERR "after select ", scalar(localtime), "\n";
$line=<NEW_HANDLE>;
print STDERR "after readline ", scalar(localtime), "\n";
print $line;
print STDERR "after print ", scalar(localtime), "\n";
print "hello2\n";
}
__END__
Output:
before accept Sat Oct 11 16:01:55 2003
after accept Sat Oct 11 16:02:44 2003
after select Sat Oct 11 16:02:44 2003
after readline Sat Oct 11 16:02:44 2003
after print Sat Oct 11 16:02:44 2003
before accept Sat Oct 11 16:02:44 2003
after accept Sat Oct 11 16:03:12 2003
after select Sat Oct 11 16:03:12 2003
after readline Sat Oct 11 16:03:12 2003
after print Sat Oct 11 16:03:12 2003
before accept Sat Oct 11 16:03:12 2003
Note that the only pauses are for the accept() call, not select(). And you can see a screen shot with two browser windows as well as the perl program in a DOS box here. The select() call redirects the standard output to a socket which sends is connect to a browser.
|