Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qlocalserver_tcp.cpp
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
#
include
"qlocalserver.h"
6
#
include
"qlocalserver_p.h"
7
#
include
"qlocalsocket.h"
8
#
include
"qlocalsocket_p.h"
9
10
#
include
<
qhostaddress
.
h
>
11
#
include
<
qsettings
.
h
>
12
#
include
<
qdebug
.
h
>
13
14
QT_BEGIN_NAMESPACE
15
16
using
namespace
Qt::StringLiterals;
17
18
void
QLocalServerPrivate::init()
19
{
20
Q_Q(QLocalServer);
21
q->connect(&tcpServer, SIGNAL(newConnection()), SLOT(_q_onNewConnection()));
22
}
23
24
bool
QLocalServerPrivate::listen(
const
QString &requestedServerName)
25
{
26
tcpServer.setListenBacklogSize(listenBacklog);
27
28
if
(!tcpServer.listen(QHostAddress::LocalHost))
29
return
false
;
30
31
const
auto
prefix =
"QLocalServer/"_L1
;
32
if
(requestedServerName.startsWith(prefix))
33
fullServerName = requestedServerName;
34
else
35
fullServerName = prefix + requestedServerName;
36
37
QSettings settings(
"QtProject"_L1
,
"Qt"_L1
);
38
if
(settings.contains(fullServerName)) {
39
qWarning(
"QLocalServer::listen: server name is already in use."
);
40
tcpServer.close();
41
return
false
;
42
}
43
44
settings.setValue(fullServerName, tcpServer.serverPort());
45
return
true
;
46
}
47
48
bool
QLocalServerPrivate::listen(qintptr socketDescriptor)
49
{
50
return
tcpServer.setSocketDescriptor(socketDescriptor);
51
}
52
53
void
QLocalServerPrivate::closeServer()
54
{
55
QSettings settings(
"QtProject"_L1
,
"Qt"_L1
);
56
if
(fullServerName ==
"QLocalServer"_L1
)
57
settings.setValue(fullServerName, QVariant());
58
else
59
settings.remove(fullServerName);
60
tcpServer.close();
61
}
62
63
void
QLocalServerPrivate::waitForNewConnection(
int
msec,
bool
*timedOut)
64
{
65
if
(pendingConnections.isEmpty())
66
tcpServer.waitForNewConnection(msec, timedOut);
67
else
if
(timedOut)
68
*timedOut =
false
;
69
}
70
71
void
QLocalServerPrivate::_q_onNewConnection()
72
{
73
Q_Q(QLocalServer);
74
QTcpSocket* tcpSocket = tcpServer.nextPendingConnection();
75
if
(!tcpSocket) {
76
qWarning(
"QLocalServer: no pending connection"
);
77
return
;
78
}
79
80
tcpSocket->setParent(q);
81
const
quintptr socketDescriptor = tcpSocket->socketDescriptor();
82
q->incomingConnection(socketDescriptor);
83
}
84
85
bool
QLocalServerPrivate::removeServer(
const
QString &name)
86
{
87
const
auto
prefix =
"QLocalServer/"_L1
;
88
QString serverName;
89
if
(name.startsWith(prefix))
90
serverName = name;
91
else
92
serverName = prefix + name;
93
94
QSettings settings(
"QtProject"_L1
,
"Qt"_L1
);
95
if
(settings.contains(serverName))
96
settings.remove(serverName);
97
98
return
true
;
99
}
100
101
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtbase
src
network
socket
qlocalserver_tcp.cpp
Generated on
for Qt by
1.18.0