Overte C++ Documentation
NetworkSocket Class Reference

Multiplexes a QUdpSocket and a WebRTCSocket so that they appear as a single QUdpSocket-style socket. More...

#include <NetworkSocket.h>

Inherits QObject.

Signals

void readyRead ()
 Emitted each time new data becomes available for reading.
 
void stateChanged (SocketType socketType, QAbstractSocket::SocketState socketState)
 Emitted when the state of the underlying UDP or WebRTC socket changes. More...
 
void socketError (SocketType socketType, QAbstractSocket::SocketError socketError)
 

Public Member Functions

 NetworkSocket (QObject *parent)
 Constructs a new NetworkSocket object. More...
 
void setSocketOption (SocketType socketType, QAbstractSocket::SocketOption option, const QVariant &value)
 Set the value of a UDP or WebRTC socket option. More...
 
QVariant socketOption (SocketType socketType, QAbstractSocket::SocketOption option)
 Gets the value of a UDP or WebRTC socket option. More...
 
void bind (SocketType socketType, const QHostAddress &address, quint16 port=0)
 Binds the UDP or WebRTC socket to an address and port. More...
 
void abort (SocketType socketType)
 Immediately closes and resets the socket. More...
 
quint16 localPort (SocketType socketType) const
 Gets the UDP or WebRTC local port number. More...
 
qintptr socketDescriptor (SocketType socketType) const
 Returns the native socket descriptor of the UDP or WebRTC socket. More...
 
qint64 writeDatagram (const QByteArray &datagram, const SockAddr &sockAddr)
 Sends a datagram to a network address. More...
 
qint64 bytesToWrite (SocketType socketType, const SockAddr &address=SockAddr()) const
 Gets the number of bytes waiting to be written. More...
 
bool hasPendingDatagrams () const
 Gets whether there is a pending datagram waiting to be read. More...
 
qint64 pendingDatagramSize ()
 Gets the size of the next pending datagram, alternating between socket types if both have datagrams to read. More...
 
qint64 readDatagram (char *data, qint64 maxSize, SockAddr *sockAddr=nullptr)
 Reads the next datagram per the most recent pendingDatagramSize call if made, otherwise alternating between socket types if both have datagrams to read. More...
 
QAbstractSocket::SocketState state (SocketType socketType) const
 Gets the state of the UDP or WebRTC socket. More...
 
QAbstractSocket::SocketError error (SocketType socketType) const
 Gets the type of error that last occurred. More...
 
QString errorString (SocketType socketType) const
 Gets the description of the error that last occurred. More...
 
const WebRTCSocketgetWebRTCSocket ()
 Gets a pointer to the WebRTC socket object. More...
 

Detailed Description

Multiplexes a QUdpSocket and a WebRTCSocket so that they appear as a single QUdpSocket-style socket.

Constructor & Destructor Documentation

◆ NetworkSocket()

NetworkSocket::NetworkSocket ( QObject *  parent)

Constructs a new NetworkSocket object.

Parameters
parentQt parent object.

Member Function Documentation

◆ abort()

void NetworkSocket::abort ( SocketType  socketType)

Immediately closes and resets the socket.

Parameters
socketTypeThe type of socket to close and reset.

◆ bind()

void NetworkSocket::bind ( SocketType  socketType,
const QHostAddress &  address,
quint16  port = 0 
)

Binds the UDP or WebRTC socket to an address and port.

Parameters
socketTypeThe type of socket to bind.
addressThe address to bind to.
portThe port to bind to.

◆ bytesToWrite()

qint64 NetworkSocket::bytesToWrite ( SocketType  socketType,
const SockAddr &  address = SockAddr() 
) const

Gets the number of bytes waiting to be written.

For UDP, there's a single buffer used for all destinations. For WebRTC, each destination has its own buffer.

Parameters
socketTypeThe type of socket for which to get the number of bytes waiting to be written.
addressIf a WebRTCSocket, the destination address for which to get the number of bytes waiting.
portIf a WebRTC socket, the destination port for which to get the number of bytes waiting.
Returns
The number of bytes waiting to be written.

◆ error()

QAbstractSocket::SocketError NetworkSocket::error ( SocketType  socketType) const

Gets the type of error that last occurred.

Parameters
socketTypeThe type of socket for which to get the last error.
Returns
The type of error that last occurred.

◆ errorString()

QString NetworkSocket::errorString ( SocketType  socketType) const

Gets the description of the error that last occurred.

Parameters
socketTypeThe type of socket for which to get the last error's description.
Returns
The description of the error that last occurred.

◆ getWebRTCSocket()

const WebRTCSocket * NetworkSocket::getWebRTCSocket ( )

Gets a pointer to the WebRTC socket object.

Returns
A pointer to the WebRTC socket object.

◆ hasPendingDatagrams()

bool NetworkSocket::hasPendingDatagrams ( ) const

Gets whether there is a pending datagram waiting to be read.

Returns
true if there is a datagram waiting to be read, false if there isn't.

◆ localPort()

quint16 NetworkSocket::localPort ( SocketType  socketType) const

Gets the UDP or WebRTC local port number.

Parameters
socketTypeThe type of socket for which to the get local port number.
Returns
The UDP or WebRTC local port number if available, otherwise 0.

◆ pendingDatagramSize()

qint64 NetworkSocket::pendingDatagramSize ( )

Gets the size of the next pending datagram, alternating between socket types if both have datagrams to read.

Returns
The size of the next pending datagram.

◆ readDatagram()

qint64 NetworkSocket::readDatagram ( char *  data,
qint64  maxSize,
SockAddr *  sockAddr = nullptr 
)

Reads the next datagram per the most recent pendingDatagramSize call if made, otherwise alternating between socket types if both have datagrams to read.

Parameters
dataThe destination to write the data into.
maxSizeThe maximum number of bytes to read.
sockAddrThe destination to write the source network address into.
Returns
The number of bytes if successfully read, otherwise -1.

◆ setSocketOption()

void NetworkSocket::setSocketOption ( SocketType  socketType,
QAbstractSocket::SocketOption  option,
const QVariant &  value 
)

Set the value of a UDP or WebRTC socket option.

Parameters
socketTypeThe type of socket for which to set the option value.
optionThe option to set the value of.
valueThe option value.

◆ socketDescriptor()

qintptr NetworkSocket::socketDescriptor ( SocketType  socketType) const

Returns the native socket descriptor of the UDP or WebRTC socket.

Parameters
socketTypeThe type of socket to get the socket descriptor for.
Returns
The native socket descriptor if available, otherwise -1.

◆ socketError

void NetworkSocket::socketError ( SocketType  socketType,
QAbstractSocket::SocketError  socketError 
)
signal
Parameters
socketType
socketError

◆ socketOption()

QVariant NetworkSocket::socketOption ( SocketType  socketType,
QAbstractSocket::SocketOption  option 
)

Gets the value of a UDP or WebRTC socket option.

Parameters
socketTypeThe type of socket for which to get the option value.
optionThe option to get the value of.
Returns
The option value.

◆ state()

QAbstractSocket::SocketState NetworkSocket::state ( SocketType  socketType) const

Gets the state of the UDP or WebRTC socket.

Parameters
socketTypeThe type of socket for which to get the state.
Returns
The socket state.

◆ stateChanged

void NetworkSocket::stateChanged ( SocketType  socketType,
QAbstractSocket::SocketState  socketState 
)
signal

Emitted when the state of the underlying UDP or WebRTC socket changes.

Parameters
socketTypeThe type of socket that changed state.
socketStateThe socket's new state.

◆ writeDatagram()

qint64 NetworkSocket::writeDatagram ( const QByteArray &  datagram,
const SockAddr &  sockAddr 
)

Sends a datagram to a network address.

Parameters
datagramThe datagram to send.
sockAddrThe address to send to.
Returns
The number of bytes if successfully sent, otherwise -1.

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