Re: sysread & eof
- From: Ben Morrow <ben@xxxxxxxxxxxx>
- Date: Wed, 28 Feb 2007 04:24:09 +0000
Quoth lstouder@xxxxxxxxxxxx:
I'm use IO::Socket on linux to read from a webpage. I don't want to use
LWP::Simple. How would I find the EOF when the web server is finished
sending me the webpage? Here's what I'm using right now:
while (my $res = sysread($sock_in,$buf,$bufsize)) {
syswrite($sock_out,$buf,length($buf));
last if ($res < $bufsize);
}
It works, but obviously, if a webpage has a size that is a multiple of
$bufsize, this will loop forever.
I don't know what makes you think that. Did you try it? sysread returns
0 on EOF.
Note that you should also be checking defined($res), as sysread returns
undef on errors. Depending on how you've opened the socket and your
system, some errors (EINTR and EAGAIN, specifically) are not in fact
errors, but indications that you need to retry the read.
I think you need to read
perldoc -f sysread
and
man 2 read
before you go much further (the latter assumes you are on Unix; this is
the documentation for the C read function which is what Perl's sysread
calls. If you are on some other system you will need to find the
appropriate documentation for yourself).
Ben
--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
ben@xxxxxxxxxxxx Frank Herbert, 'Dune'
.
- References:
- sysread & eof
- From: lucas
- sysread & eof
- Prev by Date: Expect and xterm
- Next by Date: Re: perl bug with references
- Previous by thread: sysread & eof
- Next by thread: FAQ 7.22 How do I create a switch or case statement?
- Index(es):
Relevant Pages
|