Mike:

On Mon, Dec 29, 2014 at 10:23:00AM -0600, Mike wrote:
> Can anyone point me in the direction of more thorough
> documentation for the IO::Socket module? Seems like the
> documentation on perl.org is pretty limited. At least, it
> doesn't feel very thorough to me.
> 
> http://perldoc.perl.org/IO/Socket.html
> 
> For example, what exactly does "timeout" affect?
> 
> This documentation also doesn't explain what values the methods
> accept or how to use them.

I believe that IO::Socket is intended to be a Perl OO wrapper
around the raw UNIX socket concept (and WinSock's concept of an
Internet socket copied from Berkeley's implementation) and its
raw Perl wrapper (e.g., Socket.pm). I guess the documentation
relies on knowledge of this underlying API and/or reference to
its documentation.

There appears to be a "send timeout" and a "receive timeout"
option for UNIX sockets, though the documentation says that not
all implementations support it. Since Perl's OO wrapper only
seems to have one I can only assume that the timeout applies to
both read and write operations on the socket. At least shy of
accessing the source code to see for myself.

...read read read...

It appears that IO::Socket's timeout is unrelated to the
afforementioned send and receive timeout options (though those
could potentially still be accessed using the raw
/(get|set)sockopt/ functions)..

The IO::Socket source appears to construct an IO::Select object
with the timeout value and then waits until you can either read
or write, depending on what's applicable, or the timeout is
elapsed. This appeared to only affect connect() and accept()
methods. Though the documentation cited this by saying that it's
horribly inefficient to do this since the IO::Select object is
constructed just for this one purpose and that using select() or
non-blocking IO is preferred.

Truly understanding the implenetation details may require dipping
into IO::Select's source too and following it all back to C. I
can't be bothered. I think that to understand what's going on
here you need experience programming raw sockets in C.

While raw socket access is a useful skill (mostly for a C
programmer), I think that older and wiser Perl hackers would
encourage the use of higher-level, event-based wrappers for
networking in Perl to save yourself the trouble of reinventing
the square wheel. YMMV. Raw socket access or experience shouldn't
really be necessary if using one of the higher-level wrappers so
you can spare yourself the nightmares if all you need is
networking. :)

Regards,


-- 
Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

Attachment: signature.asc
Description: Digital signature

Reply via email to