Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Simple proxy: Net::Tcp::Server vs. IO::Connectby dd-b (Monk) |
on Sep 16, 2011 at 23:21 UTC ( [id://926500]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|