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
12QT_REQUIRE_CONFIG(localserver);
13
14QT_BEGIN_NAMESPACE
15
16class QLocalSocket;
17class QLocalServerPrivate;
18
19class 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
26Q_SIGNALS:
27 void newConnection();
28
29public:
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
69protected:
70 virtual void incomingConnection(quintptr socketDescriptor);
71
72private:
73 Q_DISABLE_COPY(QLocalServer)
74 Q_PRIVATE_SLOT(d_func(), void _q_onNewConnection())
75};
76
77Q_DECLARE_OPERATORS_FOR_FLAGS(QLocalServer::SocketOptions)
78
79QT_END_NAMESPACE
80
81#endif // QLOCALSERVER_H
82
83

source code of qtbase/src/network/socket/qlocalserver.h