Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qsocket.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of QSocket 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 QSOCKET_H 00039 #define QSOCKET_H 00040 00041 #ifndef QT_H 00042 #include "qobject.h" 00043 #include "qiodevice.h" 00044 #include "qhostaddress.h" // int->QHostAddress conversion 00045 #endif // QT_H 00046 00047 #if !defined( QT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK ) 00048 #define QM_EXPORT_NETWORK 00049 #else 00050 #define QM_EXPORT_NETWORK Q_EXPORT 00051 #endif 00052 00053 #ifndef QT_NO_NETWORK 00054 class QSocketPrivate; 00055 class QSocketDevice; 00056 00057 00058 class QM_EXPORT_NETWORK QSocket : public QObject, public QIODevice 00059 { 00060 Q_OBJECT 00061 public: 00062 enum Error { 00063 ErrConnectionRefused, 00064 ErrHostNotFound, 00065 ErrSocketRead 00066 }; 00067 00068 QSocket( QObject *parent=0, const char *name=0 ); 00069 virtual ~QSocket(); 00070 00071 enum State { Idle, HostLookup, Connecting, 00072 Connected, Closing, 00073 Connection=Connected }; 00074 State state() const; 00075 00076 int socket() const; 00077 virtual void setSocket( int ); 00078 00079 QSocketDevice *socketDevice(); 00080 virtual void setSocketDevice( QSocketDevice * ); 00081 00082 #ifndef QT_NO_DNS 00083 virtual void connectToHost( const QString &host, Q_UINT16 port ); 00084 #endif 00085 QString peerName() const; 00086 00087 // Implementation of QIODevice abstract virtual functions 00088 bool open( int mode ); 00089 void close(); 00090 void flush(); 00091 Offset size() const; 00092 Offset at() const; 00093 bool at( Offset ); 00094 bool atEnd() const; 00095 00096 Q_ULONG bytesAvailable() const; // ### QIODevice::Offset instead? 00097 Q_ULONG waitForMore( int msecs, bool *timeout ) const; 00098 Q_ULONG waitForMore( int msecs ) const; // ### Qt 4.0: merge the two overloads 00099 Q_ULONG bytesToWrite() const; 00100 void clearPendingData(); 00101 00102 Q_LONG readBlock( char *data, Q_ULONG maxlen ); 00103 Q_LONG writeBlock( const char *data, Q_ULONG len ); 00104 Q_LONG readLine( char *data, Q_ULONG maxlen ); 00105 00106 int getch(); 00107 int putch( int ); 00108 int ungetch(int); 00109 00110 bool canReadLine() const; 00111 virtual QString readLine(); 00112 00113 Q_UINT16 port() const; 00114 Q_UINT16 peerPort() const; 00115 QHostAddress address() const; 00116 QHostAddress peerAddress() const; 00117 00118 void setReadBufferSize( Q_ULONG ); 00119 Q_ULONG readBufferSize() const; 00120 00121 signals: 00122 void hostFound(); 00123 void connected(); 00124 void connectionClosed(); 00125 void delayedCloseFinished(); 00126 void readyRead(); 00127 void bytesWritten( int nbytes ); 00128 void error( int ); 00129 00130 protected slots: 00131 virtual void sn_read( bool force=FALSE ); 00132 virtual void sn_write(); 00133 00134 private slots: 00135 void tryConnecting(); 00136 void emitErrorConnectionRefused(); 00137 00138 private: 00139 QSocketPrivate *d; 00140 00141 bool consumeWriteBuf( Q_ULONG nbytes ); 00142 void tryConnection(); 00143 void setSocketIntern( int socket ); 00144 00145 private: // Disabled copy constructor and operator= 00146 #if defined(Q_DISABLE_COPY) 00147 QSocket( const QSocket & ); 00148 QSocket &operator=( const QSocket & ); 00149 #endif 00150 }; 00151 00152 #endif //QT_NO_NETWORK 00153 #endif // QSOCKET_H