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 Qt3Support 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 Q3SOCKETDEVICE_H
|
|
43 |
#define Q3SOCKETDEVICE_H
|
|
44 |
|
|
45 |
#include <QtCore/qiodevice.h>
|
|
46 |
#include <QtNetwork/qhostaddress.h> // int->QHostAddress conversion
|
|
47 |
|
|
48 |
QT_BEGIN_HEADER
|
|
49 |
|
|
50 |
QT_BEGIN_NAMESPACE
|
|
51 |
|
|
52 |
QT_MODULE(Qt3Support)
|
|
53 |
|
|
54 |
#ifndef QT_NO_NETWORK
|
|
55 |
|
|
56 |
class Q3SocketDevicePrivate;
|
|
57 |
|
|
58 |
class Q_COMPAT_EXPORT Q3SocketDevice: public QIODevice
|
|
59 |
{
|
|
60 |
public:
|
|
61 |
enum Type { Stream, Datagram };
|
|
62 |
enum Protocol { IPv4, IPv6, Unknown };
|
|
63 |
|
|
64 |
Q3SocketDevice( Type type = Stream );
|
|
65 |
Q3SocketDevice( Type type, Protocol protocol, int dummy );
|
|
66 |
Q3SocketDevice( int socket, Type type );
|
|
67 |
virtual ~Q3SocketDevice();
|
|
68 |
|
|
69 |
bool isValid() const;
|
|
70 |
Type type() const;
|
|
71 |
Protocol protocol() const;
|
|
72 |
|
|
73 |
int socket() const;
|
|
74 |
virtual void setSocket( int socket, Type type );
|
|
75 |
|
|
76 |
bool open( OpenMode mode );
|
|
77 |
bool open( int mode ) { return open((OpenMode)mode); }
|
|
78 |
void close();
|
|
79 |
bool flush();
|
|
80 |
|
|
81 |
// Implementation of QIODevice abstract virtual functions
|
|
82 |
Offset size() const;
|
|
83 |
Offset at() const;
|
|
84 |
bool at( Offset );
|
|
85 |
bool atEnd() const;
|
|
86 |
|
|
87 |
bool blocking() const;
|
|
88 |
virtual void setBlocking( bool );
|
|
89 |
|
|
90 |
bool addressReusable() const;
|
|
91 |
virtual void setAddressReusable( bool );
|
|
92 |
|
|
93 |
int receiveBufferSize() const;
|
|
94 |
virtual void setReceiveBufferSize( uint );
|
|
95 |
int sendBufferSize() const;
|
|
96 |
virtual void setSendBufferSize( uint );
|
|
97 |
|
|
98 |
virtual bool connect( const QHostAddress &, Q_UINT16 );
|
|
99 |
|
|
100 |
virtual bool bind( const QHostAddress &, Q_UINT16 );
|
|
101 |
virtual bool listen( int backlog );
|
|
102 |
virtual int accept();
|
|
103 |
|
|
104 |
qint64 bytesAvailable() const;
|
|
105 |
Q_LONG waitForMore( int msecs, bool *timeout=0 ) const;
|
|
106 |
virtual Q_LONG writeBlock( const char *data, Q_ULONG len,
|
|
107 |
const QHostAddress & host, Q_UINT16 port );
|
|
108 |
inline Q_LONG writeBlock(const char *data, Q_ULONG len)
|
|
109 |
{ return qint64(write(data, qint64(len))); }
|
|
110 |
inline qint64 readBlock(char *data, Q_ULONG maxlen)
|
|
111 |
{ return qint64(read(data, qint64(maxlen))); }
|
|
112 |
|
|
113 |
Q_UINT16 port() const;
|
|
114 |
Q_UINT16 peerPort() const;
|
|
115 |
QHostAddress address() const;
|
|
116 |
QHostAddress peerAddress() const;
|
|
117 |
|
|
118 |
enum Error {
|
|
119 |
NoError,
|
|
120 |
AlreadyBound,
|
|
121 |
Inaccessible,
|
|
122 |
NoResources,
|
|
123 |
InternalError,
|
|
124 |
Bug = InternalError, // ### remove in 4.0?
|
|
125 |
Impossible,
|
|
126 |
NoFiles,
|
|
127 |
ConnectionRefused,
|
|
128 |
NetworkFailure,
|
|
129 |
UnknownError
|
|
130 |
};
|
|
131 |
Error error() const;
|
|
132 |
|
|
133 |
inline bool isSequential() const { return true; }
|
|
134 |
|
|
135 |
protected:
|
|
136 |
void setError( Error err );
|
|
137 |
qint64 readData(char *data, qint64 maxlen);
|
|
138 |
qint64 writeData(const char *data, qint64 len);
|
|
139 |
|
|
140 |
private:
|
|
141 |
int fd;
|
|
142 |
Type t;
|
|
143 |
Q_UINT16 p;
|
|
144 |
QHostAddress a;
|
|
145 |
Q_UINT16 pp;
|
|
146 |
QHostAddress pa;
|
|
147 |
Q3SocketDevice::Error e;
|
|
148 |
Q3SocketDevicePrivate * d;
|
|
149 |
|
|
150 |
enum Option { Broadcast, ReceiveBuffer, ReuseAddress, SendBuffer };
|
|
151 |
|
|
152 |
int option( Option ) const;
|
|
153 |
virtual void setOption( Option, int );
|
|
154 |
|
|
155 |
void fetchConnectionParameters();
|
|
156 |
#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
|
|
157 |
void fetchPeerConnectionParameters();
|
|
158 |
#endif
|
|
159 |
|
|
160 |
static void init();
|
|
161 |
int createNewSocket();
|
|
162 |
Protocol getProtocol() const;
|
|
163 |
|
|
164 |
private: // Disabled copy constructor and operator=
|
|
165 |
#if defined(Q_DISABLE_COPY)
|
|
166 |
Q3SocketDevice( const Q3SocketDevice & );
|
|
167 |
Q3SocketDevice &operator=( const Q3SocketDevice & );
|
|
168 |
#endif
|
|
169 |
};
|
|
170 |
|
|
171 |
#endif // QT_NO_NETWORK
|
|
172 |
|
|
173 |
QT_END_NAMESPACE
|
|
174 |
|
|
175 |
QT_END_HEADER
|
|
176 |
|
|
177 |
#endif // Q3SOCKETDEVICE_H
|