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