Eneboo - Documentación para desarrolladores
src/qt/include/qsocketdevice.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qsocketdevice.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QSocketDevice class.
00005 **
00006 ** Created : 970521
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the network module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00022 ** file in accordance with the Qt Commercial License Agreement provided
00023 ** with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QSOCKETDEVICE_H
00039 #define QSOCKETDEVICE_H
00040 
00041 #ifndef QT_H
00042 #include "qiodevice.h"
00043 #include "qhostaddress.h" // int->QHostAddress conversion
00044 #endif // QT_H
00045 
00046 #if !defined( QT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK )
00047 #define QM_EXPORT_NETWORK
00048 #else
00049 #define QM_EXPORT_NETWORK Q_EXPORT
00050 #endif
00051 
00052 #ifndef QT_NO_NETWORK
00053 class QSocketDevicePrivate;
00054 
00055 
00056 class  QM_EXPORT_NETWORK QSocketDevice: public QIODevice
00057 {
00058 public:
00059     enum Type { Stream, Datagram };
00060     enum Protocol { IPv4, IPv6, Unknown };
00061 
00062     QSocketDevice( Type type = Stream );
00063     QSocketDevice( Type type, Protocol protocol, int dummy );
00064     QSocketDevice( int socket, Type type );
00065     virtual ~QSocketDevice();
00066 
00067     bool         isValid() const;
00068     Type         type() const;
00069     Protocol     protocol() const;
00070 
00071     int          socket() const;
00072     virtual void setSocket( int socket, Type type );
00073 
00074     bool         open( int mode );
00075     void         close();
00076     void         flush();
00077 
00078     // Implementation of QIODevice abstract virtual functions
00079     Offset       size() const;
00080     Offset       at() const;
00081     bool         at( Offset );
00082     bool         atEnd() const;
00083 
00084     bool         blocking() const;
00085     virtual void setBlocking( bool );
00086 
00087     bool         addressReusable() const;
00088     virtual void setAddressReusable( bool );
00089 
00090     int          receiveBufferSize() const;
00091     virtual void setReceiveBufferSize( uint );
00092     int          sendBufferSize() const;
00093     virtual void setSendBufferSize( uint );
00094 
00095     virtual bool connect( const QHostAddress &, Q_UINT16 );
00096 
00097     virtual bool bind( const QHostAddress &, Q_UINT16 );
00098     virtual bool listen( int backlog );
00099     virtual int  accept();
00100 
00101     Q_LONG       bytesAvailable() const;
00102     Q_LONG       waitForMore( int msecs, bool *timeout=0 ) const;
00103     Q_LONG       readBlock( char *data, Q_ULONG maxlen );
00104     Q_LONG       writeBlock( const char *data, Q_ULONG len );
00105     virtual Q_LONG  writeBlock( const char *data, Q_ULONG len,
00106                             const QHostAddress & host, Q_UINT16 port );
00107 
00108     int          getch();
00109     int          putch( int );
00110     int          ungetch(int);
00111 
00112     Q_UINT16     port() const;
00113     Q_UINT16     peerPort() const;
00114     QHostAddress address() const;
00115     QHostAddress peerAddress() const;
00116 
00117     enum Error {
00118         NoError,
00119         AlreadyBound,
00120         Inaccessible,
00121         NoResources,
00122         InternalError,
00123         Bug = InternalError, // ### remove in 4.0?
00124         Impossible,
00125         NoFiles,
00126         ConnectionRefused,
00127         NetworkFailure,
00128         UnknownError
00129     };
00130     Error        error() const;
00131 
00132 protected:
00133     void setError( Error err );
00134 
00135 private:
00136     int fd;
00137     Type t;
00138     Q_UINT16 p;
00139     QHostAddress a;
00140     Q_UINT16 pp;
00141     QHostAddress pa;
00142     QSocketDevice::Error e;
00143     QSocketDevicePrivate * d;
00144 
00145     enum Option { Broadcast, ReceiveBuffer, ReuseAddress, SendBuffer };
00146 
00147     int          option( Option ) const;
00148     virtual void setOption( Option, int );
00149 
00150     void         fetchConnectionParameters();
00151 #if defined(Q_OS_WIN32)
00152     void         fetchPeerConnectionParameters();
00153 #endif
00154 
00155     static void  init();
00156     int          createNewSocket();
00157     Protocol     getProtocol() const;
00158 
00159 private:        // Disabled copy constructor and operator=
00160 #if defined(Q_DISABLE_COPY)
00161     QSocketDevice( const QSocketDevice & );
00162     QSocketDevice &operator=( const QSocketDevice & );
00163 #endif
00164 };
00165 
00166 #endif // QT_NO_NETWORK
00167 #endif // QSOCKETDEVICE_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'