MythTV  master
Signals | Public Member Functions | Static Public Attributes | Protected Slots | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Friends | List of all members
MythSocket Class Reference

Class for communcating between myth backends and frontends. More...

#include <mythsocket.h>

Inheritance diagram for MythSocket:
Inheritance graph
[legend]
Collaboration diagram for MythSocket:
Collaboration graph
[legend]

Signals

void CallReadyRead (void)
 

Public Member Functions

 MythSocket (qintptr socket=-1, MythSocketCBs *cb=nullptr, bool use_shared_thread=false)
 
bool ConnectToHost (const QString &hostname, quint16 port)
 connect to host More...
 
bool ConnectToHost (const QHostAddress &address, quint16 port)
 
void DisconnectFromHost (void)
 
bool Validate (std::chrono::milliseconds timeout=kMythSocketLongTimeout, bool error_dialog_desired=false)
 
bool IsValidated (void) const
 
bool Announce (const QStringList &new_announce)
 
QStringList GetAnnounce (void) const
 
void SetAnnounce (const QStringList &new_announce)
 
bool IsAnnounced (void) const
 
void SetReadyReadCallbackEnabled (bool enabled)
 
bool SendReceiveStringList (QStringList &list, uint min_reply_length=0, std::chrono::milliseconds timeoutMS=kLongTimeout)
 
bool ReadStringList (QStringList &list, std::chrono::milliseconds timeoutMS=kShortTimeout)
 
bool WriteStringList (const QStringList &list)
 
bool IsConnected (void) const
 
bool IsDataAvailable (void)
 
QHostAddress GetPeerAddress (void) const
 
int GetPeerPort (void) const
 
int GetSocketDescriptor (void) const
 
int Write (const char *data, int size)
 
int Read (char *data, int size, std::chrono::milliseconds max_wait)
 
void Reset (void)
 
- Public Member Functions inherited from ReferenceCounter
 ReferenceCounter (const QString &debugName, bool logDebug=true)
 Creates reference counter with an initial value of 1. More...
 
virtual int IncrRef (void)
 Increments reference count. More...
 
virtual int DecrRef (void)
 Decrements reference count and deletes on 0. More...
 

Static Public Attributes

static constexpr std::chrono::milliseconds kShortTimeout { kMythSocketShortTimeout }
 
static constexpr std::chrono::milliseconds kLongTimeout { kMythSocketLongTimeout }
 

Protected Slots

void ConnectHandler (void)
 
void ErrorHandler (QAbstractSocket::SocketError err)
 
void AboutToCloseHandler (void)
 
void DisconnectHandler (void)
 
void ReadyReadHandler (void)
 
void CallReadyReadHandler (void)
 
void ReadStringListReal (QStringList *list, std::chrono::milliseconds timeoutMS, bool *ret)
 
void WriteStringListReal (const QStringList *list, bool *ret)
 
void ConnectToHostReal (const QHostAddress &addr, quint16 port, bool *ret)
 
void DisconnectFromHostReal (void)
 
void WriteReal (const char *data, int size, int *ret)
 
void ReadReal (char *data, int size, std::chrono::milliseconds max_wait_ms, int *ret)
 
void ResetReal (void)
 
void IsDataAvailableReal (bool *ret) const
 

Protected Member Functions

 ~MythSocket () override
 
- Protected Member Functions inherited from ReferenceCounter
virtual ~ReferenceCounter (void)
 Called on destruction, will warn if object deleted with references in place. More...
 

Protected Attributes

QTcpSocket * m_tcpSocket {nullptr}
 
MThreadm_thread {nullptr}
 
QMutex m_lock
 
qintptr m_socketDescriptor {-1}
 
QHostAddress m_peerAddress
 
int m_peerPort {-1}
 
MythSocketCBsm_callback {nullptr}
 
bool m_useSharedThread
 
QAtomicInt m_disableReadyReadCallback {0}
 
bool m_connected {false}
 
QAtomicInt m_dataAvailable {0}
 This is used internally as a hint that there might be data available for reading. More...
 
bool m_isValidated {false}
 
bool m_isAnnounced {false}
 
QStringList m_announce
 
- Protected Attributes inherited from ReferenceCounter
bool m_logDebug
 This is used to suppress creating LoggingItem classes for LoggingItem reference count changes. More...
 
QAtomicInt m_referenceCount {1}
 

Static Protected Attributes

static const int kSocketReceiveBufferSize = 128 * 1024
 
static QMutex s_loopbackCacheLock
 
static QHash< QString, QHostAddress::SpecialAddress > s_loopbackCache
 
static QMutex s_thread_lock
 
static MThreads_thread = nullptr
 
static int s_thread_cnt = 0
 

Private Member Functions

QString LOC ()
 

Friends

class MythSocketManager
 

Additional Inherited Members

- Static Public Member Functions inherited from ReferenceCounter
static void PrintDebug (void)
 Print out any leaks if that level of debugging is enabled. More...
 

Detailed Description

Class for communcating between myth backends and frontends.

Note
Access to the methods of MythSocket must be externally serialized (i.e. the MythSocket must only be available to one thread at a time).

Definition at line 25 of file mythsocket.h.

Constructor & Destructor Documentation

◆ MythSocket()

MythSocket::MythSocket ( qintptr  socket = -1,
MythSocketCBs cb = nullptr,
bool  use_shared_thread = false 
)
explicit

Definition at line 71 of file mythsocket.cpp.

◆ ~MythSocket()

MythSocket::~MythSocket ( )
overrideprotected

Definition at line 140 of file mythsocket.cpp.

Member Function Documentation

◆ ConnectToHost() [1/2]

bool MythSocket::ConnectToHost ( const QString &  host,
quint16  port 
)

connect to host

Returns
true on success

Definition at line 374 of file mythsocket.cpp.

Referenced by MythCoreContext::ConnectCommandSocket(), ZMClient::connectToHost(), and OutboundRequestHandler::DoConnectToMaster().

◆ ConnectToHost() [2/2]

bool MythSocket::ConnectToHost ( const QHostAddress &  address,
quint16  port 
)

Definition at line 287 of file mythsocket.cpp.

◆ DisconnectFromHost()

void MythSocket::DisconnectFromHost ( void  )

◆ Validate()

bool MythSocket::Validate ( std::chrono::milliseconds  timeout = kMythSocketLongTimeout,
bool  error_dialog_desired = false 
)

Definition at line 403 of file mythsocket.cpp.

Referenced by OutboundRequestHandler::DoConnectToMaster().

◆ IsValidated()

bool MythSocket::IsValidated ( void  ) const
inline

Definition at line 41 of file mythsocket.h.

Referenced by MythSocketManager::ProcessRequestWork().

◆ Announce()

bool MythSocket::Announce ( const QStringList &  new_announce)

Definition at line 456 of file mythsocket.cpp.

Referenced by ControlRequestHandler::AnnounceSocket().

◆ GetAnnounce()

QStringList MythSocket::GetAnnounce ( void  ) const
inline

Definition at line 44 of file mythsocket.h.

◆ SetAnnounce()

void MythSocket::SetAnnounce ( const QStringList &  new_announce)

Definition at line 492 of file mythsocket.cpp.

Referenced by BaseRequestHandler::HandleAnnounce().

◆ IsAnnounced()

bool MythSocket::IsAnnounced ( void  ) const
inline

Definition at line 46 of file mythsocket.h.

Referenced by MythSocketManager::ProcessRequestWork().

◆ SetReadyReadCallbackEnabled()

void MythSocket::SetReadyReadCallbackEnabled ( bool  enabled)
inline

◆ SendReceiveStringList()

bool MythSocket::SendReceiveStringList ( QStringList &  list,
uint  min_reply_length = 0,
std::chrono::milliseconds  timeoutMS = kLongTimeout 
)

◆ ReadStringList()

bool MythSocket::ReadStringList ( QStringList &  list,
std::chrono::milliseconds  timeoutMS = kShortTimeout 
)

◆ WriteStringList()

bool MythSocket::WriteStringList ( const QStringList &  list)

◆ IsConnected()

bool MythSocket::IsConnected ( void  ) const

◆ IsDataAvailable()

bool MythSocket::IsDataAvailable ( void  )

◆ GetPeerAddress()

QHostAddress MythSocket::GetPeerAddress ( void  ) const

Definition at line 581 of file mythsocket.cpp.

Referenced by MainServer::HandleAnnounce().

◆ GetPeerPort()

int MythSocket::GetPeerPort ( void  ) const

Definition at line 587 of file mythsocket.cpp.

◆ GetSocketDescriptor()

int MythSocket::GetSocketDescriptor ( void  ) const

◆ Write()

int MythSocket::Write ( const char *  data,
int  size 
)

◆ Read()

int MythSocket::Read ( char *  data,
int  size,
std::chrono::milliseconds  max_wait 
)

◆ Reset()

void MythSocket::Reset ( void  )

Definition at line 541 of file mythsocket.cpp.

Referenced by RemoteFile::Read(), RemoteFile::Reset(), and RemoteFile::SeekInternal().

◆ LOC()

QString MythSocket::LOC ( )
inlineprivate

◆ CallReadyRead

void MythSocket::CallReadyRead ( void  )
signal

Referenced by MythSocket(), and ReadyReadHandler().

◆ ConnectHandler

void MythSocket::ConnectHandler ( void  )
protectedslot

Definition at line 175 of file mythsocket.cpp.

Referenced by MythSocket().

◆ ErrorHandler

void MythSocket::ErrorHandler ( QAbstractSocket::SocketError  err)
protectedslot

Definition at line 226 of file mythsocket.cpp.

Referenced by MythSocket().

◆ AboutToCloseHandler

void MythSocket::AboutToCloseHandler ( void  )
protectedslot

Definition at line 259 of file mythsocket.cpp.

Referenced by MythSocket().

◆ DisconnectHandler

void MythSocket::DisconnectHandler ( void  )
protectedslot

Definition at line 241 of file mythsocket.cpp.

Referenced by MythSocket().

◆ ReadyReadHandler

void MythSocket::ReadyReadHandler ( void  )
protectedslot

Definition at line 264 of file mythsocket.cpp.

Referenced by MythSocket().

◆ CallReadyReadHandler

void MythSocket::CallReadyReadHandler ( void  )
protectedslot

Definition at line 273 of file mythsocket.cpp.

Referenced by MythSocket().

◆ ReadStringListReal

void MythSocket::ReadStringListReal ( QStringList *  list,
std::chrono::milliseconds  timeoutMS,
bool ret 
)
protectedslot

Definition at line 790 of file mythsocket.cpp.

◆ WriteStringListReal

void MythSocket::WriteStringListReal ( const QStringList *  list,
bool ret 
)
protectedslot

Definition at line 689 of file mythsocket.cpp.

◆ ConnectToHostReal

void MythSocket::ConnectToHostReal ( const QHostAddress &  addr,
quint16  port,
bool ret 
)
protectedslot

Definition at line 601 of file mythsocket.cpp.

◆ DisconnectFromHostReal

void MythSocket::DisconnectFromHostReal ( void  )
protectedslot

Definition at line 684 of file mythsocket.cpp.

◆ WriteReal

void MythSocket::WriteReal ( const char *  data,
int  size,
int *  ret 
)
protectedslot

Definition at line 951 of file mythsocket.cpp.

◆ ReadReal

void MythSocket::ReadReal ( char *  data,
int  size,
std::chrono::milliseconds  max_wait_ms,
int *  ret 
)
protectedslot

Definition at line 956 of file mythsocket.cpp.

◆ ResetReal

void MythSocket::ResetReal ( void  )
protectedslot

Definition at line 979 of file mythsocket.cpp.

Referenced by ReadStringListReal().

◆ IsDataAvailableReal

void MythSocket::IsDataAvailableReal ( bool ret) const
protectedslot

Definition at line 595 of file mythsocket.cpp.

Friends And Related Function Documentation

◆ MythSocketManager

friend class MythSocketManager
friend

Definition at line 29 of file mythsocket.h.

Member Data Documentation

◆ kShortTimeout

constexpr std::chrono::milliseconds MythSocket::kShortTimeout { kMythSocketShortTimeout }
staticconstexpr

◆ kLongTimeout

constexpr std::chrono::milliseconds MythSocket::kLongTimeout { kMythSocketLongTimeout }
staticconstexpr

Definition at line 71 of file mythsocket.h.

Referenced by MythCoreContext::SendReceiveStringList().

◆ m_tcpSocket

QTcpSocket* MythSocket::m_tcpSocket {nullptr}
protected

◆ m_thread

MThread* MythSocket::m_thread {nullptr}
protected

◆ m_lock

QMutex MythSocket::m_lock
mutableprotected

◆ m_socketDescriptor

qintptr MythSocket::m_socketDescriptor {-1}
protected

Definition at line 109 of file mythsocket.h.

Referenced by ConnectHandler(), DisconnectHandler(), and GetSocketDescriptor().

◆ m_peerAddress

QHostAddress MythSocket::m_peerAddress
protected

Definition at line 110 of file mythsocket.h.

Referenced by ConnectHandler(), DisconnectHandler(), and GetPeerAddress().

◆ m_peerPort

int MythSocket::m_peerPort {-1}
protected

Definition at line 111 of file mythsocket.h.

Referenced by ConnectHandler(), DisconnectHandler(), and GetPeerPort().

◆ m_callback

MythSocketCBs* MythSocket::m_callback {nullptr}
protected

◆ m_useSharedThread

bool MythSocket::m_useSharedThread
protected

Definition at line 113 of file mythsocket.h.

Referenced by MythSocket(), and ~MythSocket().

◆ m_disableReadyReadCallback

QAtomicInt MythSocket::m_disableReadyReadCallback {0}
protected

Definition at line 114 of file mythsocket.h.

Referenced by ReadyReadHandler(), and SendReceiveStringList().

◆ m_connected

bool MythSocket::m_connected {false}
protected

Definition at line 115 of file mythsocket.h.

Referenced by ConnectHandler(), DisconnectHandler(), IsConnected(), and MythSocket().

◆ m_dataAvailable

QAtomicInt MythSocket::m_dataAvailable {0}
mutableprotected

This is used internally as a hint that there might be data available for reading.

Definition at line 118 of file mythsocket.h.

Referenced by IsDataAvailable(), IsDataAvailableReal(), ReadReal(), ReadStringListReal(), ReadyReadHandler(), and ResetReal().

◆ m_isValidated

bool MythSocket::m_isValidated {false}
protected

Definition at line 119 of file mythsocket.h.

Referenced by Announce(), MythSocketManager::HandleVersion(), and Validate().

◆ m_isAnnounced

bool MythSocket::m_isAnnounced {false}
protected

Definition at line 120 of file mythsocket.h.

Referenced by Announce(), and SetAnnounce().

◆ m_announce

QStringList MythSocket::m_announce
protected

Definition at line 121 of file mythsocket.h.

Referenced by Announce(), and SetAnnounce().

◆ kSocketReceiveBufferSize

const int MythSocket::kSocketReceiveBufferSize = 128 * 1024
staticprotected

Definition at line 123 of file mythsocket.h.

Referenced by ConnectHandler().

◆ s_loopbackCacheLock

QMutex MythSocket::s_loopbackCacheLock
staticprotected

Definition at line 125 of file mythsocket.h.

Referenced by ConnectToHostReal().

◆ s_loopbackCache

QHash< QString, QHostAddress::SpecialAddress > MythSocket::s_loopbackCache
staticprotected

Definition at line 126 of file mythsocket.h.

Referenced by ConnectToHostReal().

◆ s_thread_lock

QMutex MythSocket::s_thread_lock
staticprotected

Definition at line 128 of file mythsocket.h.

Referenced by MythSocket(), and ~MythSocket().

◆ s_thread

MThread * MythSocket::s_thread = nullptr
staticprotected

Definition at line 129 of file mythsocket.h.

Referenced by MythSocket(), and ~MythSocket().

◆ s_thread_cnt

int MythSocket::s_thread_cnt = 0
staticprotected

Definition at line 130 of file mythsocket.h.

Referenced by MythSocket(), and ~MythSocket().


The documentation for this class was generated from the following files: