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 WebRTCSocket * | getWebRTCSocket () |
| Gets a pointer to the WebRTC socket object. More... | |
Multiplexes a QUdpSocket and a WebRTCSocket so that they appear as a single QUdpSocket-style socket.
| NetworkSocket::NetworkSocket | ( | QObject * | parent | ) |
Constructs a new NetworkSocket object.
| parent | Qt parent object. |
| void NetworkSocket::abort | ( | SocketType | socketType | ) |
Immediately closes and resets the socket.
| socketType | The type of socket to close and reset. |
| void NetworkSocket::bind | ( | SocketType | socketType, |
| const QHostAddress & | address, | ||
| quint16 | port = 0 |
||
| ) |
Binds the UDP or WebRTC socket to an address and port.
| socketType | The type of socket to bind. |
| address | The address to bind to. |
| port | The port to bind to. |
| 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.
| socketType | The type of socket for which to get the number of bytes waiting to be written. |
| address | If a WebRTCSocket, the destination address for which to get the number of bytes waiting. |
| port | If a WebRTC socket, the destination port for which to get the number of bytes waiting. |
| QAbstractSocket::SocketError NetworkSocket::error | ( | SocketType | socketType | ) | const |
Gets the type of error that last occurred.
| socketType | The type of socket for which to get the last error. |
| QString NetworkSocket::errorString | ( | SocketType | socketType | ) | const |
Gets the description of the error that last occurred.
| socketType | The type of socket for which to get the last error's description. |
| const WebRTCSocket * NetworkSocket::getWebRTCSocket | ( | ) |
Gets a pointer to the WebRTC socket object.
| bool NetworkSocket::hasPendingDatagrams | ( | ) | const |
Gets whether there is a pending datagram waiting to be read.
true if there is a datagram waiting to be read, false if there isn't. | quint16 NetworkSocket::localPort | ( | SocketType | socketType | ) | const |
Gets the UDP or WebRTC local port number.
| socketType | The type of socket for which to the get local port number. |
0. | qint64 NetworkSocket::pendingDatagramSize | ( | ) |
Gets the size of the next pending datagram, alternating between socket types if both have datagrams to read.
| 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.
| data | The destination to write the data into. |
| maxSize | The maximum number of bytes to read. |
| sockAddr | The destination to write the source network address into. |
-1. | void NetworkSocket::setSocketOption | ( | SocketType | socketType, |
| QAbstractSocket::SocketOption | option, | ||
| const QVariant & | value | ||
| ) |
Set the value of a UDP or WebRTC socket option.
| socketType | The type of socket for which to set the option value. |
| option | The option to set the value of. |
| value | The option value. |
| qintptr NetworkSocket::socketDescriptor | ( | SocketType | socketType | ) | const |
Returns the native socket descriptor of the UDP or WebRTC socket.
| socketType | The type of socket to get the socket descriptor for. |
-1.
|
signal |
| socketType | |
| socketError |
| QVariant NetworkSocket::socketOption | ( | SocketType | socketType, |
| QAbstractSocket::SocketOption | option | ||
| ) |
Gets the value of a UDP or WebRTC socket option.
| socketType | The type of socket for which to get the option value. |
| option | The option to get the value of. |
| QAbstractSocket::SocketState NetworkSocket::state | ( | SocketType | socketType | ) | const |
Gets the state of the UDP or WebRTC socket.
| socketType | The type of socket for which to get the state. |
|
signal |
Emitted when the state of the underlying UDP or WebRTC socket changes.
| socketType | The type of socket that changed state. |
| socketState | The socket's new state. |
| qint64 NetworkSocket::writeDatagram | ( | const QByteArray & | datagram, |
| const SockAddr & | sockAddr | ||
| ) |
Sends a datagram to a network address.
| datagram | The datagram to send. |
| sockAddr | The address to send to. |
-1.