9 #ifndef overte_NetworkSocket_h
10 #define overte_NetworkSocket_h
15 #include <shared/WebRTC.h>
17 #include "../SockAddr.h"
18 #include "../NodeType.h"
19 #include "../SocketType.h"
20 #if defined(WEBRTC_DATA_CHANNELS)
21 #include "../webrtc/WebRTCSocket.h"
56 void bind(
SocketType socketType,
const QHostAddress& address, quint16 port = 0);
78 qint64
writeDatagram(
const QByteArray& datagram,
const SockAddr& sockAddr);
103 qint64
readDatagram(
char* data, qint64 maxSize, SockAddr* sockAddr =
nullptr);
123 #if defined(WEBRTC_DATA_CHANNELS)
146 void onUDPStateChanged(QAbstractSocket::SocketState socketState);
147 void onWebRTCStateChanged(QAbstractSocket::SocketState socketState);
149 void onUDPSocketError(QAbstractSocket::SocketError
socketError);
150 void onWebRTCSocketError(QAbstractSocket::SocketError
socketError);
156 QUdpSocket _udpSocket;
157 #if defined(WEBRTC_DATA_CHANNELS)
161 #if defined(WEBRTC_DATA_CHANNELS)
Multiplexes a QUdpSocket and a WebRTCSocket so that they appear as a single QUdpSocket-style socket.
Definition: NetworkSocket.h:29
QVariant socketOption(SocketType socketType, QAbstractSocket::SocketOption option)
Gets the value of a UDP or WebRTC socket option.
Definition: NetworkSocket.cpp:52
QString errorString(SocketType socketType) const
Gets the description of the error that last occurred.
Definition: NetworkSocket.cpp:255
void socketError(SocketType socketType, QAbstractSocket::SocketError socketError)
qint64 bytesToWrite(SocketType socketType, const SockAddr &address=SockAddr()) const
Gets the number of bytes waiting to be written.
Definition: NetworkSocket.cpp:144
quint16 localPort(SocketType socketType) const
Gets the UDP or WebRTC local port number.
Definition: NetworkSocket.cpp:98
void bind(SocketType socketType, const QHostAddress &address, quint16 port=0)
Binds the UDP or WebRTC socket to an address and port.
Definition: NetworkSocket.cpp:67
qint64 pendingDatagramSize()
Gets the size of the next pending datagram, alternating between socket types if both have datagrams t...
Definition: NetworkSocket.cpp:167
NetworkSocket(QObject *parent)
Constructs a new NetworkSocket object.
Definition: NetworkSocket.cpp:14
void abort(SocketType socketType)
Immediately closes and resets the socket.
Definition: NetworkSocket.cpp:82
QAbstractSocket::SocketState state(SocketType socketType) const
Gets the state of the UDP or WebRTC socket.
Definition: NetworkSocket.cpp:226
void setSocketOption(SocketType socketType, QAbstractSocket::SocketOption option, const QVariant &value)
Set the value of a UDP or WebRTC socket option.
bool hasPendingDatagrams() const
Gets whether there is a pending datagram waiting to be read.
Definition: NetworkSocket.cpp:159
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.
const WebRTCSocket * getWebRTCSocket()
Gets a pointer to the WebRTC socket object.
Definition: NetworkSocket.cpp:271
QAbstractSocket::SocketError error(SocketType socketType) const
Gets the type of error that last occurred.
Definition: NetworkSocket.cpp:241
qint64 readDatagram(char *data, qint64 maxSize, SockAddr *sockAddr=nullptr)
Reads the next datagram per the most recent pendingDatagramSize call if made, otherwise alternating b...
Definition: NetworkSocket.cpp:192
qint64 writeDatagram(const QByteArray &datagram, const SockAddr &sockAddr)
Sends a datagram to a network address.
Definition: NetworkSocket.cpp:128
qintptr socketDescriptor(SocketType socketType) const
Returns the native socket descriptor of the UDP or WebRTC socket.
Definition: NetworkSocket.cpp:112
Provides a QUdpSocket-style interface for using WebRTCDataChannels.
Definition: WebRTCSocket.h:31
SocketType
The types of network socket.
Definition: SocketType.h:22
@ Unknown
Socket type unknown or not set.