Cassidy has asked for the wisdom of the Perl Monks concerning the following question:
I tried sysread($sock, $input, 3) in hopes that it would kick out if nothing was returned. When I connect to port 25 $input is assinged what it should be(220). If I connect to port 80 (apache doesn't initially send anything) sysread() will block because there is nothing to read. Is there a way to make sysread() kick out if there is nothing to read? Should I be using a different function?
Here is the code ... any ideas?
And if you would rather see it left justified go here.#!/usr/local/bin/perl -w use IO::Socket; $addr="127.0.0.1"; $port="80"; $sock = IO::Socket::INET->new(PeerAddr => "$addr", PeerPort => "$port", Proto => 'tcp', Timeout => '1',); if ($sock) { $sock->autoflush(1); print "I am going into sysread()\n"; $foo = sysread($sock, $input, 3); chomp($input); print "Came out of sysread() with \$input as:\n$input\n\sysread() r +eturned: $foo\n"; $sock->close; if ($input eq "") { print "We have no input. Sendmail must be down. +" } elsif ($input =~ /220/) { print "We seem to have gotten the correct + response\n"; } else { print "Dosn't look like a sendmail port\n"; } } else { print "It didn\'t connect ... must be down\n"; }
Edit kudra, 2001-10-09 Replaced pre with code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sysread()
by pjf (Curate) on Oct 09, 2001 at 06:19 UTC | |
by geektron (Curate) on Oct 09, 2001 at 10:13 UTC | |
|
Re: sysread()
by Fletch (Bishop) on Oct 09, 2001 at 05:26 UTC | |
|
Re: sysread()
by chromatic (Archbishop) on Oct 09, 2001 at 06:04 UTC |