How do I properly close a socket connection?

How do I properly close a socket connection?

Post by Pete Ros » Sat, 19 Sep 1998 04:00:00



Can anyone give me some information on how a Linux server task should
properly close it's socket connection(s) when it is terminated so that
open socket connections are not left in  FIN_WAIT or FIN_WAIT_2 state?

Currently .. if my server task is running and has an open socket
connection to a client, and the server task is terminated, then the
socket connection will go to  FIN_WAIT_2  state and then the server
task can not be restarted until these connections finally time out and
close (bind fail on port in use) ..  which may take several minutes.
This happens even if the socket is not currently transferring any data.

I have tried using various combinations of   shutdown() and close()
when the server detects a SIGTERM  but they do not work reliably.. in
particular for NT clients.

This is for  AF_INET  SOCK_STREAM type sockets.. if it matters.

Any information or references to some good books that cover socket
programming would be appreciated.

=======================
Pete Rossi - WA3NNA

=======================

 
 
 

1. How do I properly close a socket connection?

Can anyone give me some information on how a Linux server task should
properly close it's socket connection(s) when it is terminated so that
open socket connections are not left in  FIN_WAIT or FIN_WAIT_2 state?

Currently .. if my server task is running and has an open socket
connection to a client, and the server task is terminated, then the
socket connection will go to  FIN_WAIT_2  state and then the server
task can not be restarted  (bind fails with 'port in use') until these
connections finally time out ... which may take several minutes.
This happens even if the socket is not currently transferring any data.

I have tried using various combinations of  shutdown() and close()
when the server detects a SIGTERM  but they do not work reliably, in
particular, with NT clients.

This is for  AF_INET  SOCK_STREAM type sockets.. if it matters.

Any information or references to some good books that cover socket
programming would be appreciated.

=======================
Pete Rossi - WA3NNA

=======================

2. New mail?

3. Reclaiming used socket fd or how to close sockets properly

4. gcc for AIX

5. Closing sockets and closing connections

6. HELP: Anyone know what this error mean?

7. JServ 1.1 sockets do not close properly

8. Free Web Agent CPdog 1.0.0a for Linux

9. ppp connection fails to close properly

10. Checking for a closed socket connection

11. How to detect when socket connection closes?

12. Linux sockets problem (closed connections staying open?)

13. mod_perl; doing something after connection->close