0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtNetwork module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#ifndef QABSTRACTSOCKETENGINE_P_H
|
|
43 |
#define QABSTRACTSOCKETENGINE_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 "QtNetwork/qhostaddress.h"
|
|
57 |
#include "QtNetwork/qabstractsocket.h"
|
|
58 |
#include "private/qobject_p.h"
|
|
59 |
|
|
60 |
QT_BEGIN_NAMESPACE
|
|
61 |
|
|
62 |
class QAuthenticator;
|
|
63 |
class QAbstractSocketEnginePrivate;
|
|
64 |
class QNetworkProxy;
|
|
65 |
|
|
66 |
class QAbstractSocketEngineReceiver {
|
|
67 |
public:
|
|
68 |
virtual ~QAbstractSocketEngineReceiver(){}
|
|
69 |
virtual void readNotification()= 0;
|
|
70 |
virtual void writeNotification()= 0;
|
|
71 |
virtual void exceptionNotification()= 0;
|
|
72 |
virtual void connectionNotification()= 0;
|
|
73 |
#ifndef QT_NO_NETWORKPROXY
|
|
74 |
virtual void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)= 0;
|
|
75 |
#endif
|
|
76 |
};
|
|
77 |
|
|
78 |
class Q_AUTOTEST_EXPORT QAbstractSocketEngine : public QObject
|
|
79 |
{
|
|
80 |
Q_OBJECT
|
|
81 |
public:
|
|
82 |
|
|
83 |
static QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent);
|
|
84 |
static QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent);
|
|
85 |
|
|
86 |
QAbstractSocketEngine(QObject *parent = 0);
|
|
87 |
|
|
88 |
enum SocketOption {
|
|
89 |
NonBlockingSocketOption,
|
|
90 |
BroadcastSocketOption,
|
|
91 |
ReceiveBufferSocketOption,
|
|
92 |
SendBufferSocketOption,
|
|
93 |
AddressReusable,
|
|
94 |
BindExclusively,
|
|
95 |
ReceiveOutOfBandData,
|
|
96 |
LowDelayOption,
|
|
97 |
KeepAliveOption
|
|
98 |
};
|
|
99 |
|
|
100 |
virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) = 0;
|
|
101 |
|
|
102 |
virtual bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) = 0;
|
|
103 |
|
|
104 |
virtual int socketDescriptor() const = 0;
|
|
105 |
|
|
106 |
virtual bool isValid() const = 0;
|
|
107 |
|
|
108 |
virtual bool connectToHost(const QHostAddress &address, quint16 port) = 0;
|
|
109 |
virtual bool connectToHostByName(const QString &name, quint16 port) = 0;
|
|
110 |
virtual bool bind(const QHostAddress &address, quint16 port) = 0;
|
|
111 |
virtual bool listen() = 0;
|
|
112 |
virtual int accept() = 0;
|
|
113 |
virtual void close() = 0;
|
|
114 |
|
|
115 |
virtual qint64 bytesAvailable() const = 0;
|
|
116 |
|
|
117 |
virtual qint64 read(char *data, qint64 maxlen) = 0;
|
|
118 |
virtual qint64 write(const char *data, qint64 len) = 0;
|
|
119 |
|
|
120 |
#ifndef QT_NO_UDPSOCKET
|
|
121 |
virtual qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr = 0,
|
|
122 |
quint16 *port = 0) = 0;
|
|
123 |
virtual qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr,
|
|
124 |
quint16 port) = 0;
|
|
125 |
virtual bool hasPendingDatagrams() const = 0;
|
|
126 |
virtual qint64 pendingDatagramSize() const = 0;
|
|
127 |
#endif
|
|
128 |
|
|
129 |
virtual int option(SocketOption option) const = 0;
|
|
130 |
virtual bool setOption(SocketOption option, int value) = 0;
|
|
131 |
|
|
132 |
virtual bool waitForRead(int msecs = 30000, bool *timedOut = 0) = 0;
|
|
133 |
virtual bool waitForWrite(int msecs = 30000, bool *timedOut = 0) = 0;
|
|
134 |
virtual bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
|
|
135 |
bool checkRead, bool checkWrite,
|
|
136 |
int msecs = 30000, bool *timedOut = 0) = 0;
|
|
137 |
|
|
138 |
QAbstractSocket::SocketError error() const;
|
|
139 |
QString errorString() const;
|
|
140 |
QAbstractSocket::SocketState state() const;
|
|
141 |
QAbstractSocket::SocketType socketType() const;
|
|
142 |
QAbstractSocket::NetworkLayerProtocol protocol() const;
|
|
143 |
|
|
144 |
QHostAddress localAddress() const;
|
|
145 |
quint16 localPort() const;
|
|
146 |
QHostAddress peerAddress() const;
|
|
147 |
quint16 peerPort() 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 |
|
|
156 |
public Q_SLOTS:
|
|
157 |
void readNotification();
|
|
158 |
void writeNotification();
|
|
159 |
void exceptionNotification();
|
|
160 |
void connectionNotification();
|
|
161 |
#ifndef QT_NO_NETWORKPROXY
|
|
162 |
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
|
|
163 |
#endif
|
|
164 |
|
|
165 |
public:
|
|
166 |
void setReceiver(QAbstractSocketEngineReceiver *receiver);
|
|
167 |
protected:
|
|
168 |
QAbstractSocketEngine(QAbstractSocketEnginePrivate &dd, QObject* parent = 0);
|
|
169 |
|
|
170 |
void setError(QAbstractSocket::SocketError error, const QString &errorString) const;
|
|
171 |
void setState(QAbstractSocket::SocketState state);
|
|
172 |
void setSocketType(QAbstractSocket::SocketType socketType);
|
|
173 |
void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol);
|
|
174 |
void setLocalAddress(const QHostAddress &address);
|
|
175 |
void setLocalPort(quint16 port);
|
|
176 |
void setPeerAddress(const QHostAddress &address);
|
|
177 |
void setPeerPort(quint16 port);
|
|
178 |
|
|
179 |
private:
|
|
180 |
Q_DECLARE_PRIVATE(QAbstractSocketEngine)
|
|
181 |
Q_DISABLE_COPY(QAbstractSocketEngine)
|
|
182 |
};
|
|
183 |
|
|
184 |
class QAbstractSocketEnginePrivate : public QObjectPrivate
|
|
185 |
{
|
|
186 |
Q_DECLARE_PUBLIC(QAbstractSocketEngine)
|
|
187 |
public:
|
|
188 |
QAbstractSocketEnginePrivate();
|
|
189 |
|
|
190 |
mutable QAbstractSocket::SocketError socketError;
|
|
191 |
mutable bool hasSetSocketError;
|
|
192 |
mutable QString socketErrorString;
|
|
193 |
QAbstractSocket::SocketState socketState;
|
|
194 |
QAbstractSocket::SocketType socketType;
|
|
195 |
QAbstractSocket::NetworkLayerProtocol socketProtocol;
|
|
196 |
QHostAddress localAddress;
|
|
197 |
quint16 localPort;
|
|
198 |
QHostAddress peerAddress;
|
|
199 |
quint16 peerPort;
|
|
200 |
QAbstractSocketEngineReceiver *receiver;
|
|
201 |
};
|
|
202 |
|
|
203 |
|
|
204 |
class Q_AUTOTEST_EXPORT QSocketEngineHandler
|
|
205 |
{
|
|
206 |
protected:
|
|
207 |
QSocketEngineHandler();
|
|
208 |
virtual ~QSocketEngineHandler();
|
|
209 |
virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
|
|
210 |
const QNetworkProxy &, QObject *parent) = 0;
|
|
211 |
virtual QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent) = 0;
|
|
212 |
|
|
213 |
private:
|
|
214 |
friend class QAbstractSocketEngine;
|
|
215 |
};
|
|
216 |
|
|
217 |
QT_END_NAMESPACE
|
|
218 |
|
|
219 |
#endif // QABSTRACTSOCKETENGINE_P_H
|