A tcp connetion question - Networking

This is a discussion on A tcp connetion question - Networking ; They r two processes, for client and server, connected with TCP. Connection is OK. I killed the server process, while the client seems not to feel that before it sent some data by calling send(). And it checked the errno, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: A tcp connetion question

  1. A tcp connetion question

    They r two processes, for client and server, connected with TCP. Connection
    is OK.
    I killed the server process, while the client seems not to feel that before
    it sent some data by calling send().
    And it checked the errno, which indicated a segmentation fault error.

    Why should it be segmentation fault rather than something indicating
    disconnection?




  2. A tcp connetion question

    Sorry, I realize the segmentation fault was caused by perror(). After
    calling send(), the value of errno is 29, which caused perror() to crash
    whole process. Confused...

    However, that ain't problem. I just wanna know how to make client process
    detect such situations as server killed, network
    cable unplugged or anything else that can cause the disconnection?



  3. Re: A tcp connetion question

    Jimmy wrote:
    > Sorry, I realize the segmentation fault was caused by perror(). After
    > calling send(), the value of errno is 29, which caused perror() to crash
    > whole process. Confused...
    >
    > However, that ain't problem. I just wanna know how to make client process
    > detect such situations as server killed, network
    > cable unplugged or anything else that can cause the disconnection?
    >
    >


    Your segmentation fault indicates a bug in your program. perror()
    doesn't normally crash even if the value of errno is 29 - you have tried
    to write to some area that doesn't belong to you. Running the process
    under gdb should tell you what caused the crash.

    You detect such situations when recv() returns 0 (for an orderly
    shutdown) or -1 (for an error).

    Robert

+ Reply to Thread