1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtNetwork module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QABSTRACTSOCKET_P_H
41#define QABSTRACTSOCKET_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of the QAbstractSocket class. This header file may change from
49// version to version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtNetwork/private/qtnetworkglobal_p.h>
55#include "QtNetwork/qabstractsocket.h"
56#include "QtCore/qbytearray.h"
57#include "QtCore/qlist.h"
58#include "QtCore/qtimer.h"
59#include "private/qiodevice_p.h"
60#include "private/qabstractsocketengine_p.h"
61#include "qnetworkproxy.h"
62
63QT_BEGIN_NAMESPACE
64
65class QHostInfo;
66
67class QAbstractSocketPrivate : public QIODevicePrivate, public QAbstractSocketEngineReceiver
68{
69 Q_DECLARE_PUBLIC(QAbstractSocket)
70public:
71 QAbstractSocketPrivate();
72 virtual ~QAbstractSocketPrivate();
73
74 // from QAbstractSocketEngineReceiver
75 inline void readNotification() override { canReadNotification(); }
76 inline void writeNotification() override { canWriteNotification(); }
77 inline void exceptionNotification() override {}
78 inline void closeNotification() override { canCloseNotification(); }
79 void connectionNotification() override;
80#ifndef QT_NO_NETWORKPROXY
81 inline void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) override {
82 Q_Q(QAbstractSocket);
83 emit q->proxyAuthenticationRequired(proxy, authenticator);
84 }
85#endif
86
87 virtual bool bind(const QHostAddress &address, quint16 port, QAbstractSocket::BindMode mode);
88
89 virtual bool canReadNotification();
90 bool canWriteNotification();
91 void canCloseNotification();
92
93 // slots
94 void _q_connectToNextAddress();
95 void _q_startConnecting(const QHostInfo &hostInfo);
96 void _q_testConnection();
97 void _q_abortConnectionAttempt();
98
99 bool emittedReadyRead;
100 bool emittedBytesWritten;
101
102 bool abortCalled;
103 bool pendingClose;
104
105 QAbstractSocket::PauseModes pauseMode;
106
107 QString hostName;
108 quint16 port;
109 QHostAddress host;
110 QList<QHostAddress> addresses;
111
112 quint16 localPort;
113 quint16 peerPort;
114 QHostAddress localAddress;
115 QHostAddress peerAddress;
116 QString peerName;
117
118 QAbstractSocketEngine *socketEngine;
119 qintptr cachedSocketDescriptor;
120
121#ifndef QT_NO_NETWORKPROXY
122 QNetworkProxy proxy;
123 QNetworkProxy proxyInUse;
124 QString protocolTag;
125 void resolveProxy(const QString &hostName, quint16 port);
126#else
127 inline void resolveProxy(const QString &, quint16) { }
128#endif
129 inline void resolveProxy(quint16 port) { resolveProxy(QString(), port); }
130
131 void resetSocketLayer();
132 virtual bool flush();
133
134 bool initSocketLayer(QAbstractSocket::NetworkLayerProtocol protocol);
135 virtual void configureCreatedSocket();
136 void startConnectingByName(const QString &host);
137 void fetchConnectionParameters();
138 bool readFromSocket();
139 virtual bool writeToSocket();
140 void emitReadyRead(int channel = 0);
141 void emitBytesWritten(qint64 bytes, int channel = 0);
142
143 void setError(QAbstractSocket::SocketError errorCode, const QString &errorString);
144 void setErrorAndEmit(QAbstractSocket::SocketError errorCode, const QString &errorString);
145
146 qint64 readBufferMaxSize;
147 bool isBuffered;
148 bool hasPendingData;
149
150 QTimer *connectTimer;
151
152 int hostLookupId;
153
154 QAbstractSocket::SocketType socketType;
155 QAbstractSocket::SocketState state;
156
157 // Must be kept in sync with QIODevicePrivate::errorString.
158 QAbstractSocket::SocketError socketError;
159
160 QAbstractSocket::NetworkLayerProtocol preferredNetworkLayerProtocol;
161
162 bool prePauseReadSocketNotifierState;
163 bool prePauseWriteSocketNotifierState;
164 bool prePauseExceptionSocketNotifierState;
165 static void pauseSocketNotifiers(QAbstractSocket*);
166 static void resumeSocketNotifiers(QAbstractSocket*);
167 static QAbstractSocketEngine* getSocketEngine(QAbstractSocket*);
168};
169
170QT_END_NAMESPACE
171
172#endif // QABSTRACTSOCKET_P_H
173