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

« back to all changes in this revision

Viewing changes to src/network/qsocketlayer_p.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 network module 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 QSOCKETLAYER_P_H
 
30
#define QSOCKETLAYER_P_H
 
31
 
 
32
#include <qhostaddress.h>
 
33
#include <qabstractsocket.h>
 
34
 
 
35
class QSocketLayerPrivate;
 
36
 
 
37
class QSocketLayer
 
38
{
 
39
public:
 
40
    enum SocketOption {
 
41
        NonBlockingSocketOption,
 
42
        BroadcastSocketOption,
 
43
        ReceiveBufferSocketOption,
 
44
        SendBufferSocketOption,
 
45
        AddressReusable
 
46
    };
 
47
 
 
48
    QSocketLayer();
 
49
    ~QSocketLayer();
 
50
 
 
51
    bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol);
 
52
    bool initialize(int socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState);
 
53
    QAbstractSocket::SocketType socketType() const;
 
54
    QAbstractSocket::NetworkLayerProtocol protocol() const;
 
55
    int socketDescriptor() const;
 
56
 
 
57
    bool isValid() const;
 
58
 
 
59
    bool connectToHost(const QHostAddress &address, quint16 port);
 
60
    bool bind(const QHostAddress &address, quint16 port);
 
61
    bool listen();
 
62
    int accept();
 
63
    void close();
 
64
 
 
65
    qint64 bytesAvailable() const;
 
66
 
 
67
    qint64 read(char *data, qint64 maxlen);
 
68
    qint64 write(const char *data, qint64 len);
 
69
 
 
70
    qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr = 0,
 
71
                            quint16 *port = 0);
 
72
    qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr,
 
73
                             quint16 port);
 
74
    bool hasPendingDatagrams() const;
 
75
    qint64 pendingDatagramSize() const;
 
76
 
 
77
    QAbstractSocket::SocketState state() const;
 
78
 
 
79
    QHostAddress localAddress() const;
 
80
    quint16 localPort() const;
 
81
    QHostAddress peerAddress() const;
 
82
    quint16 peerPort() const;
 
83
 
 
84
    qint64 receiveBufferSize() const;
 
85
    void setReceiveBufferSize(qint64 bufferSize);
 
86
 
 
87
    qint64 sendBufferSize() const;
 
88
    void setSendBufferSize(qint64 bufferSize);
 
89
 
 
90
    // native functions
 
91
    int option(SocketOption option) const;
 
92
    bool setOption(SocketOption option, int value);
 
93
    
 
94
    bool waitForRead(int msecs = 30000, bool *timedOut = 0) const;
 
95
    bool waitForWrite(int msecs = 30000, bool *timedOut = 0) const;
 
96
    bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
 
97
                            bool checkRead, bool checkWrite,
 
98
                            int msecs = 30000, bool *timedOut = 0) const;
 
99
 
 
100
    QAbstractSocket::SocketError error() const;
 
101
    QString errorString() const;
 
102
 
 
103
private:
 
104
    Q_DISABLE_COPY(QSocketLayer)
 
105
 
 
106
    QSocketLayerPrivate *d;
 
107
};
 
108
 
 
109
#ifdef Q_OS_WIN
 
110
class QWindowsSockInit
 
111
{
 
112
public:
 
113
    QWindowsSockInit();
 
114
    ~QWindowsSockInit();
 
115
    int version;
 
116
};
 
117
#endif
 
118
 
 
119
class QSocketLayerPrivate
 
120
{
 
121
public:
 
122
    QSocketLayerPrivate();
 
123
    ~QSocketLayerPrivate();
 
124
 
 
125
    int socketDescriptor;
 
126
 
 
127
    QAbstractSocket::SocketType socketType;
 
128
    QAbstractSocket::NetworkLayerProtocol socketProtocol;
 
129
    QAbstractSocket::SocketState socketState;
 
130
    mutable QAbstractSocket::SocketError socketError;
 
131
    mutable QString socketErrorString;
 
132
 
 
133
    QHostAddress peerAddress;
 
134
    quint16 peerPort;
 
135
 
 
136
    QHostAddress localAddress;
 
137
    quint16 localPort;
 
138
 
 
139
 
 
140
#ifdef Q_OS_WIN
 
141
    QWindowsSockInit winSock;
 
142
#endif
 
143
 
 
144
    enum ErrorString {
 
145
        NonBlockingInitFailedErrorString, 
 
146
        BroadcastingInitFailedErrorString,
 
147
        NoIpV6ErrorString, 
 
148
        RemoteHostClosedErrorString,
 
149
        TimeOutErrorString,
 
150
        ResourceErrorString,
 
151
        OperationUnsupportedErrorString,
 
152
        ProtocolUnsupportedErrorString, 
 
153
        InvalidSocketErrorString, 
 
154
        UnreachableErrorString, 
 
155
        AccessErrorString, 
 
156
        ConnectionTimeOutErrorString, 
 
157
        ConnectionRefusedErrorString, 
 
158
        AddressInuseErrorString, 
 
159
        AddressNotAvailableErrorString, 
 
160
        AddressProtectedErrorString, 
 
161
        DatagramTooLargeErrorString, 
 
162
        SendDatagramErrorString,
 
163
        ReceiveDatagramErrorString,
 
164
        WriteErrorString, 
 
165
        ReadErrorString,
 
166
        PortInuseErrorString
 
167
    };
 
168
 
 
169
    void setError(QAbstractSocket::SocketError error, ErrorString errorString) const;
 
170
 
 
171
    // native functions
 
172
    int option(QSocketLayer::SocketOption option) const;
 
173
    bool setOption(QSocketLayer::SocketOption option, int value);
 
174
 
 
175
    bool createNewSocket(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol);
 
176
 
 
177
    bool nativeConnect(const QHostAddress &address, quint16 port);
 
178
    bool nativeBind(const QHostAddress &address, quint16 port);
 
179
    bool nativeListen(int backlog);
 
180
    int nativeAccept();
 
181
    qint64 nativeBytesAvailable() const;
 
182
 
 
183
    bool nativeHasPendingDatagrams() const;
 
184
    qint64 nativePendingDatagramSize() const;
 
185
    qint64 nativeReceiveDatagram(char *data, qint64 maxLength,
 
186
                                     QHostAddress *address, quint16 *port);
 
187
    qint64 nativeSendDatagram(const char *data, qint64 length,
 
188
                                  const QHostAddress &host, quint16 port);
 
189
    qint64 nativeRead(char *data, qint64 maxLength);
 
190
    qint64 nativeWrite(const char *data, qint64 length);
 
191
    int nativeSelect(int timeout, bool selectForRead) const;
 
192
    int nativeSelect(int timeout, bool checkRead, bool checkWrite,
 
193
                     bool *selectForRead, bool *selectForWrite) const;
 
194
 
 
195
    void nativeClose();
 
196
 
 
197
    bool fetchConnectionParameters();
 
198
 
 
199
    QSocketLayer *q;
 
200
};
 
201
 
 
202
#endif // QSOCKETLAYER_P_H