| 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_H |
| 5 | #define QLOCALSERVER_H |
| 6 | |
| 7 | #include <QtNetwork/qtnetworkglobal.h> |
| 8 | #include <QtNetwork/qabstractsocket.h> |
| 9 | |
| 10 | #include <QtCore/qproperty.h> |
| 11 | |
| 12 | QT_REQUIRE_CONFIG(localserver); |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | class QLocalSocket; |
| 17 | class QLocalServerPrivate; |
| 18 | |
| 19 | class Q_NETWORK_EXPORT QLocalServer : public QObject |
| 20 | { |
| 21 | Q_OBJECT |
| 22 | Q_DECLARE_PRIVATE(QLocalServer) |
| 23 | Q_PROPERTY(SocketOptions socketOptions READ socketOptions WRITE setSocketOptions |
| 24 | BINDABLE bindableSocketOptions) |
| 25 | |
| 26 | Q_SIGNALS: |
| 27 | void newConnection(); |
| 28 | |
| 29 | public: |
| 30 | enum SocketOption { |
| 31 | NoOptions = 0x0, |
| 32 | UserAccessOption = 0x01, |
| 33 | GroupAccessOption = 0x2, |
| 34 | OtherAccessOption = 0x4, |
| 35 | WorldAccessOption = 0x7, |
| 36 | AbstractNamespaceOption = 0x8 |
| 37 | }; |
| 38 | Q_ENUM(SocketOption) |
| 39 | Q_DECLARE_FLAGS(SocketOptions, SocketOption) |
| 40 | Q_FLAG(SocketOptions) |
| 41 | |
| 42 | explicit QLocalServer(QObject *parent = nullptr); |
| 43 | ~QLocalServer(); |
| 44 | |
| 45 | void close(); |
| 46 | QString errorString() const; |
| 47 | virtual bool hasPendingConnections() const; |
| 48 | bool isListening() const; |
| 49 | bool listen(const QString &name); |
| 50 | bool listen(qintptr socketDescriptor); |
| 51 | int maxPendingConnections() const; |
| 52 | virtual QLocalSocket *nextPendingConnection(); |
| 53 | QString serverName() const; |
| 54 | QString fullServerName() const; |
| 55 | static bool removeServer(const QString &name); |
| 56 | QAbstractSocket::SocketError serverError() const; |
| 57 | void setMaxPendingConnections(int numConnections); |
| 58 | bool waitForNewConnection(int msec = 0, bool *timedOut = nullptr); |
| 59 | |
| 60 | void setListenBacklogSize(int size); |
| 61 | int listenBacklogSize() const; |
| 62 | |
| 63 | void setSocketOptions(SocketOptions options); |
| 64 | SocketOptions socketOptions() const; |
| 65 | QBindable<SocketOptions> bindableSocketOptions(); |
| 66 | |
| 67 | qintptr socketDescriptor() const; |
| 68 | |
| 69 | protected: |
| 70 | virtual void incomingConnection(quintptr socketDescriptor); |
| 71 | void addPendingConnection(QLocalSocket *socket); |
| 72 | |
| 73 | private: |
| 74 | Q_DISABLE_COPY(QLocalServer) |
| 75 | Q_PRIVATE_SLOT(d_func(), void _q_onNewConnection()) |
| 76 | }; |
| 77 | |
| 78 | Q_DECLARE_OPERATORS_FOR_FLAGS(QLocalServer::SocketOptions) |
| 79 | |
| 80 | QT_END_NAMESPACE |
| 81 | |
| 82 | #endif // QLOCALSERVER_H |
| 83 | |
| 84 | |