| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QLOCALSERVER_P_H |
| 5 | #define QLOCALSERVER_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of the QLocalServer class. This header file may change from |
| 13 | // version to version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtNetwork/private/qtnetworkglobal_p.h> |
| 19 | |
| 20 | #include "qlocalserver.h" |
| 21 | #include "private/qobject_p.h" |
| 22 | #include <qqueue.h> |
| 23 | |
| 24 | QT_REQUIRE_CONFIG(localserver); |
| 25 | |
| 26 | #if defined(QT_LOCALSOCKET_TCP) |
| 27 | # include <qtcpserver.h> |
| 28 | # include <QtCore/qmap.h> |
| 29 | #elif defined(Q_OS_WIN) |
| 30 | # include <qt_windows.h> |
| 31 | # include <qwineventnotifier.h> |
| 32 | #else |
| 33 | # include <private/qabstractsocketengine_p.h> |
| 34 | # include <qsocketnotifier.h> |
| 35 | #endif |
| 36 | |
| 37 | QT_BEGIN_NAMESPACE |
| 38 | |
| 39 | class QLocalServerPrivate : public QObjectPrivate |
| 40 | { |
| 41 | Q_DECLARE_PUBLIC(QLocalServer) |
| 42 | |
| 43 | public: |
| 44 | QLocalServerPrivate() : |
| 45 | #if !defined(QT_LOCALSOCKET_TCP) && !defined(Q_OS_WIN) |
| 46 | listenSocket(-1), socketNotifier(nullptr), |
| 47 | #endif |
| 48 | maxPendingConnections(30), error(QAbstractSocket::UnknownSocketError), |
| 49 | socketOptions(QLocalServer::NoOptions) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | void init(); |
| 54 | bool listen(const QString &name); |
| 55 | bool listen(qintptr socketDescriptor); |
| 56 | static bool removeServer(const QString &name); |
| 57 | void closeServer(); |
| 58 | void waitForNewConnection(int msec, bool *timedOut); |
| 59 | void _q_onNewConnection(); |
| 60 | |
| 61 | #if defined(QT_LOCALSOCKET_TCP) |
| 62 | |
| 63 | QTcpServer tcpServer; |
| 64 | QMap<quintptr, QTcpSocket*> socketMap; |
| 65 | #elif defined(Q_OS_WIN) |
| 66 | struct Listener { |
| 67 | Listener() = default; |
| 68 | HANDLE handle = nullptr; |
| 69 | OVERLAPPED overlapped; |
| 70 | bool connected = false; |
| 71 | private: |
| 72 | Q_DISABLE_COPY(Listener) |
| 73 | }; |
| 74 | |
| 75 | void setError(const QString &function); |
| 76 | bool addListener(); |
| 77 | |
| 78 | std::vector<std::unique_ptr<Listener>> listeners; |
| 79 | HANDLE eventHandle; |
| 80 | QWinEventNotifier *connectionEventNotifier; |
| 81 | #else |
| 82 | void setError(const QString &function); |
| 83 | |
| 84 | int listenSocket; |
| 85 | QSocketNotifier *socketNotifier; |
| 86 | #endif |
| 87 | |
| 88 | QString serverName; |
| 89 | QString fullServerName; |
| 90 | int maxPendingConnections; |
| 91 | QQueue<QLocalSocket*> pendingConnections; |
| 92 | QString errorString; |
| 93 | QAbstractSocket::SocketError error; |
| 94 | int listenBacklog = 50; |
| 95 | |
| 96 | Q_OBJECT_BINDABLE_PROPERTY(QLocalServerPrivate, QLocalServer::SocketOptions, socketOptions) |
| 97 | }; |
| 98 | |
| 99 | QT_END_NAMESPACE |
| 100 | |
| 101 | #endif // QLOCALSERVER_P_H |
| 102 | |
| 103 | |