Hallowed Monks, I would appreciate if you could please help me figure this off. To set the stage, I am compiling and running my programs on Win-2003 server that has Activestate Perl v5.10.0 installed. I am currently writing a multitasking server in Perl that is implementing a custom app level protocol. I am using the following modules (only the related ones are mentioned):
use Log::Log4perl qw( get_logger :levels ); use Socket; use POSIX (":sys_wait_h"); use IO::Handle;
A code snippet that creates my socket is listed below:
# 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); }
I now do an accept on my SERVER filehandle to accept CLIENT's and make the CLIENT filehandle autoflush as so:
CLIENT->autoflush (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.

In reply to Buffering & Network Programming Reads and Writes!! by MarkovChain

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.