Banjo API 0.0.1
C99 game development API
Loading...
Searching...
No Matches
Network

Macros

#define BJ_ADDR_STRLEN   46
#define BJ_NET_BACKLOG_DEFAULT   0
#define BJ_NET_BACKLOG_MAX   (-1)

Enumerations

enum  bj_net_hints {
  BJ_NET_NOHINT = 0x0 , BJ_RESOLVE_IPV4 = 0x01 , BJ_RESOLVE_IPV6 = 0x02 , BJ_EXCLUSIVE_BIND = 0x04 ,
  BJ_TCP_DELAY_ACK = 0x08 , BJ_NONBLOCKING = 0x10 , BJ_BROADCAST = 0x20
}
enum  bj_net_shutdown { BJ_SHUTDOWN_RECEIVE = 0x01 , BJ_SHUTDOWN_SEND = 0x02 , BJ_SHUTDOWN_BOTH = 0x03 }

Functions

struct bj_tcp_listenerbj_listen_tcp (const char *host, uint16_t port, uint16_t hint, int backlog, struct bj_error **error)
struct bj_tcp_streambj_connect_tcp (const char *host, uint16_t port, uint16_t hint, uint32_t ms_timeout, struct bj_error **error)
struct bj_tcp_streambj_connect_tcp_to (struct bj_address *addr, uint16_t hints, uint32_t ms_timeout, struct bj_error **error)
struct bj_tcp_streambj_accept_tcp (struct bj_tcp_listener *listener, uint32_t ms_timeout, struct bj_error **error)
int bj_tcp_recv (struct bj_tcp_stream *stream, void *buf, size_t len)
int bj_tcp_peek (struct bj_tcp_stream *stream, void *buf, size_t len)
int bj_tcp_send (struct bj_tcp_stream *stream, const void *buf, size_t len)
void bj_tcp_shutdown (struct bj_tcp_stream *stream, int mode)
bj_bool bj_set_tcp_keepalive (struct bj_tcp_stream *stream, bj_bool enable)
bj_bool bj_get_tcp_keepalive (struct bj_tcp_stream *stream)
bj_bool bj_tcp_wait (struct bj_tcp_stream *stream, uint32_t ms_timeout)
bj_bool bj_set_tcp_recv_timeout (struct bj_tcp_stream *stream, uint32_t ms_timeout)
uint32_t bj_get_tcp_recv_timeout (struct bj_tcp_stream *stream)
bj_bool bj_set_tcp_send_timeout (struct bj_tcp_stream *stream, uint32_t ms_timeout)
uint32_t bj_get_tcp_send_timeout (struct bj_tcp_stream *stream)
void bj_close_tcp_stream (struct bj_tcp_stream *stream)
void bj_close_tcp_listener (struct bj_tcp_listener *listener)
size_t bj_tcp_peer_address (const struct bj_tcp_stream *stream, char *buf, size_t size)
size_t bj_tcp_local_address (const struct bj_tcp_stream *stream, char *buf, size_t size)
uint16_t bj_tcp_listener_port (const struct bj_tcp_listener *listener)
int bj_tcp_available (struct bj_tcp_stream *stream)

Address Resolution Functions

struct bj_addressbj_resolve_address (const char *host, uint16_t port, uint16_t hints, struct bj_error **error)
size_t bj_address_string (const struct bj_address *addr, char *buf, size_t size)
uint16_t bj_address_port (const struct bj_address *addr)
bj_bool bj_address_equals (const struct bj_address *a, const struct bj_address *b)
size_t bj_address_count (const struct bj_address *addr)
bj_bool bj_address_next (struct bj_address *addr)
void bj_address_reset (struct bj_address *addr)
void bj_free_address (struct bj_address *addr)

UDP Functions

struct bj_udpbj_open_udp (const char *host, uint16_t port, uint16_t hints, struct bj_error **error)
void bj_close_udp (struct bj_udp *udp)
int bj_udp_send (struct bj_udp *udp, const char *host, uint16_t port, const void *data, size_t len, struct bj_error **error)
int bj_udp_send_to (struct bj_udp *udp, const struct bj_address *addr, const void *data, size_t len, struct bj_error **error)
struct bj_datagrambj_udp_recv (struct bj_udp *udp, struct bj_error **error)
bj_bool bj_udp_available (struct bj_udp *udp)
bj_bool bj_udp_wait (struct bj_udp *udp, uint32_t ms_timeout)
uint16_t bj_udp_local_port (const struct bj_udp *udp)
size_t bj_udp_local_address (const struct bj_udp *udp, char *buf, size_t size)

Datagram Accessors

size_t bj_datagram_addr (const struct bj_datagram *dgram, char *buf, size_t size)
uint16_t bj_datagram_port (const struct bj_datagram *dgram)
const void * bj_datagram_data (const struct bj_datagram *dgram)
size_t bj_datagram_len (const struct bj_datagram *dgram)
void bj_close_datagram (struct bj_datagram *dgram)

Network Simulation

void bj_tcp_simulate_loss (struct bj_tcp_stream *stream, int percent)
void bj_udp_simulate_loss (struct bj_udp *udp, int percent)

Detailed Description

Basic network API.

The net API provides a thin wrapping mechanism around POSIX sockets and Winsocks for TCP network communication.

Basic Usage

// Server
struct bj_tcp_listener* listener = bj_listen_tcp(NULL, 8080, 0, 0, &error);
struct bj_tcp_stream* client = bj_accept_tcp(listener, UINT32_MAX, &error);
// Client
struct bj_tcp_stream* stream = bj_connect_tcp("localhost", 8080, 0, 5000, &error);
struct bj_tcp_listener bj_tcp_listener
Definition api.h:305
struct bj_tcp_stream bj_tcp_stream
Definition api.h:306
struct bj_tcp_stream * bj_accept_tcp(struct bj_tcp_listener *listener, uint32_t ms_timeout, struct bj_error **error)
Accepts an incoming connection on a TCP listener with timeout.
struct bj_tcp_listener * bj_listen_tcp(const char *host, uint16_t port, uint16_t hint, int backlog, struct bj_error **error)
Creates a TCP listener bound to the specified host and port.
struct bj_tcp_stream * bj_connect_tcp(const char *host, uint16_t port, uint16_t hint, uint32_t ms_timeout, struct bj_error **error)
Connects to a TCP server at the specified host and port.

Address Family Hints

Use BJ_RESOLVE_IPV4 and BJ_RESOLVE_IPV6 to control address resolution:

  • 0 or both flags: Accept any address family
  • BJ_RESOLVE_IPV4: IPv4 only
  • BJ_RESOLVE_IPV6: IPv6 only

Macro Definition Documentation

◆ BJ_ADDR_STRLEN

#define BJ_ADDR_STRLEN   46

Maximum length of an address string (including null terminator).

Sufficient for both IPv4 (e.g., "255.255.255.255") and IPv6 (e.g., "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") addresses.

◆ BJ_NET_BACKLOG_DEFAULT

#define BJ_NET_BACKLOG_DEFAULT   0

Default backlog value for bj_listen_tcp.

Uses a reasonable implementation-defined default.

◆ BJ_NET_BACKLOG_MAX

#define BJ_NET_BACKLOG_MAX   (-1)

Maximum backlog value for bj_listen_tcp.

Uses the system's maximum allowed backlog (SOMAXCONN).

Enumeration Type Documentation

◆ bj_net_hints

Hint flags for network operations.

These flags can be combined with bitwise OR to configure socket behavior.

Enumerator
BJ_NET_NOHINT 

No hint provided.

BJ_RESOLVE_IPV4 

Restrict address resolution to IPv4.

BJ_RESOLVE_IPV6 

Restrict address resolution to IPv6.

BJ_EXCLUSIVE_BIND 

Disable address reuse.

BJ_TCP_DELAY_ACK 

Enable Nagle's algorithm.

BJ_NONBLOCKING 

Non-blocking mode.

BJ_BROADCAST 

Enable UDP broadcast (SO_BROADCAST).

◆ bj_net_shutdown

Shutdown mode for bj_tcp_shutdown.

Enumerator
BJ_SHUTDOWN_RECEIVE 

Shutdown receive operations.

BJ_SHUTDOWN_SEND 

Shutdown send operations.

BJ_SHUTDOWN_BOTH 

Shutdown both send and receive.

Function Documentation

◆ bj_accept_tcp()

struct bj_tcp_stream * bj_accept_tcp ( struct bj_tcp_listener * listener,
uint32_t ms_timeout,
struct bj_error ** error )

Accepts an incoming connection on a TCP listener with timeout.

Waits for a client connection up to the specified timeout.

Parameters
listenerThe listener to accept connections on.
ms_timeoutTimeout in milliseconds. 0 = non-blocking, UINT32_MAX = infinite.
errorOptional error output. Set to BJ_ERROR_NETWORK_TIMEOUT on timeout.
Returns
A new TCP stream for the accepted connection, or NULL on timeout/failure.
See also
bj_listen_tcp To create a listener.
bj_close_tcp_stream To close the accepted connection.

◆ bj_address_count()

size_t bj_address_count ( const struct bj_address * addr)

Returns number of resolved addresses.

DNS resolution may return multiple IPs for a single hostname.

Parameters
addrThe address to query.
Returns
Number of resolved addresses.

◆ bj_address_equals()

bj_bool bj_address_equals ( const struct bj_address * a,
const struct bj_address * b )

Compares two addresses for equality.

Parameters
aFirst address.
bSecond address.
Returns
BJ_TRUE if addresses are equal.

◆ bj_address_next()

bj_bool bj_address_next ( struct bj_address * addr)

Advances to the next resolved address.

Use this to manually iterate through multiple resolved IPs for fallback on connection failure.

Parameters
addrThe address to advance.
Returns
BJ_TRUE if advanced to next, BJ_FALSE if no more addresses.

◆ bj_address_port()

uint16_t bj_address_port ( const struct bj_address * addr)

Gets the port from a resolved address.

Parameters
addrThe address to query.
Returns
Port number in host byte order.

◆ bj_address_reset()

void bj_address_reset ( struct bj_address * addr)

Resets address iteration to the first resolved address.

Parameters
addrThe address to reset.

◆ bj_address_string()

size_t bj_address_string ( const struct bj_address * addr,
char * buf,
size_t size )

Gets the IP address string from a resolved address.

Parameters
addrThe address to query.
bufBuffer to store the string. May be NULL to query length.
sizeBuffer size.
Returns
Length of address string, or 0 on error.

◆ bj_close_datagram()

void bj_close_datagram ( struct bj_datagram * dgram)

Closes a datagram and frees resources.

NULL-safe.

Parameters
dgramThe datagram to close. May be NULL.

◆ bj_close_tcp_listener()

void bj_close_tcp_listener ( struct bj_tcp_listener * listener)

Closes a TCP listener and releases associated resources.

Safe to call with NULL.

Parameters
listenerThe TCP listener to close. May be NULL.

◆ bj_close_tcp_stream()

void bj_close_tcp_stream ( struct bj_tcp_stream * stream)

Closes a TCP stream and releases associated resources.

Safe to call with NULL.

Parameters
streamThe TCP stream to close. May be NULL.

◆ bj_close_udp()

void bj_close_udp ( struct bj_udp * udp)

Closes a UDP socket.

NULL-safe.

Parameters
udpThe UDP socket to close. May be NULL.

◆ bj_connect_tcp()

struct bj_tcp_stream * bj_connect_tcp ( const char * host,
uint16_t port,
uint16_t hint,
uint32_t ms_timeout,
struct bj_error ** error )

Connects to a TCP server at the specified host and port.

Resolves the hostname and attempts to connect. If multiple addresses are returned by DNS, each is tried until one succeeds.

Parameters
hostHostname or IP address to connect to.
portPort number to connect to.
hintAddress family hint. Use 0 for any, BJ_RESOLVE_IPV4 for IPv4 only, or BJ_RESOLVE_IPV6 for IPv6 only.
ms_timeoutAttempt timeout in milliseconds (0 = infinite)
errorOptional error output. May be NULL.
Returns
A new TCP stream, or NULL on failure.
See also
bj_tcp_send To send data.
bj_tcp_recv To receive data.
bj_close_tcp_stream To close the connection.

◆ bj_connect_tcp_to()

struct bj_tcp_stream * bj_connect_tcp_to ( struct bj_address * addr,
uint16_t hints,
uint32_t ms_timeout,
struct bj_error ** error )

Connects to a pre-resolved address, trying all resolved IPs.

Automatically iterates through all addresses returned by DNS resolution until one succeeds.

Parameters
addrDestination address (from bj_resolve_address).
hintsSocket hints (BJ_TCP_DELAY_ACK, etc.).
ms_timeoutConnection timeout per address in milliseconds.
errorOptional error output.
Returns
TCP stream, or NULL on failure.
See also
bj_resolve_address To create the address.
bj_connect_tcp For hostname-based connection.

◆ bj_datagram_addr()

size_t bj_datagram_addr ( const struct bj_datagram * dgram,
char * buf,
size_t size )

Gets the sender's address from a datagram.

Parameters
dgramDatagram.
bufOutput buffer (may be NULL to query length).
sizeBuffer size.
Returns
Address string length, or 0 on error.

◆ bj_datagram_data()

const void * bj_datagram_data ( const struct bj_datagram * dgram)

Gets the data pointer from a datagram.

Parameters
dgramDatagram.
Returns
Pointer to data, or NULL on error.

◆ bj_datagram_len()

size_t bj_datagram_len ( const struct bj_datagram * dgram)

Gets the data length from a datagram.

Parameters
dgramDatagram.
Returns
Data length, or 0 on error.

◆ bj_datagram_port()

uint16_t bj_datagram_port ( const struct bj_datagram * dgram)

Gets the sender's port from a datagram.

Parameters
dgramDatagram.
Returns
Sender port, or 0 on error.

◆ bj_free_address()

void bj_free_address ( struct bj_address * addr)

Frees a resolved address.

NULL-safe.

Parameters
addrThe address to free. May be NULL.

◆ bj_get_tcp_keepalive()

bj_bool bj_get_tcp_keepalive ( struct bj_tcp_stream * stream)

Gets the current TCP keep-alive setting.

Parameters
streamTCP stream.
Returns
BJ_TRUE if keep-alive is enabled, BJ_FALSE otherwise.

◆ bj_get_tcp_recv_timeout()

uint32_t bj_get_tcp_recv_timeout ( struct bj_tcp_stream * stream)

Gets the current receive timeout.

Parameters
streamTCP stream.
Returns
Timeout in milliseconds, or 0 if no timeout set.

◆ bj_get_tcp_send_timeout()

uint32_t bj_get_tcp_send_timeout ( struct bj_tcp_stream * stream)

Gets the current send timeout.

Parameters
streamTCP stream.
Returns
Timeout in milliseconds, or 0 if no timeout set.

◆ bj_listen_tcp()

struct bj_tcp_listener * bj_listen_tcp ( const char * host,
uint16_t port,
uint16_t hint,
int backlog,
struct bj_error ** error )

Creates a TCP listener bound to the specified host and port.

The listener accepts incoming TCP connections via bj_accept_tcp.

Parameters
hostHostname or IP address to bind to. Pass NULL to bind to all interfaces.
portPort number to listen on.
hintAddress family hint. Use 0 for any, BJ_RESOLVE_IPV4 for IPv4 only, or BJ_RESOLVE_IPV6 for IPv6 only.
backlogMaximum pending connections queue size. Use BJ_NET_BACKLOG_DEFAULT for a reasonable default, or BJ_NET_BACKLOG_MAX for the system maximum.
errorOptional error output. May be NULL.
Returns
A new TCP listener, or NULL on failure.
See also
bj_accept_tcp To accept incoming connections.
bj_close_tcp_listener To close the listener.

◆ bj_open_udp()

struct bj_udp * bj_open_udp ( const char * host,
uint16_t port,
uint16_t hints,
struct bj_error ** error )

Opens a UDP socket bound to the specified port.

Parameters
hostHostname/IP to bind to. NULL for any interface.
portPort to bind. 0 for ephemeral (system-assigned).
hintsFlags: BJ_RESOLVE_IPV4, BJ_RESOLVE_IPV6, BJ_NONBLOCKING, BJ_BROADCAST
errorOptional error output.
Returns
New UDP socket, or NULL on failure.

◆ bj_resolve_address()

struct bj_address * bj_resolve_address ( const char * host,
uint16_t port,
uint16_t hints,
struct bj_error ** error )

Resolves a hostname to a network address.

The returned address can be used with bj_connect_tcp_to and bj_udp_send_to to avoid repeated DNS lookups.

Parameters
hostHostname or IP string to resolve.
portPort number.
hintsBJ_RESOLVE_IPV4, BJ_RESOLVE_IPV6, or 0 for any.
errorOptional error output.
Returns
Resolved address, or NULL on failure.
See also
bj_free_address To free the address.
bj_address_next To iterate through multiple resolved IPs.

◆ bj_set_tcp_keepalive()

bj_bool bj_set_tcp_keepalive ( struct bj_tcp_stream * stream,
bj_bool enable )

Enables or disables TCP keep-alive probes.

When enabled, the OS sends periodic probes on idle connections to detect dead peers. If no response is received, the connection is terminated.

Parameters
streamTCP stream.
enableBJ_TRUE to enable, BJ_FALSE to disable.
Returns
BJ_TRUE on success.
Note
Keep-alive timing is controlled by the implementation.

◆ bj_set_tcp_recv_timeout()

bj_bool bj_set_tcp_recv_timeout ( struct bj_tcp_stream * stream,
uint32_t ms_timeout )

Sets the receive timeout for a TCP stream.

When set, recv operations will timeout after the specified duration.

Parameters
streamTCP stream.
ms_timeoutTimeout in milliseconds. 0 = no timeout (blocking).
Returns
BJ_TRUE on success.

◆ bj_set_tcp_send_timeout()

bj_bool bj_set_tcp_send_timeout ( struct bj_tcp_stream * stream,
uint32_t ms_timeout )

Sets the send timeout for a TCP stream.

When set, send operations will timeout after the specified duration.

Parameters
streamTCP stream.
ms_timeoutTimeout in milliseconds. 0 = no timeout (blocking).
Returns
BJ_TRUE on success.

◆ bj_tcp_available()

int bj_tcp_available ( struct bj_tcp_stream * stream)

Checks bytes available to read without blocking.

Parameters
streamTCP stream.
Returns
Bytes available (>=0), or -1 on error/closed connection.

◆ bj_tcp_listener_port()

uint16_t bj_tcp_listener_port ( const struct bj_tcp_listener * listener)

Get the listening port of the given server.

Parameters
listenerThe listener to get the local port from.
Returns
Listener port number

Will return 0 if listener is 0 or closed.

◆ bj_tcp_local_address()

size_t bj_tcp_local_address ( const struct bj_tcp_stream * stream,
char * buf,
size_t size )

Gets the local address of a TCP stream.

Writes the local IP address as a string into buf. Works like snprintf: returns the length of the address string regardless of buffer size.

Parameters
streamThe TCP stream to query.
bufBuffer to store the address string. May be NULL to query length only.
sizeSize of the buffer in bytes.
Returns
Length of the address string (excluding null terminator), or 0 on error. If the return value is >= size, the output was truncated.
See also
BJ_ADDR_STRLEN For the recommended buffer size.
bj_tcp_peer_address To get the remote address.

◆ bj_tcp_peek()

int bj_tcp_peek ( struct bj_tcp_stream * stream,
void * buf,
size_t len )

Peek at incoming data without consuming it.

Like bj_tcp_recv but data remains in the buffer for subsequent reads. Useful for protocol parsing where you need to inspect headers.

Parameters
streamThe TCP stream to peek from.
bufBuffer to store peeked data.
lenMaximum number of bytes to peek.
Returns
Number of bytes peeked, 0 if connection closed, or -1 on error.
See also
bj_tcp_recv

◆ bj_tcp_peer_address()

size_t bj_tcp_peer_address ( const struct bj_tcp_stream * stream,
char * buf,
size_t size )

Gets the remote address of a TCP stream.

Writes the peer's IP address as a string into buf. Works like snprintf: returns the length of the address string regardless of buffer size.

Parameters
streamThe TCP stream to query.
bufBuffer to store the address string. May be NULL to query length only.
sizeSize of the buffer in bytes.
Returns
Length of the address string (excluding null terminator), or 0 on error. If the return value is >= size, the output was truncated.
See also
BJ_ADDR_STRLEN For the recommended buffer size.
bj_tcp_local_address To get the local address.

◆ bj_tcp_recv()

int bj_tcp_recv ( struct bj_tcp_stream * stream,
void * buf,
size_t len )

Receives data from a TCP stream.

Reads up to len bytes from the stream into buf. Blocks until data is available or the connection is closed.

Parameters
streamThe TCP stream to receive from.
bufBuffer to store received data.
lenMaximum number of bytes to receive.
Returns
Number of bytes received, 0 if connection closed, or -1 on error.
See also
bj_tcp_peek

◆ bj_tcp_send()

int bj_tcp_send ( struct bj_tcp_stream * stream,
const void * buf,
size_t len )

Sends data over a TCP stream.

Sends up to len bytes from buf over the stream.

Parameters
streamThe TCP stream to send on.
bufBuffer containing data to send.
lenNumber of bytes to send.
Returns
Number of bytes sent, or -1 on error.

◆ bj_tcp_shutdown()

void bj_tcp_shutdown ( struct bj_tcp_stream * stream,
int mode )

Shuts down part or all of a TCP connection.

Gracefully shuts down the send and/or receive side of the connection without closing the socket.

Parameters
streamThe TCP stream to shutdown.
modeShutdown mode: BJ_SHUTDOWN_RECEIVE, BJ_SHUTDOWN_SEND, or BJ_SHUTDOWN_BOTH.
See also
bj_close_tcp_stream To fully close the connection.

◆ bj_tcp_simulate_loss()

void bj_tcp_simulate_loss ( struct bj_tcp_stream * stream,
int percent )

Simulates packet loss on a TCP stream.

Parameters
streamTCP stream.
percentLoss percentage (0-100). 0 disables simulation.

◆ bj_tcp_wait()

bj_bool bj_tcp_wait ( struct bj_tcp_stream * stream,
uint32_t ms_timeout )

Waits for data to become available on a TCP stream.

Uses select() internally to wait for readability with a timeout.

Parameters
streamTCP stream to wait on.
ms_timeoutTimeout in milliseconds. 0 = non-blocking poll.
Returns
BJ_TRUE if data available, BJ_FALSE on timeout.

◆ bj_udp_available()

bj_bool bj_udp_available ( struct bj_udp * udp)

Checks if a datagram is available without blocking.

Parameters
udpUDP socket.
Returns
BJ_TRUE if data available, BJ_FALSE otherwise.

◆ bj_udp_local_address()

size_t bj_udp_local_address ( const struct bj_udp * udp,
char * buf,
size_t size )

Gets the local address of a UDP socket (snprintf-style).

Parameters
udpUDP socket.
bufOutput buffer (may be NULL to query length).
sizeBuffer size.
Returns
Address string length, or 0 on error.

◆ bj_udp_local_port()

uint16_t bj_udp_local_port ( const struct bj_udp * udp)

Gets the local port of a UDP socket.

Parameters
udpUDP socket.
Returns
Local port, or 0 on error.

◆ bj_udp_recv()

struct bj_datagram * bj_udp_recv ( struct bj_udp * udp,
struct bj_error ** error )

Receives a datagram from the UDP socket.

If BJ_NONBLOCKING was set and no data available, returns NULL without error. If blocking, waits until a datagram arrives.

Parameters
udpUDP socket.
errorOptional error output.
Returns
Received datagram (caller must close), or NULL if no data/error. Check error to distinguish: NULL + no error = no data available.

◆ bj_udp_send()

int bj_udp_send ( struct bj_udp * udp,
const char * host,
uint16_t port,
const void * data,
size_t len,
struct bj_error ** error )

Sends a datagram to the specified destination.

Resolves hostname internally on each call.

Parameters
udpUDP socket.
hostDestination hostname or IP.
portDestination port.
dataData to send.
lenData length.
errorOptional error output.
Returns
Bytes sent, or -1 on error.

◆ bj_udp_send_to()

int bj_udp_send_to ( struct bj_udp * udp,
const struct bj_address * addr,
const void * data,
size_t len,
struct bj_error ** error )

Sends a datagram to a pre-resolved address (no DNS lookup).

More efficient than bj_udp_send when sending many packets to the same destination, as it avoids repeated DNS lookups.

Parameters
udpUDP socket.
addrDestination address (from bj_resolve_address).
dataData to send.
lenData length.
errorOptional error output.
Returns
Bytes sent, or -1 on error.
See also
bj_resolve_address To create the address.
bj_udp_send For hostname-based sending.

◆ bj_udp_simulate_loss()

void bj_udp_simulate_loss ( struct bj_udp * udp,
int percent )

Simulates packet loss on a UDP socket.

Parameters
udpUDP socket.
percentLoss percentage (0-100). 0 disables simulation.

◆ bj_udp_wait()

bj_bool bj_udp_wait ( struct bj_udp * udp,
uint32_t ms_timeout )

Waits for data to become available on a UDP socket.

Uses select() internally to wait for readability with a timeout.

Parameters
udpUDP socket.
ms_timeoutTimeout in milliseconds. 0 = non-blocking poll.
Returns
BJ_TRUE if data available, BJ_FALSE on timeout.