MythTV  master
bufferedsocketdevice.h
Go to the documentation of this file.
1 // Program Name: bufferedsocketdevice.h
3 // Created : Oct. 1, 2005
4 //
5 // Purpose :
6 //
7 // Copyright (c) 2005 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 #ifndef BUFFEREDSOCKETDEVICE_H
14 #define BUFFEREDSOCKETDEVICE_H
15 
16 // C++ headers
17 #include <deque>
18 
19 // Qt headers
20 #include <QString>
21 #include <QByteArray>
22 #include <QHostAddress>
23 
24 // MythTV headers
25 #include "mmembuf.h"
26 #include "msocketdevice.h"
27 #include "compat.h"
28 
31 //
32 //
33 //
36 
38 {
39  protected:
40 
41  MSocketDevice *m_pSocket {nullptr};
42 
43  qulonglong m_nMaxReadBufferSize {0};
44  qint64 m_nWriteSize {0};
45  qint64 m_nWriteIndex {0};
46 
47  bool m_bHandleSocketDelete {true};
48 
49  QHostAddress m_destHostAddress;
50  quint16 m_nDestPort {0};
51 
52  MMembuf m_bufRead;
53  std::deque<QByteArray*> m_bufWrite;
54 
55  int ReadBytes ( );
56  bool ConsumeWriteBuf( qulonglong nbytes );
57 
58  public:
59 
60  explicit BufferedSocketDevice( int nSocket );
61  explicit BufferedSocketDevice( MSocketDevice *pSocket = nullptr,
62  bool bTakeOwnership = false );
63 
64  virtual ~BufferedSocketDevice( );
65 
66  MSocketDevice *SocketDevice ();
67  void SetSocketDevice ( MSocketDevice *pSocket );
68 
69  void SetDestAddress ( QHostAddress hostAddress,
70  quint16 nPort );
71 
72  bool Connect ( const QHostAddress &addr,
73  quint16 port );
74  void Close ();
75  void Flush ();
76  qint64 Size ();
77  static qint64 At () ;
78  bool At ( qlonglong index );
79  bool AtEnd ();
80 
81  qulonglong BytesAvailable ();
82  qulonglong WaitForMore ( int msecs,
83  bool *timeout = nullptr );
84 
85  qulonglong BytesToWrite () const;
86  void ClearPendingData ();
87  void ClearReadBuffer ();
88 
89  qlonglong ReadBlock ( char *data,
90  qulonglong maxlen );
91  qlonglong WriteBlock ( const char *data,
92  qulonglong len );
93  qlonglong WriteBlockDirect ( const char *data,
94  qulonglong len );
95 
96  int Getch ();
97  int Putch ( int ch );
98  int Ungetch ( int ch );
99 
100  bool CanReadLine ();
101  QString ReadLine ();
102  QString ReadLine ( int msecs );
103  qlonglong ReadLine ( char *data,
104  qulonglong maxlen );
105 
106  quint16 Port () const;
107  quint16 PeerPort () const;
108  QHostAddress Address () const;
109  QHostAddress PeerAddress () const;
110 
111  void SetReadBufferSize ( qulonglong bufSize );
112  qulonglong ReadBufferSize () const;
113 
114  bool IsValid () { return( ( m_pSocket ) ? m_pSocket->isValid() : false ); }
115  int socket () { return( ( m_pSocket ) ? m_pSocket->socket() : 0 ); }
116 };
117 
118 #endif // BUFFEREDSOCKETDEVICE_H
BufferedSocketDevice::m_bHandleSocketDelete
bool m_bHandleSocketDelete
Definition: bufferedsocketdevice.h:47
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
BufferedSocketDevice::BytesAvailable
qulonglong BytesAvailable()
Definition: bufferedsocketdevice.cpp:371
BufferedSocketDevice::Putch
int Putch(int ch)
Definition: bufferedsocketdevice.cpp:570
BufferedSocketDevice
Definition: bufferedsocketdevice.h:38
BufferedSocketDevice::Connect
bool Connect(const QHostAddress &addr, quint16 port)
Definition: bufferedsocketdevice.cpp:99
BufferedSocketDevice::m_pSocket
MSocketDevice * m_pSocket
Definition: bufferedsocketdevice.h:41
BufferedSocketDevice::SetReadBufferSize
void SetReadBufferSize(qulonglong bufSize)
Definition: bufferedsocketdevice.cpp:145
BufferedSocketDevice::WriteBlock
qlonglong WriteBlock(const char *data, qulonglong len)
Definition: bufferedsocketdevice.cpp:491
BufferedSocketDevice::m_bufRead
MMembuf m_bufRead
Definition: bufferedsocketdevice.h:52
BufferedSocketDevice::m_destHostAddress
QHostAddress m_destHostAddress
Definition: bufferedsocketdevice.h:49
BufferedSocketDevice::m_nMaxReadBufferSize
qulonglong m_nMaxReadBufferSize
Definition: bufferedsocketdevice.h:43
BufferedSocketDevice::Address
QHostAddress Address() const
Definition: bufferedsocketdevice.cpp:695
BufferedSocketDevice::ClearPendingData
void ClearPendingData()
Definition: bufferedsocketdevice.cpp:445
BufferedSocketDevice::Port
quint16 Port() const
Definition: bufferedsocketdevice.cpp:671
BufferedSocketDevice::ReadBlock
qlonglong ReadBlock(char *data, qulonglong maxlen)
Definition: bufferedsocketdevice.cpp:468
BufferedSocketDevice::~BufferedSocketDevice
virtual ~BufferedSocketDevice()
Definition: bufferedsocketdevice.cpp:65
BufferedSocketDevice::Ungetch
int Ungetch(int ch)
Definition: bufferedsocketdevice.cpp:581
BufferedSocketDevice::SetDestAddress
void SetDestAddress(QHostAddress hostAddress, quint16 nPort)
Definition: bufferedsocketdevice.cpp:134
BufferedSocketDevice::WaitForMore
qulonglong WaitForMore(int msecs, bool *timeout=nullptr)
Definition: bufferedsocketdevice.cpp:383
BufferedSocketDevice::CanReadLine
bool CanReadLine()
Definition: bufferedsocketdevice.cpp:590
BufferedSocketDevice::m_nDestPort
quint16 m_nDestPort
Definition: bufferedsocketdevice.h:50
BufferedSocketDevice::ReadLine
QString ReadLine()
Definition: bufferedsocketdevice.cpp:601
compat.h
BufferedSocketDevice::WriteBlockDirect
qlonglong WriteBlockDirect(const char *data, qulonglong len)
Definition: bufferedsocketdevice.cpp:526
BufferedSocketDevice::BufferedSocketDevice
BufferedSocketDevice(int nSocket)
Definition: bufferedsocketdevice.cpp:27
BufferedSocketDevice::PeerAddress
QHostAddress PeerAddress() const
Definition: bufferedsocketdevice.cpp:709
BufferedSocketDevice::SocketDevice
MSocketDevice * SocketDevice()
Definition: bufferedsocketdevice.cpp:111
BufferedSocketDevice::AtEnd
bool AtEnd()
Definition: bufferedsocketdevice.cpp:356
BufferedSocketDevice::IsValid
bool IsValid()
Definition: bufferedsocketdevice.h:114
BufferedSocketDevice::Flush
void Flush()
Definition: bufferedsocketdevice.cpp:252
BufferedSocketDevice::Close
void Close()
Definition: bufferedsocketdevice.cpp:74
BufferedSocketDevice::Getch
int Getch()
Definition: bufferedsocketdevice.cpp:547
BufferedSocketDevice::Size
qint64 Size()
Definition: bufferedsocketdevice.cpp:321
BufferedSocketDevice::At
static qint64 At()
Definition: bufferedsocketdevice.cpp:330
BufferedSocketDevice::ConsumeWriteBuf
bool ConsumeWriteBuf(qulonglong nbytes)
Definition: bufferedsocketdevice.cpp:216
BufferedSocketDevice::socket
int socket()
Definition: bufferedsocketdevice.h:115
BufferedSocketDevice::PeerPort
quint16 PeerPort() const
Definition: bufferedsocketdevice.cpp:683
BufferedSocketDevice::m_nWriteSize
qint64 m_nWriteSize
write total buf size
Definition: bufferedsocketdevice.h:44
BufferedSocketDevice::m_nWriteIndex
qint64 m_nWriteIndex
write index
Definition: bufferedsocketdevice.h:45
BufferedSocketDevice::ReadBytes
int ReadBytes()
Definition: bufferedsocketdevice.cpp:163
BufferedSocketDevice::ReadLine
qlonglong ReadLine(char *data, qulonglong maxlen)
BufferedSocketDevice::ReadBufferSize
qulonglong ReadBufferSize() const
Definition: bufferedsocketdevice.cpp:154
BufferedSocketDevice::ClearReadBuffer
void ClearReadBuffer()
Definition: bufferedsocketdevice.cpp:459
BufferedSocketDevice::SetSocketDevice
void SetSocketDevice(MSocketDevice *pSocket)
Definition: bufferedsocketdevice.cpp:120
BufferedSocketDevice::m_bufWrite
std::deque< QByteArray * > m_bufWrite
Definition: bufferedsocketdevice.h:53
BufferedSocketDevice::BytesToWrite
qulonglong BytesToWrite() const
Definition: bufferedsocketdevice.cpp:435