Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8657665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:34:39+00:00 2026-06-12T15:34:39+00:00

Suppose a simple network model: A has successfully created a TCP connection to B,

  • 0

Suppose a simple network model: A has successfully created a TCP connection to B, and they are communicating with each other like this

A <----------> B

I know that if the program on A dies (such as core dump), that will cause a RST packet to B. So any read attempt of B will lead to an EOF, and any write attempt of B will lead to SIGPIPE. Am I right?

If, however, suppose the network has broken down (such as cable/router failure) on A, what happens to the read/write attempt of B? In my situation, all the sockets has been set to non-blocking. As a result, is it impossible for me to detect network error?

By the way, I notice that there is an option SO_KEEPALIVE in socket which may be useful to me http://tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/. But I wonder how much the cost will be if I set the probing interval to 2~3 second (which by default is 75 seoncd)? And it seems interval configuration is a global one, so is this gonna affect all the sockets on the machine?

Final question…
Say the network has broken down and any write attempt would cause EPIPE some time later. If, however, instead of trying to write, I put this socket into epoll device, what will happend then? Will epoll_wait return EPOLLHUP or EPOLLERR event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:34:40+00:00Added an answer on June 12, 2026 at 3:34 pm

    There’s numerous other ways a TCP connection can go dead undetected

    • someone yanks out a network cable inbetween.
    • the computer at the other end gets nuked.
    • a nat gateway inbetween silently drops the connection
    • the OS at the other end crashes hard.
    • the FIN packets gets lost.
    • undetectable errors: A router in-between the endpoints may drops packets.(including control packets)
      reff

    In all cases you can know about it when you try to write on socket this cause through SIGPIPE error in your program and terminate it.

    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.

    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.

    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).

    Setting the probing interval Dependends on your application or say
    Application layer protocol.

    Though enabling TCP keepalive, you’ll detect it eventually – at least during a couple of hours.

    Say if the network has broken down and however, instead of trying to write, socket is puted into some epoll device :

    The second argument in epoll:

     n = epoll_wait (efd, events, MAXEVENTS, -1);
    

    Set with correct event-related code, Good practice is to check this code for
    caution as follow.

    n = epoll_wait (efd, events, MAXEVENTS, -1);  
    for (i = 0; i < n; i++)  
    {   
        if ((events[i].events & EPOLLERR) ||
              (events[i].events & EPOLLHUP) ||
              (!(events[i].events & 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
         }
    }
    

    Where EPOLLRDHUP means is:
    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.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have a simple class like this: class foo{ private: int* mData; int
Suppose this simple scenario: My client has an already working .net application and he/she
Suppose I have a simple method like this for processing two lists: public static
Suppose a simple ActiveRecord model corresponding to a table with just two columns, id
Suppose I have a simple model, such as Record: @Model public class Record {
Suppose I get, on a page, this simple html/script : <a id=hey href=#>try</a> var
i'm sorry for asking this question because i think it has a really simple
I had a code (lets suppose a simple chat application), I used Tcp with
Suppose I have this simple contract which I've taken from MS examples and altered
Suppose I have simple class like: class MyClass { private $_prop; public function getProp()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.