Find the answer to your Linux question:
Results 1 to 2 of 2
Let's say I opened a TCP socket to another server. I have two threads, in one thread I do a block read(...), while in the 2nd thread I close the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    1

    Closing socket, what's the expected behavior


    Let's say I opened a TCP socket to another server. I have two threads, in one thread I do a block read(...), while in the 2nd thread I close the socket. what would be the expected behavior of my 1st thread?

    I am asking this because I saw different behavior on different builds, on one redhat version the 1st thread return with a 0, indicate the socket is closed, on another version the 1st thread got stuck and never return from read().

    Many thanks in advance!

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,572
    Great question! I think this is implementation-defined. In theory, it can either return 0, and have either the eof or bad bits set, or it can return -1, and set errno appropriately. I think you need to check for both situations for a cross-platform implementation.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •