PDA

View Full Version : How to close socket on timeout?



Helg
10th February 2011, 10:02
I read http://www.qtcentre.org/wiki/index.php?title=Multi_client_server_without_thread ing. So I have a small question. What's right way for server to close inactive sockets?

1. Store timestamp for every opened socket.
2. Update timestamp on every Read/Write operation.
2. Make single QTimer and by QTimer::timeout check what socket is expired.

Or:

1. Create QTimer pool for server and QTimer object for every socket.
2. Connect all timers to a single server slot slotTimeout.
3. Restart socket timer on each Read/Write operation.
3. In server slotTimeout close expired socket.

Or something else?

kuzulis
10th February 2011, 11:36
IMHO, p.1


1. Store timestamp for every opened socket.
2. Update timestamp on every Read/Write operation.
2. Make single QTimer and by QTimer::timeout check what socket is expired.


as only one QTimer for all sockets - that is saving (minimizing) resources.