MythTV master
Public Member Functions | Private Attributes | List of all members
BlockingTcpSocket Class Reference

Wraps a QTcpSocket to provide a blocking connect(), readLine(), and write() with a timeout. More...

#include <libmythupnp/blockingtcpsocket.h>

Public Member Functions

 BlockingTcpSocket ()=default
 
bool connect (const QHostAddress &address, quint16 port, std::chrono::milliseconds timeout)
 Connect the socket to a host. More...
 
QString readLine (std::chrono::milliseconds timeout)
 Read a whole line from the socket. More...
 
qint64 write (const char *data, qint64 size, std::chrono::milliseconds timeout)
 

Private Attributes

QTcpSocket m_socket
 

Detailed Description

Wraps a QTcpSocket to provide a blocking connect(), readLine(), and write() with a timeout.

Definition at line 13 of file blockingtcpsocket.h.

Constructor & Destructor Documentation

◆ BlockingTcpSocket()

BlockingTcpSocket::BlockingTcpSocket ( )
default

Member Function Documentation

◆ connect()

bool BlockingTcpSocket::connect ( const QHostAddress &  address,
quint16  port,
std::chrono::milliseconds  timeout 
)

Connect the socket to a host.

Returns
True if a connection was established.

Definition at line 6 of file blockingtcpsocket.cpp.

Referenced by UPnpEventTask::Execute(), UPNPSubscription::SendSubscribeRequest(), and UPNPSubscription::SendUnsubscribeRequest().

◆ readLine()

QString BlockingTcpSocket::readLine ( std::chrono::milliseconds  timeout)

Read a whole line from the socket.

The data will remain buffered in the socket until QIODevice::canReadLine() returns true.

Parameters
timeoutTotal amount of time to wait.
Returns
The entire line read from the socket, including '
' per the QIODevice::readLine() documentation, or an empty string if no '
' was read.

Definition at line 19 of file blockingtcpsocket.cpp.

Referenced by UPnpEventTask::Execute(), UPNPSubscription::SendSubscribeRequest(), and UPNPSubscription::SendUnsubscribeRequest().

◆ write()

qint64 BlockingTcpSocket::write ( const char *  data,
qint64  size,
std::chrono::milliseconds  timeout 
)

Member Data Documentation

◆ m_socket

QTcpSocket BlockingTcpSocket::m_socket
private

Definition at line 32 of file blockingtcpsocket.h.

Referenced by connect(), readLine(), and write().


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