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

  1. /****************************************************************************
  2. ** $Id:  qt/qsocketdevice.h   3.0.0   edited Sep 3 16:56 $
  3. **
  4. ** Definition of QSocketDevice 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 QSOCKETDEVICE_H
  39. #define QSOCKETDEVICE_H
  40.  
  41. #ifndef QT_H
  42. #include "qiodevice.h"
  43. #include "qhostaddress.h" // int->QHostAddress conversion
  44. #endif // QT_H
  45.  
  46. #if !defined( QT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK )
  47. #define QM_EXPORT_NETWORK
  48. #else
  49. #define QM_EXPORT_NETWORK Q_EXPORT
  50. #endif
  51.  
  52. #ifndef QT_NO_NETWORK
  53. class QSocketDevicePrivate;
  54.  
  55.  
  56. class  QM_EXPORT_NETWORK QSocketDevice: public QIODevice
  57. {
  58. public:
  59.     enum Type { Stream, Datagram };
  60.  
  61.     QSocketDevice( Type type = Stream );
  62.     QSocketDevice( int socket, Type type );
  63.     virtual ~QSocketDevice();
  64.  
  65.     bool     isValid() const;
  66.     Type     type() const;
  67.  
  68.     int         socket() const;
  69.     virtual void setSocket( int socket, Type type );
  70.  
  71.     bool     open( int mode );
  72.     void     close();
  73.     void     flush();
  74.  
  75.     // Implementation of QIODevice abstract virtual functions
  76.     Offset     size() const;
  77.     Offset     at() const;
  78.     bool     at( Offset );
  79.     bool     atEnd() const;
  80.  
  81.     bool     blocking() const;
  82.     virtual void setBlocking( bool );
  83.  
  84.     bool     addressReusable() const;
  85.     virtual void setAddressReusable( bool );
  86.  
  87.     int         receiveBufferSize() const;
  88.     virtual void setReceiveBufferSize( uint );
  89.     int         sendBufferSize() const;
  90.     virtual void setSendBufferSize( uint );
  91.  
  92.     virtual bool connect( const QHostAddress &, Q_UINT16 );
  93.  
  94.     virtual bool bind( const QHostAddress &, Q_UINT16 );
  95.     virtual bool listen( int backlog );
  96.     virtual int     accept();
  97.  
  98.     Q_LONG     bytesAvailable() const;
  99.     Q_LONG     waitForMore( int msecs, bool *timeout=0 ) const;
  100.     Q_LONG     readBlock( char *data, Q_ULONG maxlen );
  101.     Q_LONG     writeBlock( const char *data, Q_ULONG len );
  102.     virtual Q_LONG  writeBlock( const char *data, Q_ULONG len,
  103.                 const QHostAddress & host, Q_UINT16 port );
  104.  
  105.     int         getch();
  106.     int         putch( int );
  107.     int         ungetch(int);
  108.  
  109.     Q_UINT16     port() const;
  110.     Q_UINT16     peerPort() const;
  111.     QHostAddress address() const;
  112.     QHostAddress peerAddress() const;
  113.  
  114.     enum Error { NoError, AlreadyBound, Inaccessible, NoResources,
  115.          Bug, Impossible, NoFiles, ConnectionRefused,
  116.          NetworkFailure, UnknownError };
  117.     Error      error() const;
  118.  
  119. protected:
  120.     void setError( Error err );
  121.  
  122. private:
  123.     int fd;
  124.     Type t;
  125.     Q_UINT16 p;
  126.     QHostAddress a;
  127.     Q_UINT16 pp;
  128.     QHostAddress pa;
  129.     QSocketDevice::Error e;
  130.     QSocketDevicePrivate * d;
  131.  
  132.     enum Option { Broadcast, ReceiveBuffer, ReuseAddress, SendBuffer };
  133.  
  134.     int         option( Option ) const;
  135.     virtual void setOption( Option, int );
  136.  
  137.     void     fetchConnectionParameters();
  138. #if defined(Q_OS_WIN32)
  139.     void     fetchPeerConnectionParameters();
  140. #endif
  141.  
  142.     static void  init();
  143.     int         createNewSocket();
  144.  
  145. private:    // Disabled copy constructor and operator=
  146. #if defined(Q_DISABLE_COPY)
  147.     QSocketDevice( const QSocketDevice & );
  148.     QSocketDevice &operator=( const QSocketDevice & );
  149. #endif
  150. };
  151.  
  152. #endif // QT_NO_NETWORK
  153. #endif // QSOCKETDEVICE_H
  154.