~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/qt3support/network/q3socketdevice.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#ifndef Q3SOCKETDEVICE_H
 
30
#define Q3SOCKETDEVICE_H
 
31
 
 
32
#ifndef QT_H
 
33
#include "QtCore/qiodevice.h"
 
34
#include "QtNetwork/qhostaddress.h" // int->QHostAddress conversion
 
35
#endif // QT_H
 
36
 
 
37
#ifndef QT_NO_NETWORK
 
38
class Q3SocketDevicePrivate;
 
39
 
 
40
class Q_COMPAT_EXPORT Q3SocketDevice: public QIODevice
 
41
{
 
42
public:
 
43
    enum Type { Stream, Datagram };
 
44
    enum Protocol { IPv4, IPv6, Unknown };
 
45
 
 
46
    Q3SocketDevice( Type type = Stream );
 
47
    Q3SocketDevice( Type type, Protocol protocol, int dummy );
 
48
    Q3SocketDevice( int socket, Type type );
 
49
    virtual ~Q3SocketDevice();
 
50
 
 
51
    bool         isValid() const;
 
52
    Type         type() const;
 
53
    Protocol     protocol() const;
 
54
 
 
55
    int          socket() const;
 
56
    virtual void setSocket( int socket, Type type );
 
57
 
 
58
    bool         open( int mode );
 
59
    void         close();
 
60
    bool         flush();
 
61
 
 
62
    // Implementation of QIODevice abstract virtual functions
 
63
    Offset       size() const;
 
64
    Offset       at() const;
 
65
    bool         at( Offset );
 
66
    bool         atEnd() const;
 
67
 
 
68
    bool         blocking() const;
 
69
    virtual void setBlocking( bool );
 
70
 
 
71
    bool         addressReusable() const;
 
72
    virtual void setAddressReusable( bool );
 
73
 
 
74
    int          receiveBufferSize() const;
 
75
    virtual void setReceiveBufferSize( uint );
 
76
    int          sendBufferSize() const;
 
77
    virtual void setSendBufferSize( uint );
 
78
 
 
79
    virtual bool connect( const QHostAddress &, Q_UINT16 );
 
80
 
 
81
    virtual bool bind( const QHostAddress &, Q_UINT16 );
 
82
    virtual bool listen( int backlog );
 
83
    virtual int  accept();
 
84
 
 
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))); }
 
93
 
 
94
    Q_UINT16     port() const;
 
95
    Q_UINT16     peerPort() const;
 
96
    QHostAddress address() const;
 
97
    QHostAddress peerAddress() const;
 
98
 
 
99
    enum Error {
 
100
        NoError,
 
101
        AlreadyBound,
 
102
        Inaccessible,
 
103
        NoResources,
 
104
        InternalError,
 
105
        Bug = InternalError, // ### remove in 4.0?
 
106
        Impossible,
 
107
        NoFiles,
 
108
        ConnectionRefused,
 
109
        NetworkFailure,
 
110
        UnknownError
 
111
    };
 
112
    Error        error() const;
 
113
 
 
114
    inline bool isSequential() const { return true; }
 
115
 
 
116
protected:
 
117
    void setError( Error err );
 
118
    qint64 readData(char *data, qint64 maxlen);
 
119
    qint64 writeData(const char *data, qint64 len);
 
120
 
 
121
private:
 
122
    int fd;
 
123
    Type t;
 
124
    Q_UINT16 p;
 
125
    QHostAddress a;
 
126
    Q_UINT16 pp;
 
127
    QHostAddress pa;
 
128
    Q3SocketDevice::Error e;
 
129
    Q3SocketDevicePrivate * d;
 
130
 
 
131
    enum Option { Broadcast, ReceiveBuffer, ReuseAddress, SendBuffer };
 
132
 
 
133
    int          option( Option ) const;
 
134
    virtual void setOption( Option, int );
 
135
 
 
136
    void         fetchConnectionParameters();
 
137
#if defined(Q_OS_WIN32)
 
138
    void         fetchPeerConnectionParameters();
 
139
#endif
 
140
 
 
141
    static void  init();
 
142
    int          createNewSocket();
 
143
    Protocol     getProtocol() const;
 
144
 
 
145
private:        // Disabled copy constructor and operator=
 
146
#if defined(Q_DISABLE_COPY)
 
147
    Q3SocketDevice( const Q3SocketDevice & );
 
148
    Q3SocketDevice &operator=( const Q3SocketDevice & );
 
149
#endif
 
150
};
 
151
 
 
152
#endif // QT_NO_NETWORK
 
153
 
 
154
#endif // Q3SOCKETDEVICE_H