(Please understand that this subthread has become quite Off-Topic here)

What can_write() can really tell you is if the server has closed its connection in a clean way, i.e. sending you a FIN packet that your TCP stack has diligently ACKed, which is the best you can get now.

Changing the system won't help you much, so I'm inclined to tell you that you will not know that your connection is down so fast. Any TCP implementation is based on the fact that the underlying network protocol (i.e. IP) can generate delays that are virtually indistinguishable from network failures; in fact, TCP usually adopts some retry schemes for packets that are not acknowledged, so you definitively have to wait.

Moreover, to check if the server is down you actually have to force the TCP/IP stack to send something to him and have it unacknowledged, and I fear that any implementation is "smart" enough to need real data to make such a check. But here I'm going too deep into the forest, and I don't have the needed light at the moment to make the matter clearer - try to ask to some TCP expert forum, or to read about the TCP implementation in the Linux Kernel.

Flavio

Don't fool yourself.

In reply to Re^3: Maintain TCP client connection to server? by polettix
in thread Maintain TCP client connection to server? by Anonymous Monk

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.