1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#ifndef Q3SOCKETDEVICE_H
30
#define Q3SOCKETDEVICE_H
33
#include "QtCore/qiodevice.h"
34
#include "QtNetwork/qhostaddress.h" // int->QHostAddress conversion
38
class Q3SocketDevicePrivate;
40
class Q_COMPAT_EXPORT Q3SocketDevice: public QIODevice
43
enum Type { Stream, Datagram };
44
enum Protocol { IPv4, IPv6, Unknown };
46
Q3SocketDevice( Type type = Stream );
47
Q3SocketDevice( Type type, Protocol protocol, int dummy );
48
Q3SocketDevice( int socket, Type type );
49
virtual ~Q3SocketDevice();
53
Protocol protocol() const;
56
virtual void setSocket( int socket, Type type );
58
bool open( int mode );
62
// Implementation of QIODevice abstract virtual functions
68
bool blocking() const;
69
virtual void setBlocking( bool );
71
bool addressReusable() const;
72
virtual void setAddressReusable( bool );
74
int receiveBufferSize() const;
75
virtual void setReceiveBufferSize( uint );
76
int sendBufferSize() const;
77
virtual void setSendBufferSize( uint );
79
virtual bool connect( const QHostAddress &, Q_UINT16 );
81
virtual bool bind( const QHostAddress &, Q_UINT16 );
82
virtual bool listen( int backlog );
85
qint64 bytesAvailable() const;
86
Q_LONG waitForMore( int msecs, bool *timeout=0 ) const;
87
virtual Q_LONG writeBlock( const char *data, Q_ULONG len,
88
const QHostAddress & host, Q_UINT16 port );
89
inline Q_LONG writeBlock(const char *data, Q_ULONG len)
90
{ return qint64(write(data, qint64(len))); }
91
inline qint64 readBlock(char *data, Q_ULONG maxlen)
92
{ return qint64(read(data, qint64(maxlen))); }
94
Q_UINT16 port() const;
95
Q_UINT16 peerPort() const;
96
QHostAddress address() const;
97
QHostAddress peerAddress() const;
105
Bug = InternalError, // ### remove in 4.0?
114
inline bool isSequential() const { return true; }
117
void setError( Error err );
118
qint64 readData(char *data, qint64 maxlen);
119
qint64 writeData(const char *data, qint64 len);
128
Q3SocketDevice::Error e;
129
Q3SocketDevicePrivate * d;
131
enum Option { Broadcast, ReceiveBuffer, ReuseAddress, SendBuffer };
133
int option( Option ) const;
134
virtual void setOption( Option, int );
136
void fetchConnectionParameters();
137
#if defined(Q_OS_WIN32)
138
void fetchPeerConnectionParameters();
142
int createNewSocket();
143
Protocol getProtocol() const;
145
private: // Disabled copy constructor and operator=
146
#if defined(Q_DISABLE_COPY)
147
Q3SocketDevice( const Q3SocketDevice & );
148
Q3SocketDevice &operator=( const Q3SocketDevice & );
152
#endif // QT_NO_NETWORK
154
#endif // Q3SOCKETDEVICE_H