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

« back to all changes in this revision

Viewing changes to src/qt3support/network/q3socket.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 Q3SOCKET_H
 
30
#define Q3SOCKET_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
class Q3SocketPrivate;
 
38
class Q3SocketDevice;
 
39
 
 
40
class Q_COMPAT_EXPORT Q3Socket : public QIODevice
 
41
{
 
42
    Q_OBJECT
 
43
public:
 
44
    enum Error {
 
45
        ErrConnectionRefused,
 
46
        ErrHostNotFound,
 
47
        ErrSocketRead
 
48
    };
 
49
 
 
50
    Q3Socket( QObject *parent=0, const char *name=0 );
 
51
    virtual ~Q3Socket();
 
52
 
 
53
    enum State { Idle, HostLookup, Connecting,
 
54
                 Connected, Closing,
 
55
                 Connection=Connected };
 
56
    State        state() const;
 
57
 
 
58
    int          socket() const;
 
59
    virtual void setSocket( int );
 
60
 
 
61
    Q3SocketDevice *socketDevice();
 
62
    virtual void setSocketDevice( Q3SocketDevice * );
 
63
 
 
64
#ifndef QT_NO_DNS
 
65
    virtual void connectToHost( const QString &host, Q_UINT16 port );
 
66
#endif
 
67
    QString      peerName() const;
 
68
 
 
69
    // Implementation of QIODevice abstract virtual functions
 
70
    bool         open( int mode );
 
71
    void         close();
 
72
    bool         flush();
 
73
    Offset       size() const;
 
74
    Offset       at() const;
 
75
    bool         at( Offset );
 
76
    bool         atEnd() const;
 
77
 
 
78
    qint64       bytesAvailable() const;
 
79
    Q_ULONG      waitForMore( int msecs, bool *timeout  ) const;
 
80
    Q_ULONG      waitForMore( int msecs ) const; // ### Qt 4.0: merge the two overloads
 
81
    qint64       bytesToWrite() const;
 
82
    void         clearPendingData();
 
83
 
 
84
    int          getch();
 
85
    int          putch( int );
 
86
    int          ungetch(int);
 
87
 
 
88
    bool         canReadLine() const;
 
89
 
 
90
    Q_UINT16     port() const;
 
91
    Q_UINT16     peerPort() const;
 
92
    QHostAddress address() const;
 
93
    QHostAddress peerAddress() const;
 
94
 
 
95
    void         setReadBufferSize( Q_ULONG );
 
96
    Q_ULONG      readBufferSize() const;
 
97
 
 
98
    inline bool  isSequential() const { return !isOpen(); }
 
99
 
 
100
signals:
 
101
    void         hostFound();
 
102
    void         connected();
 
103
    void         connectionClosed();
 
104
    void         delayedCloseFinished();
 
105
    void         readyRead();
 
106
    void         bytesWritten( int nbytes );
 
107
    void         error( int );
 
108
 
 
109
protected slots:
 
110
    virtual void sn_read( bool force=false );
 
111
    virtual void sn_write();
 
112
 
 
113
protected:
 
114
    qint64 readData(char *data, qint64 maxlen);
 
115
    qint64 writeData(const char *data, qint64 len);
 
116
 
 
117
private slots:
 
118
    void        tryConnecting();
 
119
    void        emitErrorConnectionRefused();
 
120
 
 
121
private:
 
122
    Q3SocketPrivate *d;
 
123
 
 
124
    bool         consumeWriteBuf( Q_ULONG nbytes );
 
125
    void         tryConnection();
 
126
    void         setSocketIntern( int socket );
 
127
 
 
128
private:        // Disabled copy constructor and operator=
 
129
#if defined(Q_DISABLE_COPY)
 
130
    Q3Socket( const Q3Socket & );
 
131
    Q3Socket &operator=( const Q3Socket & );
 
132
#endif
 
133
};
 
134
 
 
135
#endif // Q3SOCKET_H