Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's numerous other ways a TCP connection can go dead undetected</p> <blockquote> <ul> <li>someone yanks out a network cable inbetween.</li> <li>the computer at the other end gets nuked.</li> <li>a nat gateway inbetween silently drops the connection</li> <li>the OS at the other end crashes hard.</li> <li>the FIN packets gets lost.</li> <li>undetectable errors: A router in-between the endpoints may drops packets.(including control packets) <a href="https://stackoverflow.com/questions/2428804/tcp-socket-closed?answertab=active#tab-top">reff</a></li> </ul> </blockquote> <p>In all cases you can know about it when you try to <strong>write</strong> on socket this cause through SIGPIPE error in your program and terminate it. </p> <p>By read() it can't be know whether other-side live or not. Thants Why SO_KEEPALIVE useful. Keepalive is non-invasive, and in most cases, if you're in doubt, you can turn it on without the risk of doing something wrong. But do remember that it generates extra network traffic, which can have an impact on routers and firewalls.</p> <p>And this affects all sockets on your machine too!(you are correct). And Because SO_KEEPALIVE increase traffic and consume CPU. It's best to set the SIGPIPE handle, if there is a chance application will ever write to a broken connection. </p> <blockquote> <p>Also use SO_KEEPALIVE at reasonable place in the application. It's poor to use it for whole connection duration (i.e do use so_keepalive when server works for long on client query).</p> <p>Setting the probing interval Dependends on your application or say Application layer protocol.</p> </blockquote> <p>Though enabling TCP keepalive, you'll detect it eventually - at least during a couple of hours.</p> <p><strong>Say if the network has broken down and however, instead of trying to write, socket is puted into some epoll device :</strong> </p> <p>The second argument in epoll:</p> <pre><code> n = epoll_wait (efd, events, MAXEVENTS, -1); </code></pre> <p>Set with correct event-related code, Good practice is to check this code for<br> caution as follow. </p> <pre><code>n = epoll_wait (efd, events, MAXEVENTS, -1); for (i = 0; i &lt; n; i++) { if ((events[i].events &amp; EPOLLERR) || (events[i].events &amp; EPOLLHUP) || (!(events[i].events &amp; EPOLLIN))) { /* An error has occured on this fd, or the socket is not ready for reading (why were we notified then?) */ fprintf (stderr, "epoll error\n"); close (events[i].data.fd); continue; } else if (sfd == events[i].data.fd) { /* We have a notification on the listening socket, which means one or more incoming connections. */ // Do what you wants } } </code></pre> <p>Where <strong>EPOLLRDHUP</strong> means is:<br> Stream socket peer closed connection, or shut down writing half of connection. (This flag is especially useful for writing simple code to detect peer shutdown when using Edge Triggered monitoring.) </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload