summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2017-05-31 15:34:43 +0200
committerJesus Fernandez <Jesus.Fernandez@qt.io>2017-06-06 17:46:50 +0000
commit5b24f0a6bb5a670539ed6ad94a9359378203b6da (patch)
tree09216e07453dd1531372f196e804a6892933ae0e /src/network
parent3a072f354f607d60386507f42775b05feddd428c (diff)
Add QLocalServer::socketDescriptor
Adds a function to return the native socket descriptor. It allows threaded or forked applications to reuse a previously created socket. [ChangeLog][QtNetwork][QLocalServer] Added a function to retrieve the socket descriptor. Task-number: QTBUG-55043 Change-Id: I556e97000d2c02ad2bdd636984de6c7564381c6a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/socket/qlocalserver.cpp40
-rw-r--r--src/network/socket/qlocalserver.h2
2 files changed, 42 insertions, 0 deletions
diff --git a/src/network/socket/qlocalserver.cpp b/src/network/socket/qlocalserver.cpp
index 94143c2dc0..219a19f8b1 100644
--- a/src/network/socket/qlocalserver.cpp
+++ b/src/network/socket/qlocalserver.cpp
@@ -41,6 +41,10 @@
#include "qlocalserver_p.h"
#include "qlocalsocket.h"
+#if defined(Q_OS_WIN) && !defined(QT_LOCALSOCKET_TCP)
+#include <QtCore/qt_windows.h>
+#endif
+
QT_BEGIN_NAMESPACE
#ifndef QT_NO_LOCALSERVER
@@ -183,6 +187,42 @@ QLocalServer::SocketOptions QLocalServer::socketOptions() const
}
/*!
+ \since 5.10
+ Returns the native socket descriptor the server uses to listen
+ for incoming instructions, or -1 if the server is not listening.
+
+ The type of the descriptor depends on the platform:
+ \list
+ \li On Windows, the returned value is a
+ \l{https://msdn.microsoft.com/en-us/library/windows/desktop/ms740522(v=vs.85).aspx}
+ {Winsock 2 Socket Handle}.
+
+ \li With WinRT and on INTEGRITY, the returned value is the
+ QTcpServer socket descriptor and the type is defined by
+ \l{QTcpServer::socketDescriptor}{socketDescriptor}.
+
+ \li On all other UNIX-like operating systems, the type is
+ a file descriptor representing a listening socket.
+ \endlist
+
+ \sa listen()
+*/
+qintptr QLocalServer::socketDescriptor() const
+{
+ Q_D(const QLocalServer);
+ if (!isListening())
+ return -1;
+#if defined(QT_LOCALSOCKET_TCP)
+ return d->tcpServer.socketDescriptor();
+#elif defined(Q_OS_WIN)
+ const auto handle = d->connectionEventNotifier->handle();
+ return handle != INVALID_HANDLE_VALUE ? qintptr(handle) : -1;
+#else
+ return d->socketNotifier->socket();
+#endif
+}
+
+/*!
Stop listening for incoming connections. Existing connections are not
affected, but any new connections will be refused.
diff --git a/src/network/socket/qlocalserver.h b/src/network/socket/qlocalserver.h
index 52c533141f..2341fd40d4 100644
--- a/src/network/socket/qlocalserver.h
+++ b/src/network/socket/qlocalserver.h
@@ -93,6 +93,8 @@ public:
void setSocketOptions(SocketOptions options);
SocketOptions socketOptions() const;
+ qintptr socketDescriptor() const;
+
protected:
virtual void incomingConnection(quintptr socketDescriptor);