Results 1 to 2 of 2
I have a server using unix domain socket. It works in a standard way: listening for requests and accepting each of them by running a separater thread for it:
while(true){
...
- 03-30-2007 #1Just Joined!
- Join Date
- Mar 2007
- Posts
- 20
How to terminate a socket server gracefully?
I have a server using unix domain socket. It works in a standard way: listening for requests and accepting each of them by running a separater thread for it:
while(true){
int clientsocket;
clientsocket=accept(serversocket, NULL, NULL);
ClientHandler * ch = new ClientHandler(someparameters, clientsocket);
ch->start();
}
So, how to terminate this server gracefully? I think some signal handler can be used for this purpose though I haven't done so and it's ok to do "kill -TERM pid" w/o the signal is handled by the server. But since there is a lot of cleanning work to do for each socket connection, this is not something recommended.
Any idea or suggestions? Thanks!
- 03-30-2007 #2
It is always better to trap signals and close the socket. Otherwise, the opened socket would be left unclosed and if your system reaches the max number of open descriptors limit, u wud be able to accept any new connections.
---------------------------------
Registered Linux User #440311
HI2ARUN _AT_ GMAIL _DOT_ COM
---------------------------------


Reply With Quote