Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Dear Monks,

Thank you for your replies and trying to help me. Please also forgive that my language is not always clear. I try to improve.

I am speaking about TCP and not about UDP. Many think that data cannot be lost on TPC, unfortunately this is not always true. As long as both peers keep their sockets open and only the network is down for some time, the connection will recover, data transmission is repeated and nothing is lost. If, however, one side dies, the socket on the other side may still be open, so the application may continue writing data into this socket until it will block or eventually returns an error code. And obviously all this data will never arrive at the other side which is already dead.

Testing $conn->connected() exactly fails in this sitation of a "half-open" TCP connection, since the local socket believes the connection is established. That is exactly the issue I want to detect

It has been suggested to use SO_KEEPALIVE. Thank you for this idea. This indeed would resolve the issue, however it is not a viable solution. The problem here is, that the keepalive timeout typically is 2 hours. As far as I know, it can only be configured globally on a machine, so I don't want to play with this parameter, as it may cause side effects. I want to detect the half-open connection after a few seconds, ont only after hours. Some comments on the web suggest that the application should use its own heartbeat messages. However this will not work in my case. Unfortunately the application protocol is fixed, I cannot change it, and it does not provide a heartbeat message

Pinging the peer hoat may be another way to check, if it is available. However, I would prefer send_q as it would use status data of the actual socket rather than introducing another channel.

Thank you also for pointing out that send_q does not count the pending messages but the pending octets. Good to know, even though in my case this detail does not really matter. I would only be interested to test if send_q is 0 or not.

Now I come back to my original question: Is there a function in Perl which returns the current value of send_q for an open TCP connection? Would be great, if someone knows the answer. Thanks again for your support. Best regards, Andreas

I should add that in my case it would be fully sufficient if the application layer detects that something is "wrong" with that TCP connection. There are recovery mechanisms available in the code which only need to be triggered.


In reply to Re: function to count pending packets in TCP socket by Anonymous Monk
in thread function to count pending packets in TCP socket 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [marto]: use dreamweaver they said, it's brilliant they told me...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (8)
    As of 2018-07-20 12:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (431 votes). Check out past polls.

      Notices?