Qt 4.8
qabstractsocketengine_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 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 
61 
62 class QAuthenticator;
64 #ifndef QT_NO_NETWORKINTERFACE
65 class QNetworkInterface;
66 #endif
67 class QNetworkProxy;
68 
70 public:
72  virtual void readNotification()= 0;
73  virtual void writeNotification()= 0;
74  virtual void exceptionNotification()= 0;
75  virtual void connectionNotification()= 0;
76 #ifndef QT_NO_NETWORKPROXY
77  virtual void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)= 0;
78 #endif
79 };
80 
82 {
83  Q_OBJECT
84 public:
85 
86  static QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent);
87  static QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent);
88 
89  QAbstractSocketEngine(QObject *parent = 0);
90 
91  enum SocketOption {
102  MulticastLoopbackOption
103  };
104 
106 
107  virtual bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) = 0;
108 
109  virtual int socketDescriptor() const = 0;
110 
111  virtual bool isValid() const = 0;
112 
113  virtual bool connectToHost(const QHostAddress &address, quint16 port) = 0;
114  virtual bool connectToHostByName(const QString &name, quint16 port) = 0;
115  virtual bool bind(const QHostAddress &address, quint16 port) = 0;
116  virtual bool listen() = 0;
117  virtual int accept() = 0;
118  virtual void close() = 0;
119 
120  virtual qint64 bytesAvailable() const = 0;
121 
122  virtual qint64 read(char *data, qint64 maxlen) = 0;
123  virtual qint64 write(const char *data, qint64 len) = 0;
124 
125 #ifndef QT_NO_UDPSOCKET
126 #ifndef QT_NO_NETWORKINTERFACE
127  virtual bool joinMulticastGroup(const QHostAddress &groupAddress,
128  const QNetworkInterface &iface) = 0;
129  virtual bool leaveMulticastGroup(const QHostAddress &groupAddress,
130  const QNetworkInterface &iface) = 0;
131  virtual QNetworkInterface multicastInterface() const = 0;
132  virtual bool setMulticastInterface(const QNetworkInterface &iface) = 0;
133 #endif // QT_NO_NETWORKINTERFACE
134 
135  virtual qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr = 0,
136  quint16 *port = 0) = 0;
137  virtual qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr,
138  quint16 port) = 0;
139  virtual bool hasPendingDatagrams() const = 0;
140  virtual qint64 pendingDatagramSize() const = 0;
141 #endif // QT_NO_UDPSOCKET
142 
143  virtual qint64 bytesToWrite() const = 0;
144 
145  virtual int option(SocketOption option) const = 0;
146  virtual bool setOption(SocketOption option, int value) = 0;
147 
148  virtual bool waitForRead(int msecs = 30000, bool *timedOut = 0) = 0;
149  virtual bool waitForWrite(int msecs = 30000, bool *timedOut = 0) = 0;
150  virtual bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
151  bool checkRead, bool checkWrite,
152  int msecs = 30000, bool *timedOut = 0) = 0;
153 
155  QString errorString() const;
156  QAbstractSocket::SocketState state() const;
157  QAbstractSocket::SocketType socketType() const;
158  QAbstractSocket::NetworkLayerProtocol protocol() const;
159 
160  QHostAddress localAddress() const;
161  quint16 localPort() const;
162  QHostAddress peerAddress() const;
163  quint16 peerPort() const;
164 
165  virtual bool isReadNotificationEnabled() const = 0;
166  virtual void setReadNotificationEnabled(bool enable) = 0;
167  virtual bool isWriteNotificationEnabled() const = 0;
168  virtual void setWriteNotificationEnabled(bool enable) = 0;
169  virtual bool isExceptionNotificationEnabled() const = 0;
170  virtual void setExceptionNotificationEnabled(bool enable) = 0;
171 
172 public Q_SLOTS:
173  void readNotification();
174  void writeNotification();
175  void exceptionNotification();
176  void connectionNotification();
177 #ifndef QT_NO_NETWORKPROXY
178  void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
179 #endif
180 
181 public:
182  void setReceiver(QAbstractSocketEngineReceiver *receiver);
183 protected:
185 
186  void setError(QAbstractSocket::SocketError error, const QString &errorString) const;
187  void setState(QAbstractSocket::SocketState state);
188  void setSocketType(QAbstractSocket::SocketType socketType);
189  void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol);
190  void setLocalAddress(const QHostAddress &address);
191  void setLocalPort(quint16 port);
192  void setPeerAddress(const QHostAddress &address);
193  void setPeerPort(quint16 port);
194 
195 private:
198 };
199 
201 {
203 public:
205 
207  mutable bool hasSetSocketError;
217 };
218 
219 
221 {
222 protected:
224  virtual ~QSocketEngineHandler();
225  virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
226  const QNetworkProxy &, QObject *parent) = 0;
227  virtual QAbstractSocketEngine *createSocketEngine(int socketDescripter, QObject *parent) = 0;
228 
229 private:
230  friend class QAbstractSocketEngine;
231 };
232 
234 
235 #endif // QABSTRACTSOCKETENGINE_P_H
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 void writeNotification()=0
#define error(msg)
QAbstractSocketEngineReceiver * receiver
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_SLOTS
Definition: qobjectdefs.h:71
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 void exceptionNotification()=0
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
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 void readNotification()=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)
QAbstractSocket::SocketError socketError
__int64 qint64
Definition: qglobal.h:942
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QAuthenticator class provides an authentication object.
QAbstractSocket::SocketType socketType
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
virtual void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)=0
QAbstractSocket::SocketState socketState
virtual void connectionNotification()=0
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
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
QAbstractSocket::NetworkLayerProtocol socketProtocol