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
qabstractsocketengine_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QABSTRACTSOCKETENGINE_P_H
7#define QABSTRACTSOCKETENGINE_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtNetwork/private/qtnetworkglobal_p.h>
21#include "QtNetwork/qhostaddress.h"
22#include "QtNetwork/qabstractsocket.h"
23#include <QtCore/qdeadlinetimer.h>
24#include "private/qabstractsocketenginereceiver_p.h"
25#include "private/qnetworkdatagram_p.h"
26#include "private/qobject_p.h"
27
29
30class QAuthenticator;
32#ifndef QT_NO_NETWORKINTERFACE
33class QNetworkInterface;
34#endif
35class QNetworkProxy;
36
37static constexpr std::chrono::seconds DefaultTimeout{30};
38
39class Q_AUTOTEST_EXPORT QAbstractSocketEngine : public QObject
40{
41 Q_OBJECT
42 Q_MOC_INCLUDE(<QtNetwork/qauthenticator.h>)
43public:
44
45 static QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent);
46 static QAbstractSocketEngine *createSocketEngine(qintptr socketDescriptor, QObject *parent);
47
48 QAbstractSocketEngine(QObject *parent = nullptr);
49
50 enum SocketOption {
51 NonBlockingSocketOption,
52 BroadcastSocketOption,
53 ReceiveBufferSocketOption,
54 SendBufferSocketOption,
55 AddressReusable,
56 BindExclusively,
57 ReceiveOutOfBandData,
58 LowDelayOption,
59 KeepAliveOption,
60 MulticastTtlOption,
61 MulticastLoopbackOption,
62 TypeOfServiceOption,
63 ReceivePacketInformation,
64 ReceiveHopLimit,
65 MaxStreamsSocketOption,
66 PathMtuInformation,
67 BindInterfaceIndex,
68 KeepAliveIdleOption,
69 KeepAliveIntervalOption,
70 KeepAliveCountOption,
71 };
72
73 enum PacketHeaderOption {
74 WantNone = 0,
75 WantDatagramSender = 0x01,
76 WantDatagramDestination = 0x02,
77 WantDatagramHopLimit = 0x04,
78 WantStreamNumber = 0x08,
79 WantEndOfRecord = 0x10,
80
81 WantAll = 0xff
82 };
83 Q_DECLARE_FLAGS(PacketHeaderOptions, PacketHeaderOption)
84
85 virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) = 0;
86
87 virtual bool initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) = 0;
88
89 virtual qintptr socketDescriptor() const = 0;
90
91 virtual bool isValid() const = 0;
92
93 virtual bool connectToHost(const QHostAddress &address, quint16 port) = 0;
94 virtual bool connectToHostByName(const QString &name, quint16 port) = 0;
95 virtual bool bind(const QHostAddress &address, quint16 port) = 0;
96 virtual bool listen(int backlog) = 0;
97 virtual qintptr accept() = 0;
98 virtual void close() = 0;
99
100 virtual qint64 bytesAvailable() const = 0;
101
102 virtual qint64 read(char *data, qint64 maxlen) = 0;
103 virtual qint64 write(const char *data, qint64 len) = 0;
104
105#ifndef QT_NO_UDPSOCKET
106#ifndef QT_NO_NETWORKINTERFACE
107 virtual bool joinMulticastGroup(const QHostAddress &groupAddress,
108 const QNetworkInterface &iface) = 0;
109 virtual bool leaveMulticastGroup(const QHostAddress &groupAddress,
110 const QNetworkInterface &iface) = 0;
111 virtual QNetworkInterface multicastInterface() const = 0;
112 virtual bool setMulticastInterface(const QNetworkInterface &iface) = 0;
113#endif // QT_NO_NETWORKINTERFACE
114
115 virtual bool hasPendingDatagrams() const = 0;
116 virtual qint64 pendingDatagramSize() const = 0;
117#endif // QT_NO_UDPSOCKET
118
119 virtual qint64 readDatagram(char *data, qint64 maxlen, QIpPacketHeader *header = nullptr,
120 PacketHeaderOptions = WantNone) = 0;
121 virtual qint64 writeDatagram(const char *data, qint64 len, const QIpPacketHeader &header) = 0;
122 virtual qint64 bytesToWrite() const = 0;
123
124 virtual int option(SocketOption option) const = 0;
125 virtual bool setOption(SocketOption option, int value) = 0;
126
127 virtual bool waitForRead(QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
128 bool *timedOut = nullptr) = 0;
129 virtual bool waitForWrite(QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
130 bool *timedOut = nullptr) = 0;
131 virtual bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
132 bool checkRead, bool checkWrite,
133 QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
134 bool *timedOut = nullptr) = 0;
135
136 QAbstractSocket::SocketError error() const;
137 QString errorString() const;
138 QAbstractSocket::SocketState state() const;
139 QAbstractSocket::SocketType socketType() const;
140 QAbstractSocket::NetworkLayerProtocol protocol() const;
141
142 QHostAddress localAddress() const;
143 quint16 localPort() const;
144 QHostAddress peerAddress() const;
145 quint16 peerPort() const;
146 int inboundStreamCount() const;
147 int outboundStreamCount() const;
148
149 virtual bool isReadNotificationEnabled() const = 0;
150 virtual void setReadNotificationEnabled(bool enable) = 0;
151 virtual bool isWriteNotificationEnabled() const = 0;
152 virtual void setWriteNotificationEnabled(bool enable) = 0;
153 virtual bool isExceptionNotificationEnabled() const = 0;
154 virtual void setExceptionNotificationEnabled(bool enable) = 0;
155
156public Q_SLOTS:
157 void readNotification();
158 void writeNotification();
159 void closeNotification();
160 void exceptionNotification();
161 void connectionNotification();
162#ifndef QT_NO_NETWORKPROXY
163 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
164#endif
165
166public:
167 void setReceiver(QAbstractSocketEngineReceiver *receiver);
168protected:
169 QAbstractSocketEngine(QAbstractSocketEnginePrivate &dd, QObject* parent = nullptr);
170
171 void setError(QAbstractSocket::SocketError error, const QString &errorString) const;
172 void setState(QAbstractSocket::SocketState state);
173 void setSocketType(QAbstractSocket::SocketType socketType);
174 void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol);
175 void setLocalAddress(const QHostAddress &address);
176 void setLocalPort(quint16 port);
177 void setPeerAddress(const QHostAddress &address);
178 void setPeerPort(quint16 port);
179
180private:
181 Q_DECLARE_PRIVATE(QAbstractSocketEngine)
182 Q_DISABLE_COPY_MOVE(QAbstractSocketEngine)
183};
184
205
206
207class Q_AUTOTEST_EXPORT QSocketEngineHandler
208{
209protected:
210 QSocketEngineHandler();
211 virtual ~QSocketEngineHandler();
212 virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
213 const QNetworkProxy &, QObject *parent) = 0;
214 virtual QAbstractSocketEngine *createSocketEngine(qintptr socketDescriptor, QObject *parent) = 0;
215
216private:
217 friend class QAbstractSocketEngine;
218};
219
220Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractSocketEngine::PacketHeaderOptions)
221
222QT_END_NAMESPACE
223
224#endif // QABSTRACTSOCKETENGINE_P_H
QAbstractSocketEngineReceiver * receiver
Combined button and popup list for selecting options.
static bool isProxyError(QAbstractSocket::SocketError error)
#define QABSTRACTSOCKET_BUFFERSIZE
static constexpr std::chrono::seconds DefaultTimeout