QcTcpGoodbye Class
Ends a TCP connection so that the peer reads everything sent before (decision E-904). More...
| Header: | #include <network/QcTcpGoodbye.h> |
| Inherits: | QObject |
Static Public Members
| void | begin(QTcpSocket &socket, int lingerMs, bool peerLeft) |
| void | finishLingering(int maxWaitMs = 1'000) |
| void | release(std::unique_ptr<QTcpSocket> owned, int lingerMs, bool peerLeft) |
Detailed Description
Closing at once with unread or later arriving data makes the system reset the connection, and a Windows peer throws away what it had not read yet: the reason of a Disconnect. So the goodbye
- waits until Qt's buffers are empty, then shuts the socket's write side down (FIN) while its read side stays open; over TLS only when the peer left first (its Disconnect arrived), else the peer is expected to close on the Disconnect it reads, and the end waits for that;
- waits until the system has sent everything (where it tells), then gives the peer the linger time to close too, reading and throwing away whatever it still sends;
- closes the socket then, at the latest after four linger times (a peer that reads nothing).
Lives as a child of its socket, in the socket's thread.
Member Function Documentation
[static] void QcTcpGoodbye::begin(QTcpSocket &socket, int lingerMs, bool peerLeft)
Starts the goodbye of a connected socket, once; the owner keeps the socket. Closes a socket that is not connected at once. lingerMs is the linger time, peerLeft tells that the peer said goodbye first.
[static] void QcTcpGoodbye::finishLingering(int maxWaitMs = 1'000)
Runs the calling thread's event loop until the sockets released in it ended their goodbye, at most maxWaitMs, and ends the rest; for a thread that is about to end, which would otherwise cut them off at once. Returns at once in a thread without.
[static] void QcTcpGoodbye::release(std::unique_ptr<QTcpSocket> owned, int lingerMs, bool peerLeft)
Takes owned over and starts its goodbye as begin() does with lingerMs and peerLeft: the socket deletes itself when the goodbye ended or when its thread ends.