dash2 has asked for the wisdom of the Perl Monks concerning the following question:
The practical side: I have a load of sockets from which I am reading. They are IO::Socket objects attached to an IO::Select. I want to loop through them using while (@handles =IO::Select->select ($sel, undef, $self, 1) ) and read a line at a time. The idea is, it is faster to do this than to read each one in turn: I am trying to parallelize my socket reading.
So far, so good... but I have a problem. Normally, with just one socket, I can read the socket "to the end" by using <> in array context. With my new solution, I don't want to read the socket to the end - I just want one line at a time. But I do want to find out when data has finished coming over a socket. Otherwise, I end up going round and round the select() call.
That's the practical question: how do I find out when a data has finished coming over a socket, the same way perl does when I use the angle operator in array context, so as to remove the socket from my IO::Select?
The theoretical question is: what's the underlying mechanism? I know an HTML page is finished cos it says </HTML>. But how does one know a socket is finished? Does it communicate this fact at all? Or are you just supposed to guess because it has stopped talking to you?
Awaiting enlightenment.
dave hj~
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Knowing an IO::Socket handle has
by Everlasting God (Beadle) on Jul 10, 2001 at 18:59 UTC | |
|
Re: Knowing an IO::Socket handle has
by dash2 (Hermit) on Jul 10, 2001 at 16:07 UTC | |
by Anonymous Monk on Jul 10, 2001 at 20:29 UTC | |
|
Re: Knowing an IO::Socket handle has
by kschwab (Vicar) on Jul 10, 2001 at 20:30 UTC |