I have a server that is listening to stdin (user) and other clients.
Let’s say the server is connected to many clients (using select to control all file descriptors), and the user enters EXIT in the terminal. This means the server should close itself.
What is the correct way to close the server gracefully? Should the server go through all file descriptors and close(fd) all of them or just close the listener fd? Alternatively, should I not close anything and just let the server process finish and exit?
I’m using only one thread in my program.
Thank you.
Closing the listener
fdmeans no more connections will be accepted. The nicest way to handle this would be to:Closing a process automatically closes all its open file-descriptors. Telling everyone to close before you exit is just a convenience so as not to abruptly close the connection.