![]() |
NDEVR
API Documentation
|
A core ConnectionBackend for QAbstractSocket supporting TCP and UDP connections. More...
Public Member Functions | |
| SocketConnection (LogPtr log) | |
| Constructs a SocketConnection with the given log for diagnostics. | |
| virtual uint04 | bytesAvailable () const override |
| Returns the number of bytes available for reading from the socket. | |
| virtual void | close () final override |
| Closes the socket connection and releases associated resources. | |
| virtual bool | isOpen () const final override |
| Checks whether the socket connection is currently open. | |
| virtual TranslatedString | lastError () const final override |
| Returns a translated description of the last socket error encountered. | |
| virtual bool | open (const ConnectionInfo &request) final override |
| Opens a socket connection using the given connection info (TCP or UDP). | |
| bool | openTCP (const ConnectionInfo &request) |
| Opens a TCP connection using the given connection info. | |
| bool | openUDP (const ConnectionInfo &request) |
| Opens a UDP client connection using the given connection info. | |
| bool | openUDPServer (const ConnectionInfo &request) |
| Opens a UDP server (broadcast listener) using the given connection info. | |
| virtual uint04 | peek (char *, uint04 size) const final override |
| Peeks at incoming data without consuming it from the socket buffer. | |
| virtual uint04 | rx (char *, uint04 size=Constant< uint04 >::Max) final override |
| Reads (receives) data from the socket. | |
| void | setSocket (QAbstractSocket *socket) |
| Replaces the internal socket with the given QAbstractSocket. | |
| virtual bool | setTCPPort (QTcpSocket *tcp_port, ConnectionOpenType connect_mode) |
| Assigns an existing QTcpSocket to this connection. | |
| virtual bool | setUDPPort (QUdpSocket *udp_port, ConnectionOpenType connect_mode) |
| Assigns an existing QUdpSocket to this connection. | |
| virtual void | tx (const StringView &command) final override |
| Transmits the given command string over the socket. | |
| void | txInThread (const StringView &data) |
| Transmits data over the socket from a worker thread context. | |
| virtual bool | waitForConnection (QAbstractSocket *socket, const ConnectionInfo &request) |
| Blocks until the socket establishes a connection or the request times out. | |
| virtual bool | waitForReadyRead (const TimeSpan &span) final override |
| Blocks until data is available to read or the given timeout elapses. | |
| Public Member Functions inherited from ConnectionBackend | |
| ConnectionBackend (LogPtr log) | |
| Constructs a ConnectionBackend with the given log. | |
| void | connectionStateChangedSignal (ConnectionState state) |
| Emitted when the connection state changes. | |
| void | dataAvailableSignal () |
| Emitted when data is available to be read from the connection. | |
| virtual String | threadID () const |
| Returns the thread ID this backend must execute on, if any. | |
Protected Member Functions | |
| void | handleSocketErrorSlot (int error) |
| Slot that handles socket error signals and stores the error description. | |
Protected Attributes | |
| uint02 | m_broadcast_port = Constant<uint02>::Invalid |
| The UDP broadcast port, or Invalid if not broadcasting. | |
| QHostAddress | m_host_address |
| The resolved host address for the connection. | |
| TranslatedString | m_last_error |
| The last error message from the socket. | |
| QAbstractSocket * | m_socket = nullptr |
| The underlying Qt socket (TCP or UDP). | |
| Protected Attributes inherited from ConnectionBackend | |
| LogPtr | m_log |
| Log for diagnostic messages. | |
A core ConnectionBackend for QAbstractSocket supporting TCP and UDP connections.
Definition at line 16 of file SocketConnection.h.
| SocketConnection::SocketConnection | ( | LogPtr | log | ) |
Constructs a SocketConnection with the given log for diagnostics.
| [in] | log | The log pipe for recording connection events and errors. |
References SocketConnection().
Referenced by SocketConnection().
|
overridevirtual |
Returns the number of bytes available for reading from the socket.
Implements ConnectionBackend.
References bytesAvailable().
Referenced by bytesAvailable().
|
protected |
Slot that handles socket error signals and stores the error description.
| [in] | error | The socket error code. |
References handleSocketErrorSlot().
Referenced by handleSocketErrorSlot().
|
finaloverridevirtual |
Checks whether the socket connection is currently open.
Implements ConnectionBackend.
References isOpen().
Referenced by isOpen().
|
finaloverridevirtual |
Returns a translated description of the last socket error encountered.
Implements ConnectionBackend.
References lastError().
Referenced by lastError().
|
finaloverridevirtual |
Opens a socket connection using the given connection info (TCP or UDP).
| [in] | request | The connection parameters specifying address, port, and protocol. |
Implements ConnectionBackend.
| bool SocketConnection::openTCP | ( | const ConnectionInfo & | request | ) |
| bool SocketConnection::openUDP | ( | const ConnectionInfo & | request | ) |
| bool SocketConnection::openUDPServer | ( | const ConnectionInfo & | request | ) |
Opens a UDP server (broadcast listener) using the given connection info.
| [in] | request | The connection parameters. |
References openUDPServer().
Referenced by openUDPServer().
Peeks at incoming data without consuming it from the socket buffer.
| [in] | size | The maximum number of bytes to peek. |
Implements ConnectionBackend.
|
finaloverridevirtual |
Reads (receives) data from the socket.
| [in] | size | The maximum number of bytes to read. |
Implements ConnectionBackend.
| void SocketConnection::setSocket | ( | QAbstractSocket * | socket | ) |
Replaces the internal socket with the given QAbstractSocket.
| [in] | socket | The new socket to use for this connection. |
References setSocket().
Referenced by setSocket().
|
virtual |
Assigns an existing QTcpSocket to this connection.
| [in] | tcp_port | The TCP socket to use. |
| [in] | connect_mode | The open mode (read, write, or both). |
References setTCPPort().
Referenced by setTCPPort().
|
virtual |
Assigns an existing QUdpSocket to this connection.
| [in] | udp_port | The UDP socket to use. |
| [in] | connect_mode | The open mode (read, write, or both). |
References setUDPPort().
Referenced by setUDPPort().
|
finaloverridevirtual |
Transmits the given command string over the socket.
| [in] | command | The data to send. |
Implements ConnectionBackend.
| void SocketConnection::txInThread | ( | const StringView & | data | ) |
Transmits data over the socket from a worker thread context.
| [in] | data | The data to send. |
|
virtual |
Blocks until the socket establishes a connection or the request times out.
| [in] | socket | The abstract socket to wait on. |
| [in] | request | The connection info containing timeout parameters. |
References waitForConnection().
Referenced by waitForConnection().
|
finaloverridevirtual |
Blocks until data is available to read or the given timeout elapses.
| [in] | span | The maximum time to wait. |
Implements ConnectionBackend.
References waitForReadyRead().
Referenced by waitForReadyRead().