MythSocket Class Reference

#include <mythsocket.h>

Inheritance diagram for MythSocket:
MSocketDevice

List of all members.

Public Types

enum  State { Connected, Connecting, HostLookup, Idle }

Public Member Functions

 MythSocket (int socket=-1, MythSocketCBs *cb=NULL)
void close (void)
bool closedByRemote (void)
void deleteLater (void)
void UpRef (void)
bool DownRef (void)
State state (void) const
QString stateToString (void) const
QString stateToString (const State state) const
QString errorToString (void) const
QString errorToString (const Error error) const
bool Validate (uint timeout_ms=kMythSocketLongTimeout, bool error_dialog_desired=false)
void setValidated (bool isValidated=true)
bool isValidated (void)
bool Announce (QStringList &strlist)
QStringList getAnnounce (void)
void setAnnounce (QStringList &strlist)
bool isAnnounced (void)
bool isExpectingReply (void)
void setSocket (int socket, Type type=MSocketDevice::Stream)
void setCallbacks (MythSocketCBs *cb)
void useReadyReadCallback (bool useReadyReadCallback=true)
qint64 readBlock (char *data, quint64 len)
qint64 writeBlock (const char *data, quint64 len)
 Attempt to write 'len' bytes to socket.
bool readStringList (QStringList &list, uint timeoutMS=kLongTimeout)
bool readStringList (QStringList &list, bool quickTimeout)
bool writeStringList (QStringList &list)
bool SendReceiveStringList (QStringList &list, uint min_reply_length=0)
bool readData (char *data, quint64 len)
 Read len bytes to data from socket.
bool writeData (const char *data, quint64 len)
 Write len bytes to data to socket.
bool connect (const QHostAddress &hadr, quint16 port)
 connect to host
bool connect (const QString &host, quint16 port)
 connect to host
void Lock (void) const
bool TryLock (bool wakereadyread) const
void Unlock (bool wakereadyread=true) const

Static Public Attributes

static const uint kShortTimeout = kMythSocketShortTimeout
static const uint kLongTimeout = kMythSocketLongTimeout

Protected Member Functions

 ~MythSocket ()
void setState (const State state)

Protected Attributes

MythSocketCBsm_cb
bool m_useReadyReadCallback
State m_state
QHostAddress m_addr
quint16 m_port
int m_ref_count
bool m_notifyread
QMutex m_ref_lock
QMutex m_lock
bool m_expectingreply
bool m_isValidated
bool m_isAnnounced
QStringList m_announce

Static Protected Attributes

static const uint kSocketBufferSize = 128000
static QMutex s_readyread_thread_lock
static MythSocketThreads_readyread_thread = NULL
static QMap< QString,
QHostAddress::SpecialAddress > 
s_loopback_cache

Friends

class MythSocketThread
class QList< MythSocket * >
void ShutdownRRT (void)

Detailed Description

Definition at line 18 of file mythsocket.h.


Member Enumeration Documentation

Enumerator:
Connected 
Connecting 
HostLookup 
Idle 

Definition at line 27 of file mythsocket.h.


Constructor & Destructor Documentation

MythSocket::MythSocket ( int  socket = -1,
MythSocketCBs cb = NULL 
)

Definition at line 44 of file mythsocket.cpp.

MythSocket::~MythSocket (  )  [protected]

Definition at line 73 of file mythsocket.cpp.


Member Function Documentation

void MythSocket::close ( void   ) 

Closes the socket and sets the socket identifier to -1 (invalid).

(This function ignores errors; if there are any then a file descriptor leakage might result. As far as we know, the only error that can arise is EBADF, and that would of course not cause leakage. There may be OS-specific errors that we haven't come across, however.)

See also:
open()

Reimplemented from MSocketDevice.

Definition at line 210 of file mythsocket.cpp.

Referenced by connect(), MythSocketManager::HandleDone(), MainServer::HandleDone(), readBlock(), ZMClient::readData(), readData(), readStringList(), MythSocketThread::ReadyToBeRead(), setSocket(), ZMClient::shutdown(), LCD::shutdown(), writeBlock(), writeData(), and ~MythSocket().

bool MythSocket::closedByRemote ( void   ) 

Definition at line 221 of file mythsocket.cpp.

Referenced by MythSocketThread::ReadyToBeRead().

void MythSocket::deleteLater ( void   ) 
void MythSocket::UpRef ( void   ) 
bool MythSocket::DownRef ( void   ) 
MythSocket::State MythSocket::state ( void   )  const
QString MythSocket::stateToString ( void   )  const [inline]

Definition at line 42 of file mythsocket.h.

Referenced by setState(), and stateToString().

QString MythSocket::stateToString ( const State  state  )  const

Definition at line 142 of file mythsocket.cpp.

QString MythSocket::errorToString ( void   )  const [inline]
QString MythSocket::errorToString ( const Error  error  )  const

Definition at line 159 of file mythsocket.cpp.

bool MythSocket::Validate ( uint  timeout_ms = kMythSocketLongTimeout,
bool  error_dialog_desired = false 
)

Definition at line 853 of file mythsocket.cpp.

Referenced by OutboundRequestHandler::DoConnectToMaster().

void MythSocket::setValidated ( bool  isValidated = true  )  [inline]

Definition at line 50 of file mythsocket.h.

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

bool MythSocket::isValidated ( void   )  [inline]

Definition at line 51 of file mythsocket.h.

Referenced by MythSocketManager::ProcessRequestWork().

bool MythSocket::Announce ( QStringList &  strlist  ) 

Definition at line 903 of file mythsocket.cpp.

Referenced by ControlRequestHandler::AnnounceSocket().

QStringList MythSocket::getAnnounce ( void   )  [inline]

Definition at line 54 of file mythsocket.h.

void MythSocket::setAnnounce ( QStringList &  strlist  ) 

Definition at line 935 of file mythsocket.cpp.

Referenced by BaseRequestHandler::HandleAnnounce().

bool MythSocket::isAnnounced ( void   )  [inline]

Definition at line 56 of file mythsocket.h.

Referenced by MythSocketManager::ProcessRequestWork().

bool MythSocket::isExpectingReply ( void   )  [inline]

Definition at line 58 of file mythsocket.h.

Referenced by MythSocketManager::ProcessRequest(), and MythSocketManager::readyRead().

void MythSocket::setSocket ( int  socket,
Type  type = MSocketDevice::Stream 
) [virtual]

Sets the socket device to operate on the existing socket socket.

The type argument must match the actual socket type; use MSocketDevice::Stream for a reliable, connection-oriented TCP socket, or MSocketDevice::Datagram for an unreliable, connectionless UDP socket.

Any existing socket is closed.

See also:
isValid(), close()

Reimplemented from MSocketDevice.

Definition at line 188 of file mythsocket.cpp.

Referenced by MythSocket().

void MythSocket::setCallbacks ( MythSocketCBs cb  ) 
void MythSocket::useReadyReadCallback ( bool  useReadyReadCallback = true  )  [inline]

Definition at line 62 of file mythsocket.h.

Referenced by FileTransfer::FileTransfer().

qint64 MythSocket::readBlock ( char *  data,
quint64  len 
)
qint64 MythSocket::writeBlock ( const char *  data,
quint64  len 
)

Attempt to write 'len' bytes to socket.

Returns:
actual bytes written

Reimplemented from MSocketDevice.

Definition at line 264 of file mythsocket.cpp.

Referenced by RemoteFile::Write(), writeData(), and writeStringList().

bool MythSocket::readStringList ( QStringList &  list,
uint  timeoutMS = kLongTimeout 
)
bool MythSocket::readStringList ( QStringList &  list,
bool  quickTimeout 
) [inline]

Definition at line 69 of file mythsocket.h.

bool MythSocket::writeStringList ( QStringList &  list  ) 
bool MythSocket::SendReceiveStringList ( QStringList &  list,
uint  min_reply_length = 0 
)
bool MythSocket::readData ( char *  data,
quint64  len 
)

Read len bytes to data from socket.

Returns:
true if desired len of data is read

Definition at line 405 of file mythsocket.cpp.

Referenced by FileTransfer::WriteBlock().

bool MythSocket::writeData ( const char *  data,
quint64  len 
)

Write len bytes to data to socket.

Returns:
true if entire len of data is written

Definition at line 461 of file mythsocket.cpp.

Referenced by FileTransfer::RequestBlock().

bool MythSocket::connect ( const QHostAddress &  hadr,
quint16  port 
) [virtual]
bool MythSocket::connect ( const QString &  host,
quint16  port 
)

connect to host

Returns:
true on success

Definition at line 756 of file mythsocket.cpp.

void MythSocket::Lock ( void   )  const
bool MythSocket::TryLock ( bool  wakereadyread  )  const

Definition at line 734 of file mythsocket.cpp.

void MythSocket::Unlock ( bool  wakereadyread = true  )  const
void MythSocket::setState ( const State  state  )  [protected]

Definition at line 131 of file mythsocket.cpp.

Referenced by close(), connect(), and setSocket().


Friends And Related Function Documentation

friend class MythSocketThread [friend]

Definition at line 20 of file mythsocket.h.

Referenced by MythSocket().

friend class QList< MythSocket * > [friend]

Definition at line 21 of file mythsocket.h.

void ShutdownRRT ( void   )  [friend]

Definition at line 47 of file mythsocketthread.cpp.


Member Data Documentation

const uint MythSocket::kShortTimeout = kMythSocketShortTimeout [static]
const uint MythSocket::kLongTimeout = kMythSocketLongTimeout [static]

Definition at line 87 of file mythsocket.h.

Definition at line 95 of file mythsocket.h.

Referenced by MythSocketThread::ReadyToBeRead().

Definition at line 96 of file mythsocket.h.

Referenced by setState(), and state().

QHostAddress MythSocket::m_addr [protected]

Definition at line 97 of file mythsocket.h.

Referenced by Announce().

quint16 MythSocket::m_port [protected]

Definition at line 98 of file mythsocket.h.

Referenced by Announce().

int MythSocket::m_ref_count [protected]

Definition at line 99 of file mythsocket.h.

Referenced by DownRef(), and UpRef().

Definition at line 101 of file mythsocket.h.

Referenced by readBlock(), readStringList(), and MythSocketThread::ReadyToBeRead().

QMutex MythSocket::m_ref_lock [protected]

Definition at line 102 of file mythsocket.h.

Referenced by DownRef(), and UpRef().

QMutex MythSocket::m_lock [mutable, protected]

Definition at line 103 of file mythsocket.h.

Referenced by Lock(), TryLock(), and Unlock().

Definition at line 105 of file mythsocket.h.

Referenced by SendReceiveStringList().

Definition at line 106 of file mythsocket.h.

Referenced by Announce(), and Validate().

Definition at line 107 of file mythsocket.h.

Referenced by Announce(), and setAnnounce().

QStringList MythSocket::m_announce [protected]

Definition at line 108 of file mythsocket.h.

Referenced by Announce(), and setAnnounce().

const uint MythSocket::kSocketBufferSize = 128000 [static, protected]

Definition at line 110 of file mythsocket.h.

Referenced by connect(), MythSocket(), readData(), and writeData().

QMutex MythSocket::s_readyread_thread_lock [static, protected]

Definition at line 111 of file mythsocket.h.

Referenced by MythSocket(), and ShutdownRRT().

MythSocketThread * MythSocket::s_readyread_thread = NULL [static, protected]
QMap< QString, QHostAddress::SpecialAddress > MythSocket::s_loopback_cache [static, protected]

Definition at line 114 of file mythsocket.h.

Referenced by connect().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends
Generated on Fri Feb 10 06:42:12 2012 for MythTV by  doxygen 1.6.3