A thread-safe queue.
More...
#include <network.h>
|
void | enqueue (const udp::packet &in) |
| Enqueue a packet.
|
|
udp::packet | pop (const tag type=NONE, const size_t &iterations=-1) |
| Remove the first packet of the type byte.
|
|
udp::packet | pop (const std::vector< uint8_t > &types, const size_t &iterations=-1) |
| Pop with multiple valid types.
|
|
bool | empty () |
| Check if the queue is empty.
|
|
size_t | size () |
| Get the current size of the queue.
|
|
void | flush () |
| Flush the queue.
|
|
◆ empty()
bool network::queue::empty |
( |
| ) |
|
|
inline |
Check if the queue is empty.
- Returns
- Whether the queue is empty.
◆ enqueue()
Enqueue a packet.
- Parameters
-
- Warning
- This function is blocking.
◆ flush()
void network::queue::flush |
( |
| ) |
|
|
inline |
Flush the queue.
- Warning
- Any messages in the queue will be dropped!
-
This function is blocking.
◆ pop() [1/2]
udp::packet network::queue::pop |
( |
const std::vector< uint8_t > & | types, |
|
|
const size_t & | iterations = -1 ) |
|
inline |
Pop with multiple valid types.
- Parameters
-
types | A list of types to search for. |
iterations | The iteration count |
- Returns
- The first matching packet.
◆ pop() [2/2]
udp::packet network::queue::pop |
( |
const tag | type = NONE, |
|
|
const size_t & | iterations = -1 ) |
|
inline |
Remove the first packet of the type byte.
- Parameters
-
type | The type to search for: NONE for any packet. |
iterations | How many times to check before failing. Defaults to -1 IE SIZE_MAX IE forever. |
- Returns
- The first matching packet.
◆ size()
size_t network::queue::size |
( |
| ) |
|
|
inline |
Get the current size of the queue.
- Returns
- The size.
◆ thread
The Network Thread.
- Parameters
-
port | The port to bind to: 0 = randomized. |
wg | An optional WireGuard configuration. |
Send a packet across a FD.
- Parameters
-
p | The packet to send. |
fd | The FD to send across. |
- Exceptions
-
runtime_error | If the packet failed to send. |
Open a socket at the specified port.
- Parameters
-
- Returns
- The socket FD.
- Warning
- This function can teardown the thread if the socket cannot be initialized.
Establish a new connection.
- Parameters
-
- Returns
- The FD of the connection.
Cleanup the thread.
Wait for a connection of a specific type.
- Parameters
-
fd | The FD to listen on. |
tag | The tag at the start of the packet data. |
- Returns
- The UDP packet.
The documentation for this class was generated from the following file: