Okay, so I'm playing with IO::Socket, since nobody has tried to convince me of the value of higher-level facilities and the examples largely use IO::Socket.

I can listen and connect, and I can put the connected port into non-blocking mode. So that's useful. I can read from it with $client->recv($buf, 512).

So, in a non-blocking read, how do I detect EOF? Or errors? Normally recv() returns undef on error, but the doc on the socket method doesn't mention that. And calling recv() non-blocking when there's no data present returns an empty buffer, same as eof normally does, with no way to distinguish. So I tried calling $client->eof(), and that returns true all the time, which is just wrong; dunno what's up with that.

Maybe using recv() and not just getline is over-complicating things, but eventually I expect the guts of my child process will be a tight loop that copies both directions between two sockets -- read A non-blocking, if data, write B, read B non-blocking, if data, write A, lather, rinse, repeat. Except with eof checks. So not having either side wait for end-of-line, or process the characters, seems cleaner and more efficient.

Should I be using sysread instead of recv, maybe? I can't tell much from the docs. And the perl docs refer to the man pages for underlying system calls in this area a lot, but don't tell how things are mapped; in particular the system calls often have status returns that I can't see how to get from the perl functions. These details are getting very frustrating. The overall plan is simple, and many bits work, but what should be little simple stuff is holding me back a lot.


In reply to Re: Simple proxy: Net::Tcp::Server vs. IO::Connect by dd-b
in thread Simple proxy: Net::Tcp::Server vs. IO::Connect by dd-b

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.