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
qabstractsocket_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QABSTRACTSOCKET_P_H
6#define QABSTRACTSOCKET_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 QAbstractSocket 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#include "QtNetwork/qabstractsocket.h"
21#include "QtCore/qbytearray.h"
22#include "QtCore/qlist.h"
23#include "QtCore/qtimer.h"
24#include "private/qiodevice_p.h"
25#include "private/qabstractsocketengine_p.h"
26#include "qnetworkproxy.h"
27
28QT_BEGIN_NAMESPACE
29
30class QHostInfo;
31class QNetworkInterface;
32
33class Q_NETWORK_EXPORT QAbstractSocketPrivate : public QIODevicePrivate,
34 public QAbstractSocketEngineReceiver
35{
36 Q_DECLARE_PUBLIC(QAbstractSocket)
37public:
38 QAbstractSocketPrivate(decltype(QObjectPrivateVersion) version = QObjectPrivateVersion);
39 virtual ~QAbstractSocketPrivate();
40
41 // from QAbstractSocketEngineReceiver
42 inline void readNotification() override { canReadNotification(); }
43 inline void writeNotification() override { canWriteNotification(); }
44 inline void exceptionNotification() override {}
45 inline void closeNotification() override { canCloseNotification(); }
46 void connectionNotification() override;
47#ifndef QT_NO_NETWORKPROXY
48 inline void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) override {
49 Q_Q(QAbstractSocket);
50 emit q->proxyAuthenticationRequired(proxy, authenticator);
51 }
52#endif
53
54 virtual bool bind(const QHostAddress &address, quint16 port, QAbstractSocket::BindMode mode,
55 const QNetworkInterface *iface = nullptr);
56
57 virtual bool canReadNotification();
58 bool canWriteNotification();
59 void canCloseNotification();
60
61 // slots
62 void _q_connectToNextAddress();
63 void _q_startConnecting(const QHostInfo &hostInfo);
64 void _q_testConnection();
65 void _q_abortConnectionAttempt();
66
67 bool emittedReadyRead = false;
68 bool emittedBytesWritten = false;
69
70 bool abortCalled = false;
71 bool pendingClose = false;
72
73 QAbstractSocket::PauseModes pauseMode = QAbstractSocket::PauseNever;
74
75 QString hostName;
76 quint16 port = 0;
77 QHostAddress host;
78 QList<QHostAddress> addresses;
79
80 quint16 localPort = 0;
81 quint16 peerPort = 0;
82 QHostAddress localAddress;
83 QHostAddress peerAddress;
84 QString peerName;
85
86 QAbstractSocketEngine *socketEngine = nullptr;
87 qintptr cachedSocketDescriptor = -1;
88
89#ifndef QT_NO_NETWORKPROXY
90 QNetworkProxy proxy;
91 QNetworkProxy proxyInUse;
92 QString protocolTag;
93 void resolveProxy(const QString &hostName, quint16 port);
94#else
95 inline void resolveProxy(const QString &, quint16) { }
96#endif
97 inline void resolveProxy(quint16 port) { resolveProxy(QString(), port); }
98
99 void resetSocketLayer();
100 virtual bool flush();
101
102 bool initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol);
103 virtual void configureCreatedSocket();
104 void startConnectingByName(const QString &host);
105 void fetchConnectionParameters();
106 bool readFromSocket();
107 virtual bool writeToSocket();
108 void emitReadyRead(int channel = 0);
109 void emitBytesWritten(qint64 bytes, int channel = 0);
110
111 void setError(QAbstractSocket::SocketError errorCode, const QString &errorString);
112 void setErrorAndEmit(QAbstractSocket::SocketError errorCode, const QString &errorString);
113
114 qint64 readBufferMaxSize = 0;
115 bool isBuffered = false;
116 bool hasPendingData = false;
117 bool hasPendingDatagram = false;
118
119 QTimer *connectTimer = nullptr;
120
121 int hostLookupId = -1;
122
123 QAbstractSocket::SocketType socketType = QAbstractSocket::UnknownSocketType;
124 QAbstractSocket::SocketState state = QAbstractSocket::UnconnectedState;
125
126 // Must be kept in sync with QIODevicePrivate::errorString.
127 QAbstractSocket::SocketError socketError = QAbstractSocket::UnknownSocketError;
128
129 QAbstractSocket::NetworkLayerProtocol preferredNetworkLayerProtocol =
130 QAbstractSocket::UnknownNetworkLayerProtocol;
131
132 bool prePauseReadSocketNotifierState = false;
133 bool prePauseWriteSocketNotifierState = false;
134 bool prePauseExceptionSocketNotifierState = false;
135 static void pauseSocketNotifiers(QAbstractSocket*);
136 static void resumeSocketNotifiers(QAbstractSocket*);
137 static QAbstractSocketEngine* getSocketEngine(QAbstractSocket*);
138};
139
140QT_END_NAMESPACE
141
142#endif // QABSTRACTSOCKET_P_H
static bool isProxyError(QAbstractSocket::SocketError error)
#define QABSTRACTSOCKET_BUFFERSIZE
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568