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
qhttpsocketengine_p.h
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
4#ifndef QHTTPSOCKETENGINE_P_H
5#define QHTTPSOCKETENGINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/private/qtnetworkglobal_p.h>
19
20#include <QtNetwork/qnetworkproxy.h>
21
23#include "private/qauthenticator_p.h"
24#include "private/qabstractsocketengine_p.h"
25
26QT_REQUIRE_CONFIG(http);
27
28QT_BEGIN_NAMESPACE
29
30#if !defined(QT_NO_NETWORKPROXY)
31
32class QTcpSocket;
33class QHttpNetworkReply;
35
36class Q_AUTOTEST_EXPORT QHttpSocketEngine : public QAbstractSocketEngine
37{
38 Q_OBJECT
39public:
40 enum HttpState {
41 None,
42 ConnectSent,
43 Connected,
44 SendAuthentication,
45 ReadResponseContent,
46 ReadResponseHeader
47 };
48 QHttpSocketEngine(QObject *parent = nullptr);
49 ~QHttpSocketEngine();
50
51 bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) override;
52 bool initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) override;
53
54 void setProxy(const QNetworkProxy &networkProxy);
55
56 qintptr socketDescriptor() const override;
57
58 bool isValid() const override;
59
60 bool connectInternal();
61 bool connectToHost(const QHostAddress &address, quint16 port) override;
62 bool connectToHostByName(const QString &name, quint16 port) override;
63 bool bind(const QHostAddress &address, quint16 port) override;
64 bool listen(int backlog) override;
65 qintptr accept() override;
66 void close() override;
67
68 qint64 bytesAvailable() const override;
69
70 qint64 read(char *data, qint64 maxlen) override;
71 qint64 write(const char *data, qint64 len) override;
72
73#ifndef QT_NO_UDPSOCKET
74#ifndef QT_NO_NETWORKINTERFACE
75 bool joinMulticastGroup(const QHostAddress &groupAddress,
76 const QNetworkInterface &interface) override;
77 bool leaveMulticastGroup(const QHostAddress &groupAddress,
78 const QNetworkInterface &interface) override;
79 QNetworkInterface multicastInterface() const override;
80 bool setMulticastInterface(const QNetworkInterface &iface) override;
81#endif // QT_NO_NETWORKINTERFACE
82
83 bool hasPendingDatagrams() const override;
84 qint64 pendingDatagramSize() const override;
85#endif // QT_NO_UDPSOCKET
86
87 qint64 readDatagram(char *data, qint64 maxlen, QIpPacketHeader *,
88 PacketHeaderOptions) override;
89 qint64 writeDatagram(const char *data, qint64 len, const QIpPacketHeader &) override;
90 qint64 bytesToWrite() const override;
91
92 int option(SocketOption option) const override;
93 bool setOption(SocketOption option, int value) override;
94
95 bool waitForRead(QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
96 bool *timedOut = nullptr) override;
97 bool waitForWrite(QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
98 bool *timedOut = nullptr) override;
99 bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
100 bool checkRead, bool checkWrite,
101 QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
102 bool *timedOut = nullptr) override;
103
104 void waitForProtocolHandshake(QDeadlineTimer deadline) const;
105
106 bool isReadNotificationEnabled() const override;
107 void setReadNotificationEnabled(bool enable) override;
108 bool isWriteNotificationEnabled() const override;
109 void setWriteNotificationEnabled(bool enable) override;
110 bool isExceptionNotificationEnabled() const override;
111 void setExceptionNotificationEnabled(bool enable) override;
112
113public slots:
114 void slotSocketConnected();
115 void slotSocketDisconnected();
116 void slotSocketReadNotification();
117 void slotSocketBytesWritten();
118 void slotSocketError(QAbstractSocket::SocketError error);
119 void slotSocketStateChanged(QAbstractSocket::SocketState state);
120
121private slots:
122 void emitPendingReadNotification();
123 void emitPendingWriteNotification();
124 void emitPendingConnectionNotification();
125
126private:
127 void emitReadNotification();
128 void emitWriteNotification();
129 void emitConnectionNotification();
130
131 bool readHttpHeader();
132
133 Q_DECLARE_PRIVATE(QHttpSocketEngine)
134 Q_DISABLE_COPY_MOVE(QHttpSocketEngine)
135
136};
137
138
161
162class Q_AUTOTEST_EXPORT QHttpSocketEngineHandler : public QSocketEngineHandler
163{
164public:
165 virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
166 const QNetworkProxy &, QObject *parent) override;
167 virtual QAbstractSocketEngine *createSocketEngine(qintptr socketDescripter, QObject *parent) override;
168};
169#endif
170
171QT_END_NAMESPACE
172
173#endif // QHTTPSOCKETENGINE_H
Combined button and popup list for selecting options.