Socket's close() doesn't close connection (old bug?)
Martin Egholm Nielsen
martin@egholm-nielsen.dk
Thu Nov 10 07:54:00 GMT 2005
Daney,
>>>> Blah blah blah, this turned out to be reported already:
>>>>
>>>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15430
>>>>
>>>> Unfortunately still open ;-)
>>> Check the above PR for my little C program the demonstrates how by
>>> adding a call to shutdown() before the close() that the blocked
>>> read() returns. I think with a small amount of hacking we can use
>>> this technique to terminate the blocked thread with the proper
>>> exception being thrown.
>>
>>
>> Really?! Reading here:
>>
>> http://www.ecst.csuchico.edu/~beej/guide/net_old/#closedown
>>
>> shutdown(s, SHUT_RDWR);
>>
>> and
>>
>> close(s);
>>
>> are identical...
> They are not identical. shutdown() closes the socket. close()
> disconnects a process from the socket allowing the OS to close it when
> there are no more references to it. If a thread is blocked reading from
> the socket there will be a reference to it as long as it is blocked.
Bingo! It does indeed work!
But maybe, and just maybe, there may need additional code handling
So_Linger. The javadoc on socket's close() says nothing about it (maybe
the specs does), but the setSoLinger() mentions that this has effect on
close() operation...
Nevertheless, thanks Daney!
// Martin
More information about the Java
mailing list