Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qabstractsocketengine.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
5
7
8#include "qmutex.h"
9#include "qnetworkproxy.h"
10
12
13class QSocketEngineHandlerList : public QList<QSocketEngineHandler*>
14{
15public:
17};
18
20
22{
23 if (!socketHandlers())
24 return;
25 QMutexLocker locker(&socketHandlers()->mutex);
26 socketHandlers()->prepend(this);
27}
28
30{
31 if (!socketHandlers())
32 return;
33 QMutexLocker locker(&socketHandlers()->mutex);
34 socketHandlers()->removeAll(this);
35}
36
38 : socketError(QAbstractSocket::UnknownSocketError)
39 , hasSetSocketError(false)
40 , socketErrorString(QLatin1StringView(QT_TRANSLATE_NOOP(QSocketLayer, "Unknown error")))
41 , socketState(QAbstractSocket::UnconnectedState)
42 , socketType(QAbstractSocket::UnknownSocketType)
43 , socketProtocol(QAbstractSocket::UnknownNetworkLayerProtocol)
44 , localPort(0)
45 , peerPort(0)
46 , inboundStreamCount(0)
47 , outboundStreamCount(0)
48 , receiver(nullptr)
49{
50}
51
56
61
63{
64#ifndef QT_NO_NETWORKPROXY
65 // proxy type must have been resolved by now
67 return nullptr;
68#endif
69
70 QMutexLocker locker(&socketHandlers()->mutex);
71 for (int i = 0; i < socketHandlers()->size(); i++) {
72 if (QAbstractSocketEngine *ret = socketHandlers()->at(i)->createSocketEngine(socketType, proxy, parent))
73 return ret;
74 }
75
76#ifndef QT_NO_NETWORKPROXY
77 // only NoProxy can have reached here
79 return nullptr;
80#endif
81
82 return new QNativeSocketEngine(parent);
83}
84
86{
87 QMutexLocker locker(&socketHandlers()->mutex);
88 for (int i = 0; i < socketHandlers()->size(); i++) {
89 if (QAbstractSocketEngine *ret = socketHandlers()->at(i)->createSocketEngine(socketDescripter, parent))
90 return ret;
91 }
92 return new QNativeSocketEngine(parent);
93}
94
96{
97 return d_func()->socketError;
98}
99
101{
102 return d_func()->socketErrorString;
103}
104
106{
107 Q_D(const QAbstractSocketEngine);
108 d->socketError = error;
109 d->socketErrorString = errorString;
110}
111
113{
114 d_func()->receiver = receiver;
115}
116
118{
119 if (QAbstractSocketEngineReceiver *receiver = d_func()->receiver)
120 receiver->readNotification();
121}
122
124{
125 if (QAbstractSocketEngineReceiver *receiver = d_func()->receiver)
126 receiver->writeNotification();
127}
128
130{
131 if (QAbstractSocketEngineReceiver *receiver = d_func()->receiver)
132 receiver->exceptionNotification();
133}
134
136{
137 if (QAbstractSocketEngineReceiver *receiver = d_func()->receiver)
138 receiver->closeNotification();
139}
140
142{
143 if (QAbstractSocketEngineReceiver *receiver = d_func()->receiver)
144 receiver->connectionNotification();
145}
146
147#ifndef QT_NO_NETWORKPROXY
149{
150 if (QAbstractSocketEngineReceiver *receiver = d_func()->receiver)
151 receiver->proxyAuthenticationRequired(proxy, authenticator);
152}
153#endif
154
155
157{
158 return d_func()->socketState;
159}
160
162{
163 d_func()->socketState = state;
164}
165
167{
168 return d_func()->socketType;
169}
170
175
177{
178 return d_func()->socketProtocol;
179}
180
182{
183 d_func()->socketProtocol = protocol;
184}
185
187{
188 return d_func()->localAddress;
189}
190
192{
193 d_func()->localAddress = address;
194}
195
197{
198 return d_func()->localPort;
199}
200
202{
203 d_func()->localPort = port;
204}
205
207{
208 return d_func()->peerAddress;
209}
210
212{
213 d_func()->peerAddress = address;
214}
215
217{
218 return d_func()->peerPort;
219}
220
222{
223 d_func()->peerPort = port;
224}
225
227{
228 return d_func()->inboundStreamCount;
229}
230
232{
233 return d_func()->outboundStreamCount;
234}
235
237
238#include "moc_qabstractsocketengine_p.cpp"
virtual void readNotification()=0
QAbstractSocket::SocketError error() const
QAbstractSocket::NetworkLayerProtocol protocol() const
void setReceiver(QAbstractSocketEngineReceiver *receiver)
void setPeerAddress(const QHostAddress &address)
void setState(QAbstractSocket::SocketState state)
QAbstractSocket::SocketType socketType() const
void setLocalAddress(const QHostAddress &address)
QAbstractSocketEngine(QObject *parent=nullptr)
static QAbstractSocketEngine * createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent)
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
QAbstractSocket::SocketState state() const
void setSocketType(QAbstractSocket::SocketType socketType)
QHostAddress peerAddress() const
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
QHostAddress localAddress() const
void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol)
The QAbstractSocket class provides the base functionality common to all socket types.
SocketState
This enum describes the different states in which a socket can be.
SocketError
This enum describes the socket errors that can occur.
SocketType
This enum describes the transport layer protocol.
The QAuthenticator class provides an authentication object.
The QHostAddress class provides an IP address.
Definition qlist.h:75
\inmodule QtCore
Definition qmutex.h:313
\inmodule QtCore
Definition qmutex.h:281
The QNativeSocketEngine class provides low level access to a socket.
The QNetworkProxy class provides a network layer proxy.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
else opt state
[0]
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
EGLOutputPortEXT port
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
return ret
GLuint GLuint64EXT address
#define QT_TRANSLATE_NOOP(scope, x)
unsigned short quint16
Definition qtypes.h:48
ptrdiff_t qintptr
Definition qtypes.h:166
QObject::connect nullptr
QMutex mutex
[2]
QNetworkProxy proxy
[0]