Qt 4.8
qhttpsocketengine_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QHTTPSOCKETENGINE_P_H
43 #define QHTTPSOCKETENGINE_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "private/qabstractsocketengine_p.h"
57 #include "qabstractsocket.h"
58 #include "qnetworkproxy.h"
59 #include "private/qauthenticator_p.h"
60 
62 
63 #if !defined(QT_NO_NETWORKPROXY) && !defined(QT_NO_HTTP)
64 
65 class QTcpSocket;
67 
69 {
70  Q_OBJECT
71 public:
72  enum HttpState {
77  ReadResponseContent
78  };
79  QHttpSocketEngine(QObject *parent = 0);
81 
83  bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
84 
85  void setProxy(const QNetworkProxy &networkProxy);
86 
87  int socketDescriptor() const;
88 
89  bool isValid() const;
90 
91  bool connectInternal();
92  bool connectToHost(const QHostAddress &address, quint16 port);
93  bool connectToHostByName(const QString &name, quint16 port);
94  bool bind(const QHostAddress &address, quint16 port);
95  bool listen();
96  int accept();
97  void close();
98 
99  qint64 bytesAvailable() const;
100 
101  qint64 read(char *data, qint64 maxlen);
102  qint64 write(const char *data, qint64 len);
103 
104 #ifndef QT_NO_UDPSOCKET
105 #ifndef QT_NO_NETWORKINTERFACE
106  bool joinMulticastGroup(const QHostAddress &groupAddress,
107  const QNetworkInterface &interface);
108  bool leaveMulticastGroup(const QHostAddress &groupAddress,
109  const QNetworkInterface &interface);
111  bool setMulticastInterface(const QNetworkInterface &iface);
112 #endif // QT_NO_NETWORKINTERFACE
113 
114  qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr = 0,
115  quint16 *port = 0);
116  qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr,
117  quint16 port);
118  bool hasPendingDatagrams() const;
119  qint64 pendingDatagramSize() const;
120 #endif // QT_NO_UDPSOCKET
121 
122  qint64 bytesToWrite() const;
123 
124  int option(SocketOption option) const;
125  bool setOption(SocketOption option, int value);
126 
127  bool waitForRead(int msecs = 30000, bool *timedOut = 0);
128  bool waitForWrite(int msecs = 30000, bool *timedOut = 0);
129  bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
130  bool checkRead, bool checkWrite,
131  int msecs = 30000, bool *timedOut = 0);
132 
133  bool isReadNotificationEnabled() const;
134  void setReadNotificationEnabled(bool enable);
135  bool isWriteNotificationEnabled() const;
136  void setWriteNotificationEnabled(bool enable);
137  bool isExceptionNotificationEnabled() const;
138  void setExceptionNotificationEnabled(bool enable);
139 
140 public slots:
141  void slotSocketConnected();
142  void slotSocketDisconnected();
143  void slotSocketReadNotification();
144  void slotSocketBytesWritten();
145  void slotSocketError(QAbstractSocket::SocketError error);
146  void slotSocketStateChanged(QAbstractSocket::SocketState state);
147 
148 private slots:
149  void emitPendingReadNotification();
150  void emitPendingWriteNotification();
151  void emitPendingConnectionNotification();
152 
153 private:
154  void emitReadNotification();
155  void emitWriteNotification();
156  void emitConnectionNotification();
157 
160 
161 };
162 
163 
165 {
167 public:
170 
174  QByteArray readBuffer; // only used for parsing the proxy response
187 };
188 
190 {
191 public:
192  virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
193  const QNetworkProxy &, QObject *parent);
194  virtual QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent);
195 };
196 #endif
197 
199 
200 #endif // QHTTPSOCKETENGINE_H
virtual bool isReadNotificationEnabled() const =0
virtual bool waitForRead(int msecs=30000, bool *timedOut=0)=0
virtual void setExceptionNotificationEnabled(bool enable)=0
virtual qint64 bytesToWrite() const =0
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
SocketType
This enum describes the transport layer protocol.
virtual int socketDescriptor() const =0
virtual bool connectToHostByName(const QString &name, quint16 port)=0
QHttpSocketEngine::HttpState state
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
virtual bool bind(const QHostAddress &address, quint16 port)=0
NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
The QString class provides a Unicode character string.
Definition: qstring.h:83
virtual int option(SocketOption option) const =0
virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol)=0
virtual int accept()=0
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
SocketState
This enum describes the different states in which a socket can be.
The QNetworkProxy class provides a network layer proxy.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual bool isWriteNotificationEnabled() const =0
virtual bool leaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)=0
virtual void setWriteNotificationEnabled(bool enable)=0
const char * name
SocketError
This enum describes the socket errors that can occur.
unsigned short quint16
Definition: qglobal.h:936
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
__int64 qint64
Definition: qglobal.h:942
virtual bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &iface)=0
virtual qint64 write(const char *data, qint64 len)=0
virtual bool listen()=0
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAuthenticator class provides an authentication object.
virtual bool hasPendingDatagrams() const =0
virtual QNetworkInterface multicastInterface() const =0
virtual qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr=0, quint16 *port=0)=0
virtual bool isExceptionNotificationEnabled() const =0
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
virtual bool setMulticastInterface(const QNetworkInterface &iface)=0
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
virtual void close()=0
virtual bool waitForWrite(int msecs=30000, bool *timedOut=0)=0
virtual bool setOption(SocketOption option, int value)=0
virtual qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr, quint16 port)=0
virtual qint64 read(char *data, qint64 maxlen)=0
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
virtual bool isValid() const =0
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces...
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
#define slots
Definition: qobjectdefs.h:68
virtual void setReadNotificationEnabled(bool enable)=0
virtual bool connectToHost(const QHostAddress &address, quint16 port)=0
virtual bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=0)=0
virtual qint64 bytesAvailable() const =0
virtual qint64 pendingDatagramSize() const =0