MarkovChain has asked for the wisdom of the Perl Monks concerning the following question:
A code snippet that creates my socket is listed below:use Log::Log4perl qw( get_logger :levels ); use Socket; use POSIX (":sys_wait_h"); use IO::Handle;
I now do an accept on my SERVER filehandle to accept CLIENT's and make the CLIENT filehandle autoflush as so:# Create our socket. $logger->debug("Making the socket."); socket( SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp') ); $logger->debug("Socket made."); # Set socket properties. $logger->debug("Setting socket options: SO_REUSEADDR."); setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1 ); $logger->debug("Socket options set."); # Bind the socket to our port and all ip's. $logger->debug( "Binding the socket to the specified port $port " . 'and all available IP addresses on the machine.' ); $my_addr = sockaddr_in( $port, INADDR_ANY ); unless ( bind(SERVER, $my_addr ) ) { $logger->fatal("Couldn't bind to $port on this machine. $!"); $logger->fatal('Exiting with an exit code of 1.'); exit(1); } $logger->debug("Binding to port $port successful."); # Initialize our listen queue before getting ready for passive open. $logger->debug('Initialize our listen queue. Setting queue depth to SO +MAXCONN'); unless ( listen( SERVER, SOMAXCONN ) ) { $logger->fatal("Could not initialize listen'er queue for our socke +t: $!"); $logger->fatal('Will exit out with an exit code of 1.'); exit(1); }
This is just fine where all my writes to CLIENT via print work as desired i.e. in line buffered mode. However, the moment I do a read via <CLIENT>, for some reason, the filehandle goes 'cold' again. Every single write to CLIENT after this point is being done in block-buffered mode. I try using the autoflush call but to no avail. I have read a bunch of tutorials including http://perl.plover.com/FAQs/Buffering.html. I also referred to the Camel and the Cookbook but I am getting a bit lost here. I would appreciate any help. Thank you Sir / Madame for your time. P.S: I have tried to keep the post as short as possible.CLIENT->autoflush (1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Buffering & Network Programming Reads and Writes!!
by ikegami (Patriarch) on Apr 09, 2009 at 20:56 UTC | |
by MarkovChain (Sexton) on Apr 13, 2009 at 14:42 UTC | |
by ikegami (Patriarch) on Apr 13, 2009 at 15:50 UTC | |
by MarkovChain (Sexton) on Apr 13, 2009 at 19:25 UTC | |
by ikegami (Patriarch) on Apr 14, 2009 at 02:20 UTC | |
|