As pg points out once you have sent the data you should be able to close the socket. Closing a socket should not lead to the loss of lingering (aka buffered send) data. As he also points out if you don't close your sockets you may use up all the available file descriptors on your system. They will not time out for at least several hours. On Win32 you will only have ~512 by default. On *nix you should have ~1024 so it is quite easy to use them all if you don't close sockets in a process.

Are you using Socket or IO::Socket::INET? Can you show a short test case? You may find benefit setting the TCP_NODELAY flag to bypass Nagle's algorithm. I found this reference to SO_LINGER on the Socket FAQ

Closing a socket: if SO_LINGER has not been called on a socket, then close() is not supposed to discard data. This is true on SVR4.2 (and, apparently, on all non-SVR4 systems) but apparently not on SVR4; the use of either shutdown() or SO_LINGER seems to be required to guarantee delivery of all data.

NB SVR4 systems include Solaris 2.x, SCO ODT 3.0, AIX, A/UX.

Although I agree with pg that it should not happen why not try calling shutdown on the socket before you close it or specifically setting the TCP_NODELAY and SO_LINGER options. You might also try syswrite to send your data, instead of send. This bypasses both the send interface and stdio.

cheers

tachyon


In reply to Re: connect() & close() by tachyon
in thread connect() & close() by monktim

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.