Close connection with client after inactivty period
You could close the client connection when the client has not sent any data for a specific time.
For each client, you need to store the time when the last data was received.
Periodically, for example when poll()
returns because the timeout expired, you need to check this time for all clients. When this time to too long ago, you can shutdown(SHUT_WR)
and close()
the connection. You need to determine what "too long ago" is.
If a client does not have any data to send but wants to leave the connection open, it could send a "ping" message periodically. The server could reply with a "pong" message. These are just small messages with no actual data. It depends on your client/server protocol whether you can implement this.