1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the Qt3Support module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** 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 are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef Q3SOCKET_H
|
---|
43 | #define Q3SOCKET_H
|
---|
44 |
|
---|
45 | #include <QtCore/qiodevice.h>
|
---|
46 | #include <QtNetwork/qhostaddress.h> // int->QHostAddress conversion
|
---|
47 |
|
---|
48 | QT_BEGIN_HEADER
|
---|
49 |
|
---|
50 | QT_BEGIN_NAMESPACE
|
---|
51 |
|
---|
52 | QT_MODULE(Qt3Support)
|
---|
53 |
|
---|
54 | class Q3SocketPrivate;
|
---|
55 | class Q3SocketDevice;
|
---|
56 |
|
---|
57 | class Q_COMPAT_EXPORT Q3Socket : public QIODevice
|
---|
58 | {
|
---|
59 | Q_OBJECT
|
---|
60 | public:
|
---|
61 | enum Error {
|
---|
62 | ErrConnectionRefused,
|
---|
63 | ErrHostNotFound,
|
---|
64 | ErrSocketRead
|
---|
65 | };
|
---|
66 |
|
---|
67 | Q3Socket( QObject *parent=0, const char *name=0 );
|
---|
68 | virtual ~Q3Socket();
|
---|
69 |
|
---|
70 | enum State { Idle, HostLookup, Connecting,
|
---|
71 | Connected, Closing,
|
---|
72 | Connection=Connected };
|
---|
73 | State state() const;
|
---|
74 |
|
---|
75 | int socket() const;
|
---|
76 | virtual void setSocket( int );
|
---|
77 |
|
---|
78 | Q3SocketDevice *socketDevice();
|
---|
79 | virtual void setSocketDevice( Q3SocketDevice * );
|
---|
80 |
|
---|
81 | #ifndef QT_NO_DNS
|
---|
82 | virtual void connectToHost( const QString &host, Q_UINT16 port );
|
---|
83 | #endif
|
---|
84 | QString peerName() const;
|
---|
85 |
|
---|
86 | // Implementation of QIODevice abstract virtual functions
|
---|
87 | bool open( OpenMode mode );
|
---|
88 | bool open(int mode) { return open((OpenMode)mode); }
|
---|
89 | void close();
|
---|
90 | bool flush();
|
---|
91 | Offset size() const;
|
---|
92 | Offset at() const;
|
---|
93 | bool at( Offset );
|
---|
94 | bool atEnd() const;
|
---|
95 |
|
---|
96 | qint64 bytesAvailable() const;
|
---|
97 | Q_ULONG waitForMore( int msecs, bool *timeout ) const;
|
---|
98 | Q_ULONG waitForMore( int msecs ) const; // ### Qt 4.0: merge the two overloads
|
---|
99 | qint64 bytesToWrite() const;
|
---|
100 | void clearPendingData();
|
---|
101 |
|
---|
102 | int getch();
|
---|
103 | int putch( int );
|
---|
104 | int ungetch(int);
|
---|
105 |
|
---|
106 | bool canReadLine() const;
|
---|
107 |
|
---|
108 | Q_UINT16 port() const;
|
---|
109 | Q_UINT16 peerPort() const;
|
---|
110 | QHostAddress address() const;
|
---|
111 | QHostAddress peerAddress() const;
|
---|
112 |
|
---|
113 | void setReadBufferSize( Q_ULONG );
|
---|
114 | Q_ULONG readBufferSize() const;
|
---|
115 |
|
---|
116 | inline bool isSequential() const { return true; }
|
---|
117 |
|
---|
118 | Q_SIGNALS:
|
---|
119 | void hostFound();
|
---|
120 | void connected();
|
---|
121 | void connectionClosed();
|
---|
122 | void delayedCloseFinished();
|
---|
123 | void readyRead();
|
---|
124 | void bytesWritten( int nbytes );
|
---|
125 | void error( int );
|
---|
126 |
|
---|
127 | protected Q_SLOTS:
|
---|
128 | virtual void sn_read( bool force=false );
|
---|
129 | virtual void sn_write();
|
---|
130 |
|
---|
131 | protected:
|
---|
132 | qint64 readData(char *data, qint64 maxlen);
|
---|
133 | qint64 writeData(const char *data, qint64 len);
|
---|
134 |
|
---|
135 | private Q_SLOTS:
|
---|
136 | void tryConnecting();
|
---|
137 | void emitErrorConnectionRefused();
|
---|
138 |
|
---|
139 | private:
|
---|
140 | Q3SocketPrivate *d;
|
---|
141 |
|
---|
142 | bool consumeWriteBuf( Q_ULONG nbytes );
|
---|
143 | void tryConnection();
|
---|
144 | void setSocketIntern( int socket );
|
---|
145 |
|
---|
146 | private: // Disabled copy constructor and operator=
|
---|
147 | #if defined(Q_DISABLE_COPY)
|
---|
148 | Q3Socket( const Q3Socket & );
|
---|
149 | Q3Socket &operator=( const Q3Socket & );
|
---|
150 | #endif
|
---|
151 | };
|
---|
152 |
|
---|
153 | QT_END_NAMESPACE
|
---|
154 |
|
---|
155 | QT_END_HEADER
|
---|
156 |
|
---|
157 | #endif // Q3SOCKET_H
|
---|