source: trunk/src/qt3support/network/q3socketdevice.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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 Qt3Support 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 Q3SOCKETDEVICE_H
43#define Q3SOCKETDEVICE_H
44
45#include <QtCore/qiodevice.h>
46#include <QtNetwork/qhostaddress.h> // int->QHostAddress conversion
47
48QT_BEGIN_HEADER
49
50QT_BEGIN_NAMESPACE
51
52QT_MODULE(Qt3Support)
53
54#ifndef QT_NO_NETWORK
55
56class Q3SocketDevicePrivate;
57
58class Q_COMPAT_EXPORT Q3SocketDevice: public QIODevice
59{
60public:
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
135protected:
136 void setError( Error err );
137 qint64 readData(char *data, qint64 maxlen);
138 qint64 writeData(const char *data, qint64 len);
139
140private:
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
164private: // 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
173QT_END_NAMESPACE
174
175QT_END_HEADER
176
177#endif // Q3SOCKETDEVICE_H
Note: See TracBrowser for help on using the repository browser.