00001 00002 // Program Name: bufferedsocketdevice.h 00003 // 00004 // Purpose - 00005 // 00006 // Created By : David Blain Created On : Oct. 1, 2005 00007 // Modified By : Modified On: 00008 // 00010 00011 #ifndef __BUFFEREDSOCKETDEVICE_H__ 00012 #define __BUFFEREDSOCKETDEVICE_H__ 00013 00014 // Qt headers 00015 #include <qsocketdevice.h> 00016 00017 // MythTV headers 00018 #include "private/qinternal_p.h" 00019 #include "compat.h" 00020 00023 // 00024 // 00025 // 00028 00029 class BufferedSocketDevice 00030 { 00031 protected: 00032 00033 QSocketDevice *m_pSocket; 00034 00035 Q_ULONG m_nMaxReadBufferSize; 00036 QIODevice::Offset m_nWriteSize; // write total buf size 00037 QIODevice::Offset m_nWriteIndex; // write index 00038 00039 bool m_bHandleSocketDelete; 00040 00041 QHostAddress m_DestHostAddress; 00042 Q_UINT16 m_nDestPort; 00043 00044 QMembuf m_bufRead; 00045 QPtrList<QByteArray> m_bufWrite; 00046 00047 int ReadBytes ( ); 00048 bool ConsumeWriteBuf( Q_ULONG nbytes ); 00049 00050 public: 00051 00052 BufferedSocketDevice( int nSocket ); 00053 BufferedSocketDevice( QSocketDevice *pSocket = NULL, 00054 bool bTakeOwnership = false ); 00055 00056 virtual ~BufferedSocketDevice( ); 00057 00058 QSocketDevice *SocketDevice (); 00059 void SetSocketDevice ( QSocketDevice *pSocket ); 00060 00061 void SetDestAddress ( QHostAddress hostAddress, 00062 Q_UINT16 nPort ); 00063 00064 bool Connect ( const QHostAddress & addr, Q_UINT16 port ); 00065 void Close (); 00066 void Flush (); 00067 QIODevice::Offset Size (); 00068 QIODevice::Offset At (); 00069 bool At ( QIODevice::Offset ); 00070 bool AtEnd (); 00071 00072 Q_ULONG BytesAvailable (); 00073 Q_ULONG WaitForMore ( int msecs, bool *timeout = NULL ); 00074 00075 Q_ULONG BytesToWrite () const; 00076 void ClearPendingData (); 00077 void ClearReadBuffer (); 00078 00079 Q_LONG ReadBlock ( char *data, Q_ULONG maxlen ); 00080 Q_LONG WriteBlock ( const char *data, Q_ULONG len ); 00081 Q_LONG WriteBlockDirect ( const char *data, Q_ULONG len ); 00082 00083 int Getch (); 00084 int Putch ( int ); 00085 int Ungetch (int); 00086 00087 bool CanReadLine (); 00088 QString ReadLine (); 00089 QString ReadLine ( int msecs ); 00090 Q_LONG ReadLine ( char *data, Q_ULONG maxlen ); 00091 00092 Q_UINT16 Port () const; 00093 Q_UINT16 PeerPort () const; 00094 QHostAddress Address () const; 00095 QHostAddress PeerAddress () const; 00096 00097 void SetReadBufferSize ( Q_ULONG ); 00098 Q_ULONG ReadBufferSize () const; 00099 00100 bool IsValid () { return( ( m_pSocket ) ? m_pSocket->isValid() : false ); } 00101 int socket () { return( ( m_pSocket ) ? m_pSocket->socket() : 0 ); } 00102 }; 00103 00104 #endif
1.5.5