source: trunk/include/qsocketdevice.h@ 25

Last change on this file since 25 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1/****************************************************************************
2** $Id: qsocketdevice.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of QSocketDevice class.
5**
6** Created : 970521
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the network module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition licenses may use this
22** file in accordance with the Qt Commercial License Agreement provided
23** with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QSOCKETDEVICE_H
39#define QSOCKETDEVICE_H
40
41#ifndef QT_H
42#include "qiodevice.h"
43#include "qhostaddress.h" // int->QHostAddress conversion
44#endif // QT_H
45
46#if !defined( QT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK )
47#define QM_EXPORT_NETWORK
48#else
49#define QM_EXPORT_NETWORK Q_EXPORT
50#endif
51
52#ifndef QT_NO_NETWORK
53class QSocketDevicePrivate;
54
55
56class QM_EXPORT_NETWORK QSocketDevice: public QIODevice
57{
58public:
59 enum Type { Stream, Datagram };
60 enum Protocol { IPv4, IPv6, Unknown };
61
62 QSocketDevice( Type type = Stream );
63 QSocketDevice( Type type, Protocol protocol, int dummy );
64 QSocketDevice( int socket, Type type );
65 virtual ~QSocketDevice();
66
67 bool isValid() const;
68 Type type() const;
69 Protocol protocol() const;
70
71 int socket() const;
72 virtual void setSocket( int socket, Type type );
73
74 bool open( int mode );
75 void close();
76 void flush();
77
78 // Implementation of QIODevice abstract virtual functions
79 Offset size() const;
80 Offset at() const;
81 bool at( Offset );
82 bool atEnd() const;
83
84 bool blocking() const;
85 virtual void setBlocking( bool );
86
87 bool addressReusable() const;
88 virtual void setAddressReusable( bool );
89
90 int receiveBufferSize() const;
91 virtual void setReceiveBufferSize( uint );
92 int sendBufferSize() const;
93 virtual void setSendBufferSize( uint );
94
95 virtual bool connect( const QHostAddress &, Q_UINT16 );
96
97 virtual bool bind( const QHostAddress &, Q_UINT16 );
98 virtual bool listen( int backlog );
99 virtual int accept();
100
101 Q_LONG bytesAvailable() const;
102 Q_LONG waitForMore( int msecs, bool *timeout=0 ) const;
103 Q_LONG readBlock( char *data, Q_ULONG maxlen );
104 Q_LONG writeBlock( const char *data, Q_ULONG len );
105 virtual Q_LONG writeBlock( const char *data, Q_ULONG len,
106 const QHostAddress & host, Q_UINT16 port );
107
108 int getch();
109 int putch( int );
110 int ungetch(int);
111
112 Q_UINT16 port() const;
113 Q_UINT16 peerPort() const;
114 QHostAddress address() const;
115 QHostAddress peerAddress() const;
116
117 enum Error {
118 NoError,
119 AlreadyBound,
120 Inaccessible,
121 NoResources,
122 InternalError,
123 Bug = InternalError, // ### remove in 4.0?
124 Impossible,
125 NoFiles,
126 ConnectionRefused,
127 NetworkFailure,
128 UnknownError
129 };
130 Error error() const;
131
132protected:
133 void setError( Error err );
134
135private:
136 int fd;
137 Type t;
138 Q_UINT16 p;
139 QHostAddress a;
140 Q_UINT16 pp;
141 QHostAddress pa;
142 QSocketDevice::Error e;
143 QSocketDevicePrivate * d;
144
145 enum Option { Broadcast, ReceiveBuffer, ReuseAddress, SendBuffer };
146
147 int option( Option ) const;
148 virtual void setOption( Option, int );
149
150 void fetchConnectionParameters();
151#if defined(Q_OS_WIN32)
152 void fetchPeerConnectionParameters();
153#endif
154
155 static void init();
156 int createNewSocket();
157 Protocol getProtocol() const;
158
159private: // Disabled copy constructor and operator=
160#if defined(Q_DISABLE_COPY)
161 QSocketDevice( const QSocketDevice & );
162 QSocketDevice &operator=( const QSocketDevice & );
163#endif
164};
165
166#endif // QT_NO_NETWORK
167#endif // QSOCKETDEVICE_H
Note: See TracBrowser for help on using the repository browser.