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.
- 12-28-2011 #1
- Join Date
- Dec 2011
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!
- 04-24-2012 #2
- Join Date
- Apr 2009
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
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!