213#define BJ_ADDR_STRLEN 46
220#define BJ_NET_BACKLOG_DEFAULT 0
227#define BJ_NET_BACKLOG_MAX (-1)
787#if defined(BJ_BUILD_DEBUG) || defined(BJ_CONFIG_NET_SIMULATION)
General-purpose definitions for Banjo API.
bj_audio_play_note_data data
Definition audio_pcm.c:22
Recoverable error handling.
struct bj_datagram bj_datagram
Definition api.h:308
struct bj_address bj_address
Definition api.h:304
struct bj_error bj_error
Definition api.h:282
#define BANJO_EXPORT
Definition api.h:113
struct bj_udp bj_udp
Definition api.h:307
uint32_t bj_bool
Boolean type used throughout the Banjo API.
Definition api.h:207
struct bj_tcp_listener bj_tcp_listener
Definition api.h:305
struct bj_tcp_stream bj_tcp_stream
Definition api.h:306
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.
size_t bj_datagram_addr(const struct bj_datagram *dgram, char *buf, size_t size)
Gets the sender's address from a datagram.
bj_bool bj_address_next(struct bj_address *addr)
Advances to the next resolved address.
bj_bool bj_address_equals(const struct bj_address *a, const struct bj_address *b)
Compares two addresses for equality.
uint16_t bj_tcp_listener_port(const struct bj_tcp_listener *listener)
Get the listening port of the given server.
void bj_close_datagram(struct bj_datagram *dgram)
Closes a datagram and frees resources.
int bj_tcp_recv(struct bj_tcp_stream *stream, void *buf, size_t len)
Receives data from a TCP stream.
uint32_t bj_get_tcp_recv_timeout(struct bj_tcp_stream *stream)
Gets the current receive timeout.
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.
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.
uint16_t bj_datagram_port(const struct bj_datagram *dgram)
Gets the sender's port from a datagram.
size_t bj_datagram_len(const struct bj_datagram *dgram)
Gets the data length from a datagram.
bj_bool bj_set_tcp_send_timeout(struct bj_tcp_stream *stream, uint32_t ms_timeout)
Sets the send timeout for a TCP stream.
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.
bj_bool bj_set_tcp_keepalive(struct bj_tcp_stream *stream, bj_bool enable)
Enables or disables TCP keep-alive probes.
bj_bool bj_get_tcp_keepalive(struct bj_tcp_stream *stream)
Gets the current TCP keep-alive setting.
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.
bj_bool bj_set_tcp_recv_timeout(struct bj_tcp_stream *stream, uint32_t ms_timeout)
Sets the receive timeout for a TCP stream.
void bj_free_address(struct bj_address *addr)
Frees a resolved address.
void bj_close_tcp_stream(struct bj_tcp_stream *stream)
Closes a TCP stream and releases associated resources.
int bj_tcp_available(struct bj_tcp_stream *stream)
Checks bytes available to read without blocking.
bj_net_hints
Hint flags for network operations.
Definition net.h:84
size_t bj_address_count(const struct bj_address *addr)
Returns number of resolved addresses.
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.
uint16_t bj_udp_local_port(const struct bj_udp *udp)
Gets the local port of a UDP socket.
size_t bj_address_string(const struct bj_address *addr, char *buf, size_t size)
Gets the IP address string from a resolved address.
void bj_udp_simulate_loss(struct bj_udp *udp, int percent)
Simulates packet loss on a UDP socket.
int bj_tcp_peek(struct bj_tcp_stream *stream, void *buf, size_t len)
Peek at incoming data without consuming it.
void bj_address_reset(struct bj_address *addr)
Resets address iteration to the first resolved address.
uint32_t bj_get_tcp_send_timeout(struct bj_tcp_stream *stream)
Gets the current send timeout.
void bj_tcp_shutdown(struct bj_tcp_stream *stream, int mode)
Shuts down part or all of a TCP connection.
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.
void bj_close_tcp_listener(struct bj_tcp_listener *listener)
Closes a TCP listener and releases associated resources.
uint16_t bj_address_port(const struct bj_address *addr)
Gets the port from a resolved address.
int bj_tcp_send(struct bj_tcp_stream *stream, const void *buf, size_t len)
Sends data over a TCP stream.
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.
void bj_tcp_simulate_loss(struct bj_tcp_stream *stream, int percent)
Simulates packet loss on a TCP stream.
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).
bj_bool bj_udp_available(struct bj_udp *udp)
Checks if a datagram is available without blocking.
bj_net_shutdown
Shutdown mode for bj_tcp_shutdown.
Definition net.h:201
struct bj_datagram * bj_udp_recv(struct bj_udp *udp, struct bj_error **error)
Receives a datagram from the UDP socket.
bj_bool bj_tcp_wait(struct bj_tcp_stream *stream, uint32_t ms_timeout)
Waits for data to become available on a TCP stream.
void bj_close_udp(struct bj_udp *udp)
Closes a UDP socket.
const void * bj_datagram_data(const struct bj_datagram *dgram)
Gets the data pointer from a datagram.
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).
bj_bool bj_udp_wait(struct bj_udp *udp, uint32_t ms_timeout)
Waits for data to become available on a UDP socket.
@ BJ_NET_NOHINT
No hint provided.
Definition net.h:85
@ BJ_NONBLOCKING
Non-blocking mode.
Definition net.h:90
@ BJ_RESOLVE_IPV4
Restrict address resolution to IPv4.
Definition net.h:86
@ BJ_EXCLUSIVE_BIND
Disable address reuse.
Definition net.h:88
@ BJ_BROADCAST
Enable UDP broadcast (SO_BROADCAST).
Definition net.h:91
@ BJ_TCP_DELAY_ACK
Enable Nagle's algorithm.
Definition net.h:89
@ BJ_RESOLVE_IPV6
Restrict address resolution to IPv6.
Definition net.h:87
@ BJ_SHUTDOWN_SEND
Shutdown send operations.
Definition net.h:203
@ BJ_SHUTDOWN_RECEIVE
Shutdown receive operations.
Definition net.h:202
@ BJ_SHUTDOWN_BOTH
Shutdown both send and receive.
Definition net.h:204