home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qsocket.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  4KB  |  151 lines

  1. /****************************************************************************
  2. ** $Id$
  3. **
  4. ** Definition of QSocket class.
  5. **
  6. ** Created : 970521
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the network module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition licenses may use this
  22. ** file in accordance with the Qt Commercial License Agreement provided
  23. ** with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QSOCKET_H
  39. #define QSOCKET_H
  40.  
  41. #ifndef QT_H
  42. #include "qobject.h"
  43. #include "qiodevice.h"
  44. #include "qhostaddress.h" // int->QHostAddress conversion
  45. #endif // QT_H
  46.  
  47. #if !defined( QT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK )
  48. #define QM_EXPORT_NETWORK
  49. #else
  50. #define QM_EXPORT_NETWORK Q_EXPORT
  51. #endif
  52.  
  53. #ifndef QT_NO_NETWORK
  54. class QSocketPrivate;
  55. class QSocketDevice;
  56.  
  57.  
  58. class QM_EXPORT_NETWORK QSocket : public QObject, public QIODevice
  59. {
  60.     Q_OBJECT
  61. public:
  62.     enum Error {
  63.     ErrConnectionRefused,
  64.     ErrHostNotFound,
  65.     ErrSocketRead
  66.     };
  67.  
  68.     QSocket( QObject *parent=0, const char *name=0 );
  69.     virtual ~QSocket();
  70.  
  71.     enum State { Idle, HostLookup, Connecting,
  72.          Connected, Closing,
  73.          Connection=Connected };
  74.     State     state() const;
  75.  
  76.     int         socket() const;
  77.     virtual void setSocket( int );
  78.  
  79.     QSocketDevice *socketDevice();
  80.     virtual void setSocketDevice( QSocketDevice * );
  81.  
  82. #ifndef QT_NO_DNS
  83.     virtual void connectToHost( const QString &host, Q_UINT16 port );
  84. #endif
  85.     QString     peerName() const;
  86.  
  87.     // Implementation of QIODevice abstract virtual functions
  88.     bool     open( int mode );
  89.     void     close();
  90.     void     flush();
  91.     Offset     size() const;
  92.     Offset     at() const;
  93.     bool     at( Offset );
  94.     bool     atEnd() const;
  95.  
  96.     Q_ULONG     bytesAvailable() const;
  97.     Q_ULONG     waitForMore( int msecs ) const;
  98.     Q_ULONG     bytesToWrite() const;
  99.  
  100.     Q_LONG     readBlock( char *data, Q_ULONG maxlen );
  101.     Q_LONG     writeBlock( const char *data, Q_ULONG len );
  102.     Q_LONG     readLine( char *data, Q_ULONG maxlen );
  103.  
  104.     int         getch();
  105.     int         putch( int );
  106.     int         ungetch(int);
  107.  
  108.     bool     canReadLine() const;
  109.     virtual     QString readLine();
  110.  
  111.     Q_UINT16     port() const;
  112.     Q_UINT16     peerPort() const;
  113.     QHostAddress address() const;
  114.     QHostAddress peerAddress() const;
  115.  
  116. signals:
  117.     void     hostFound();
  118.     void     connected();
  119.     void     connectionClosed();
  120.     void     delayedCloseFinished();
  121.     void     readyRead();
  122.     void     bytesWritten( int nbytes );
  123.     void     error( int );
  124.  
  125. protected slots:
  126.     virtual void sn_read( bool force=FALSE );
  127.     virtual void sn_write();
  128.  
  129. private slots:
  130.     void    tryConnecting();
  131.     void    emitErrorConnectionRefused();
  132.  
  133. private:
  134.     QSocketPrivate *d;
  135.  
  136.     bool     consumeReadBuf( Q_ULONG nbytes, char * );
  137.     bool     consumeWriteBuf( Q_ULONG nbytes );
  138.     bool     scanNewline( QByteArray * = 0 );
  139.     void     tryConnection();
  140.     void         setSocketIntern( int socket );
  141.  
  142. private:    // Disabled copy constructor and operator=
  143. #if defined(Q_DISABLE_COPY)
  144.     QSocket( const QSocket & );
  145.     QSocket &operator=( const QSocket & );
  146. #endif
  147. };
  148.  
  149. #endif //QT_NO_NETWORK
  150. #endif // QSOCKET_H
  151.