source: trunk/src/network/socket/qnativesocketengine_p.h@ 755

Last change on this file since 755 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 8.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtNetwork module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** 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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QNATIVESOCKETENGINE_P_H
43#define QNATIVESOCKETENGINE_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 for the convenience
50// of the QLibrary class. This header file may change from
51// version to version without notice, or even be removed.
52//
53// We mean it.
54//
55#include "QtNetwork/qhostaddress.h"
56#include "private/qabstractsocketengine_p.h"
57#ifndef Q_OS_WIN
58# include "qplatformdefs.h"
59#else
60# include <winsock2.h>
61#endif
62
63#ifdef Q_OS_SYMBIAN
64#include <private/qeventdispatcher_symbian_p.h>
65#include <unistd.h>
66#endif
67
68QT_BEGIN_NAMESPACE
69
70// Use our own defines and structs which we know are correct
71# define QT_SS_MAXSIZE 128
72# define QT_SS_ALIGNSIZE (sizeof(qint64))
73# define QT_SS_PAD1SIZE (QT_SS_ALIGNSIZE - sizeof (short))
74# define QT_SS_PAD2SIZE (QT_SS_MAXSIZE - (sizeof (short) + QT_SS_PAD1SIZE + QT_SS_ALIGNSIZE))
75struct qt_sockaddr_storage {
76 short ss_family;
77 char __ss_pad1[QT_SS_PAD1SIZE];
78 qint64 __ss_align;
79 char __ss_pad2[QT_SS_PAD2SIZE];
80};
81
82// sockaddr_in6 size changed between old and new SDK
83// Only the new version is the correct one, so always
84// use this structure.
85struct qt_in6_addr {
86 quint8 qt_s6_addr[16];
87};
88struct qt_sockaddr_in6 {
89 short sin6_family; /* AF_INET6 */
90 quint16 sin6_port; /* Transport level port number */
91 quint32 sin6_flowinfo; /* IPv6 flow information */
92 struct qt_in6_addr sin6_addr; /* IPv6 address */
93 quint32 sin6_scope_id; /* set of interfaces for a scope */
94};
95
96union qt_sockaddr {
97 sockaddr a;
98 sockaddr_in a4;
99 qt_sockaddr_in6 a6;
100 qt_sockaddr_storage storage;
101};
102
103class QNativeSocketEnginePrivate;
104
105class Q_AUTOTEST_EXPORT QNativeSocketEngine : public QAbstractSocketEngine
106{
107 Q_OBJECT
108public:
109 QNativeSocketEngine(QObject *parent = 0);
110 ~QNativeSocketEngine();
111
112 bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol);
113 bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
114
115 int socketDescriptor() const;
116
117 bool isValid() const;
118
119 bool connectToHost(const QHostAddress &address, quint16 port);
120 bool connectToHostByName(const QString &name, quint16 port);
121 bool bind(const QHostAddress &address, quint16 port);
122 bool listen();
123 int accept();
124 void close();
125
126 qint64 bytesAvailable() const;
127
128 qint64 read(char *data, qint64 maxlen);
129 qint64 write(const char *data, qint64 len);
130
131 qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr = 0,
132 quint16 *port = 0);
133 qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr,
134 quint16 port);
135 bool hasPendingDatagrams() const;
136 qint64 pendingDatagramSize() const;
137
138 qint64 bytesToWrite() const;
139
140 qint64 receiveBufferSize() const;
141 void setReceiveBufferSize(qint64 bufferSize);
142
143 qint64 sendBufferSize() const;
144 void setSendBufferSize(qint64 bufferSize);
145
146 int option(SocketOption option) const;
147 bool setOption(SocketOption option, int value);
148
149 bool waitForRead(int msecs = 30000, bool *timedOut = 0);
150 bool waitForWrite(int msecs = 30000, bool *timedOut = 0);
151 bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
152 bool checkRead, bool checkWrite,
153 int msecs = 30000, bool *timedOut = 0);
154
155 bool isReadNotificationEnabled() const;
156 void setReadNotificationEnabled(bool enable);
157 bool isWriteNotificationEnabled() const;
158 void setWriteNotificationEnabled(bool enable);
159 bool isExceptionNotificationEnabled() const;
160 void setExceptionNotificationEnabled(bool enable);
161
162public Q_SLOTS:
163 // non-virtual override;
164 void connectionNotification();
165
166private:
167 Q_DECLARE_PRIVATE(QNativeSocketEngine)
168 Q_DISABLE_COPY(QNativeSocketEngine)
169};
170
171#ifdef Q_OS_WIN
172class QWindowsSockInit
173{
174public:
175 QWindowsSockInit();
176 ~QWindowsSockInit();
177 int version;
178};
179#endif
180
181class QSocketNotifier;
182
183class QNativeSocketEnginePrivate : public QAbstractSocketEnginePrivate
184{
185 Q_DECLARE_PUBLIC(QNativeSocketEngine)
186public:
187 QNativeSocketEnginePrivate();
188 ~QNativeSocketEnginePrivate();
189
190 int socketDescriptor;
191
192 QSocketNotifier *readNotifier, *writeNotifier, *exceptNotifier;
193
194#ifdef Q_OS_WIN
195 QWindowsSockInit winSock;
196#endif
197
198 enum ErrorString {
199 NonBlockingInitFailedErrorString,
200 BroadcastingInitFailedErrorString,
201 NoIpV6ErrorString,
202 RemoteHostClosedErrorString,
203 TimeOutErrorString,
204 ResourceErrorString,
205 OperationUnsupportedErrorString,
206 ProtocolUnsupportedErrorString,
207 InvalidSocketErrorString,
208 HostUnreachableErrorString,
209 NetworkUnreachableErrorString,
210 AccessErrorString,
211 ConnectionTimeOutErrorString,
212 ConnectionRefusedErrorString,
213 AddressInuseErrorString,
214 AddressNotAvailableErrorString,
215 AddressProtectedErrorString,
216 DatagramTooLargeErrorString,
217 SendDatagramErrorString,
218 ReceiveDatagramErrorString,
219 WriteErrorString,
220 ReadErrorString,
221 PortInuseErrorString,
222 NotSocketErrorString,
223 InvalidProxyTypeString,
224
225 UnknownSocketErrorString = -1
226 };
227
228 void setError(QAbstractSocket::SocketError error, ErrorString errorString) const;
229
230 // native functions
231 int option(QNativeSocketEngine::SocketOption option) const;
232 bool setOption(QNativeSocketEngine::SocketOption option, int value);
233
234 bool createNewSocket(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol);
235
236 bool nativeConnect(const QHostAddress &address, quint16 port);
237 bool nativeBind(const QHostAddress &address, quint16 port);
238 bool nativeListen(int backlog);
239 int nativeAccept();
240 qint64 nativeBytesAvailable() const;
241
242 bool nativeHasPendingDatagrams() const;
243 qint64 nativePendingDatagramSize() const;
244 qint64 nativeReceiveDatagram(char *data, qint64 maxLength,
245 QHostAddress *address, quint16 *port);
246 qint64 nativeSendDatagram(const char *data, qint64 length,
247 const QHostAddress &host, quint16 port);
248 qint64 nativeRead(char *data, qint64 maxLength);
249 qint64 nativeWrite(const char *data, qint64 length);
250 int nativeSelect(int timeout, bool selectForRead) const;
251 int nativeSelect(int timeout, bool checkRead, bool checkWrite,
252 bool *selectForRead, bool *selectForWrite) const;
253
254 void nativeClose();
255
256 bool checkProxy(const QHostAddress &address);
257 bool fetchConnectionParameters();
258};
259
260QT_END_NAMESPACE
261
262#endif // QNATIVESOCKETENGINE_P_H
Note: See TracBrowser for help on using the repository browser.