src/qt3support/network/q3socket.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt3Support module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    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