| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtNetwork module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 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 | };
|
|---|
| 97 |
|
|---|
| 98 | virtual bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) = 0;
|
|---|
| 99 |
|
|---|
| 100 | virtual bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) = 0;
|
|---|
| 101 |
|
|---|
| 102 | virtual int socketDescriptor() const = 0;
|
|---|
| 103 |
|
|---|
| 104 | virtual bool isValid() const = 0;
|
|---|
| 105 |
|
|---|
| 106 | virtual bool connectToHost(const QHostAddress &address, quint16 port) = 0;
|
|---|
| 107 | virtual bool connectToHostByName(const QString &name, quint16 port) = 0;
|
|---|
| 108 | virtual bool bind(const QHostAddress &address, quint16 port) = 0;
|
|---|
| 109 | virtual bool listen() = 0;
|
|---|
| 110 | virtual int accept() = 0;
|
|---|
| 111 | virtual void close() = 0;
|
|---|
| 112 |
|
|---|
| 113 | virtual qint64 bytesAvailable() const = 0;
|
|---|
| 114 |
|
|---|
| 115 | virtual qint64 read(char *data, qint64 maxlen) = 0;
|
|---|
| 116 | virtual qint64 write(const char *data, qint64 len) = 0;
|
|---|
| 117 |
|
|---|
| 118 | #ifndef QT_NO_UDPSOCKET
|
|---|
| 119 | virtual qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr = 0,
|
|---|
| 120 | quint16 *port = 0) = 0;
|
|---|
| 121 | virtual qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr,
|
|---|
| 122 | quint16 port) = 0;
|
|---|
| 123 | virtual bool hasPendingDatagrams() const = 0;
|
|---|
| 124 | virtual qint64 pendingDatagramSize() const = 0;
|
|---|
| 125 | #endif
|
|---|
| 126 |
|
|---|
| 127 | virtual int option(SocketOption option) const = 0;
|
|---|
| 128 | virtual bool setOption(SocketOption option, int value) = 0;
|
|---|
| 129 |
|
|---|
| 130 | virtual bool waitForRead(int msecs = 30000, bool *timedOut = 0) = 0;
|
|---|
| 131 | virtual bool waitForWrite(int msecs = 30000, bool *timedOut = 0) = 0;
|
|---|
| 132 | virtual bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
|
|---|
| 133 | bool checkRead, bool checkWrite,
|
|---|
| 134 | int msecs = 30000, bool *timedOut = 0) = 0;
|
|---|
| 135 |
|
|---|
| 136 | QAbstractSocket::SocketError error() const;
|
|---|
| 137 | QString errorString() const;
|
|---|
| 138 | QAbstractSocket::SocketState state() const;
|
|---|
| 139 | QAbstractSocket::SocketType socketType() const;
|
|---|
| 140 | QAbstractSocket::NetworkLayerProtocol protocol() const;
|
|---|
| 141 |
|
|---|
| 142 | QHostAddress localAddress() const;
|
|---|
| 143 | quint16 localPort() const;
|
|---|
| 144 | QHostAddress peerAddress() const;
|
|---|
| 145 | quint16 peerPort() const;
|
|---|
| 146 |
|
|---|
| 147 | virtual bool isReadNotificationEnabled() const = 0;
|
|---|
| 148 | virtual void setReadNotificationEnabled(bool enable) = 0;
|
|---|
| 149 | virtual bool isWriteNotificationEnabled() const = 0;
|
|---|
| 150 | virtual void setWriteNotificationEnabled(bool enable) = 0;
|
|---|
| 151 | virtual bool isExceptionNotificationEnabled() const = 0;
|
|---|
| 152 | virtual void setExceptionNotificationEnabled(bool enable) = 0;
|
|---|
| 153 |
|
|---|
| 154 | public Q_SLOTS:
|
|---|
| 155 | void readNotification();
|
|---|
| 156 | void writeNotification();
|
|---|
| 157 | void exceptionNotification();
|
|---|
| 158 | void connectionNotification();
|
|---|
| 159 | #ifndef QT_NO_NETWORKPROXY
|
|---|
| 160 | void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
|
|---|
| 161 | #endif
|
|---|
| 162 |
|
|---|
| 163 | public:
|
|---|
| 164 | void setReceiver(QAbstractSocketEngineReceiver *receiver);
|
|---|
| 165 | protected:
|
|---|
| 166 | QAbstractSocketEngine(QAbstractSocketEnginePrivate &dd, QObject* parent = 0);
|
|---|
| 167 |
|
|---|
| 168 | void setError(QAbstractSocket::SocketError error, const QString &errorString) const;
|
|---|
| 169 | void setState(QAbstractSocket::SocketState state);
|
|---|
| 170 | void setSocketType(QAbstractSocket::SocketType socketType);
|
|---|
| 171 | void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol);
|
|---|
| 172 | void setLocalAddress(const QHostAddress &address);
|
|---|
| 173 | void setLocalPort(quint16 port);
|
|---|
| 174 | void setPeerAddress(const QHostAddress &address);
|
|---|
| 175 | void setPeerPort(quint16 port);
|
|---|
| 176 |
|
|---|
| 177 | private:
|
|---|
| 178 | Q_DECLARE_PRIVATE(QAbstractSocketEngine)
|
|---|
| 179 | Q_DISABLE_COPY(QAbstractSocketEngine)
|
|---|
| 180 | };
|
|---|
| 181 |
|
|---|
| 182 | class QAbstractSocketEnginePrivate : public QObjectPrivate
|
|---|
| 183 | {
|
|---|
| 184 | Q_DECLARE_PUBLIC(QAbstractSocketEngine)
|
|---|
| 185 | public:
|
|---|
| 186 | QAbstractSocketEnginePrivate();
|
|---|
| 187 |
|
|---|
| 188 | mutable QAbstractSocket::SocketError socketError;
|
|---|
| 189 | mutable bool hasSetSocketError;
|
|---|
| 190 | mutable QString socketErrorString;
|
|---|
| 191 | QAbstractSocket::SocketState socketState;
|
|---|
| 192 | QAbstractSocket::SocketType socketType;
|
|---|
| 193 | QAbstractSocket::NetworkLayerProtocol socketProtocol;
|
|---|
| 194 | QHostAddress localAddress;
|
|---|
| 195 | quint16 localPort;
|
|---|
| 196 | QHostAddress peerAddress;
|
|---|
| 197 | quint16 peerPort;
|
|---|
| 198 | QAbstractSocketEngineReceiver *receiver;
|
|---|
| 199 | };
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 | class Q_AUTOTEST_EXPORT QSocketEngineHandler
|
|---|
| 203 | {
|
|---|
| 204 | protected:
|
|---|
| 205 | QSocketEngineHandler();
|
|---|
| 206 | virtual ~QSocketEngineHandler();
|
|---|
| 207 | virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
|
|---|
| 208 | const QNetworkProxy &, QObject *parent) = 0;
|
|---|
| 209 | virtual QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent) = 0;
|
|---|
| 210 |
|
|---|
| 211 | private:
|
|---|
| 212 | friend class QAbstractSocketEngine;
|
|---|
| 213 | };
|
|---|
| 214 |
|
|---|
| 215 | QT_END_NAMESPACE
|
|---|
| 216 |
|
|---|
| 217 | #endif // QABSTRACTSOCKETENGINE_P_H
|
|---|