ph713 has asked for the wisdom of the Perl Monks concerning the following question:
And what that question really boils down to is - for a nonblocking tcp connection, what is the correct way to handle all the possible outcomes of calling $socket->recv($numbytes);.
There's the actual return value we can check for defined-ness, there's the definedness and/or length of the received data versus the $numbytes we asked for, and there's several different relevant errnos which require different sorts of action. it ends up being a matrix of many possibilities and few documented gaurantees... In the case of send() the possibilities are even more complex, but in practice it tends to never fail for reasonably-sized packets on an open connection.
And that one can send or receive a chunk of data with the following calls:my $conn = Acme::Connection->new({ ip_addr => '1.2.3.4', port => 666, def_timeout => 12 });
my $data = $conn->recv(3124); $conn->send($data);
The expected behavior is that $conn->recv(3124) will attempt to receive 3124 bytes of data over the network, and will fail with a timeout exception if that doesn't occur within 12 seconds (set with def_timeout in the constructor).
Similarly, $conn->send($data) should send the contents of $data, and fail with a timeout exception if that doesn't happen in 12 seconds.
I've truncated what used to be here, it was a big peice of ugly code, the current implementation at the time of the question.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: send() + recv() on nonblocking tcp sockets
by salvix (Pilgrim) on Oct 13, 2005 at 21:05 UTC | |
by ph713 (Pilgrim) on Oct 14, 2005 at 05:00 UTC |