I find at least 3 ways to read from a nonblocking socket in perl
$socket->recv
$socket->sysread
POSIX::read($socket,...
looks like 3 different names to the same thing, I read the documentations but I can't find one huge differente. anyone?
sysread
is stream (TCP) oriented (it doesn't care about where one send ends and another begins), and recv
is datagram (UDP) oriented (it does care).
POSIX::read
works on file descriptors, whereas sysread
works on file handles.
The best source for documentation on recv()
is man recvfrom
- it is basically a perl interface to that system call. Note that recv()
is usually used on sockets which are set up non-connection oriented (i.e. a UDP socket), but it may be also be used on connection oriented (i.e. TCP) sockets.
The man differences between read()
, sysread()
and POSIX::read()
are:
read(...)
takes a file handle and the IO is bufferedsysread(...)
takes a file handle and the IO is not bufferedPOSIX::read(...)
takes a file descriptor and the IO is not bufferedA file descriptor is a value (a small integer) that is returned by POSIX::open()
.
Also, you can get the file descriptor of a perl file handle via the fileno()
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With