summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qtcpserver.cpp
diff options
context:
space:
mode:
authorØystein Heskestad <oystein.heskestad@qt.io>2022-05-30 17:35:53 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2022-06-04 00:22:55 +0000
commit782fbe0f63af5aeb583f84c28b7d0ff482bd28e4 (patch)
treece65c2f181de2bc9a92d5e7b143087bfe6f55736 /src/network/socket/qtcpserver.cpp
parent8b262335733a25a41a9625bfc5e29d41e7e25481 (diff)
The new signal pendingConnectionAvailable is added to QTcpServer
The new signal pendingConnnectionAvailable is emitted after a new connection has been added to the pending connections queue. Connect to this signal and call nextPendingConnection to handle incoming connections. The existing unchanged newConnection signal is emitted after the overridable function incomingConnection is called, regardless of whether a new connection is added to the pending connections queue in the incomingConnection function or not. If a subclass that overrides incomingConnection either decides to not add all incoming connections to the pending connections queue, or to postpone adding the connection until a handshake is successfully completed, the pendingConnectionAvailable signal should be to used, because this signal directly corresponds to insertions to the pending connections queue. [ChangeLog][QtNetwork][QTcpServer] New signal pendingConnectionAvailable is emitted when a new connection is added Task-number: QTBUG-100823 Change-Id: I00c76761389065f68271553e69e6c45c393a2fa8 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/network/socket/qtcpserver.cpp')
-rw-r--r--src/network/socket/qtcpserver.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/network/socket/qtcpserver.cpp b/src/network/socket/qtcpserver.cpp
index 1f443010e4..95d1877a5d 100644
--- a/src/network/socket/qtcpserver.cpp
+++ b/src/network/socket/qtcpserver.cpp
@@ -18,7 +18,9 @@
Call listen() to have the server listen for incoming connections.
The newConnection() signal is then emitted each time a client
- connects to the server.
+ connects to the server. When the client connection has been added
+ to the pending connection queue using the addPendingConnection()
+ function, the pendingConnectionAvailable() signal is emitted.
Call nextPendingConnection() to accept the pending connection as
a connected QTcpSocket. The function returns a pointer to a
@@ -47,11 +49,21 @@
/*! \fn void QTcpServer::newConnection()
- This signal is emitted every time a new connection is available.
+ This signal is emitted every time a new connection is available, regardless
+ of whether it has been added to the pending connections queue or not.
\sa hasPendingConnections(), nextPendingConnection()
*/
+/*! \fn void QTcpServer::pendingConnectionAvailable()
+
+ This signal is emitted every time a new connection has been added to the
+ pending connections queue.
+
+ \sa hasPendingConnections(), nextPendingConnection()
+ \since 6.4
+*/
+
/*! \fn void QTcpServer::acceptError(QAbstractSocket::SocketError socketError)
\since 5.0
@@ -182,10 +194,12 @@ void QTcpServerPrivate::readNotification()
#if defined (QTCPSERVER_DEBUG)
qDebug("QTcpServerPrivate::_q_processIncomingConnection() accepted socket %i", descriptor);
#endif
+ QPointer<QTcpServer> that = q;
q->incomingConnection(descriptor);
- QPointer<QTcpServer> that = q;
- emit q->newConnection();
+ if (that)
+ emit q->newConnection();
+
if (!that || !q->isListening())
return;
}
@@ -572,14 +586,17 @@ void QTcpServer::incomingConnection(qintptr socketDescriptor)
\note Don't forget to call this member from reimplemented
incomingConnection() if you do not want to break the
- Pending Connections mechanism.
+ Pending Connections mechanism. This function emits the
+ pendingConnectionAvailable() signal after the socket has been
+ added.
- \sa incomingConnection()
+ \sa incomingConnection(), pendingConnectionAvailable()
\since 4.7
*/
void QTcpServer::addPendingConnection(QTcpSocket* socket)
{
d_func()->pendingConnections.append(socket);
+ emit pendingConnectionAvailable(QPrivateSignal());
}
/*!