net.h(3)Bark

NAME

net.h - Bark asynchronous HTTPS and WebSocket client primitives.

SYNOPSIS

Classes

struct bark_net_cbs

Main-thread network event callbacks dispatched by bark_net_poll().

Typedefs

typedef struct bark_net bark_net_t

Opaque network manager handle (shared cookie jar + event queue).

typedef struct bark_ws bark_ws_t

Opaque WebSocket connection handle.

typedef enum bark_ws_state bark_ws_state_t

Lifecycle states of a WebSocket connection.

typedef struct bark_net_cbs bark_net_cbs_t

Main-thread network event callbacks dispatched by bark_net_poll().

typedef void(* bark_http_resp_fn) (void *user, int status, const uint8_t *body, size_t len, const char *content_type)

Per-request HTTP response callback dispatched on the main thread inside bark_net_poll().

typedef int(* bark_http_chunk_fn) (void *user, const uint8_t *data, size_t len, uint64_t received, uint64_t total)

Streaming download chunk callback; return non-zero to abort with BARK_ERR_CANCELED.

typedef int(* bark_http_cancel_fn) (void *user)

Cooperative cancellation probe polled during bark_http_download().

Enumerations

enum bark_ws_state { BARK_WS_CLOSED = 0, BARK_WS_CONNECTING = 1, BARK_WS_OPEN = 2, BARK_WS_CLOSING = 3 }

Lifecycle states of a WebSocket connection.

Functions

bark_net_t * bark_net_create (const bark_net_cbs_t *cbs, void *user)

Create a network manager handle.

int bark_net_poll (bark_net_t *net, int timeout_ms)

Pump network I/O and dispatch completed HTTP and WebSocket callbacks.

void bark_net_destroy (bark_net_t *net)

Destroy a network manager handle and close active connections.

bark_ws_t * bark_ws_open (bark_net_t *net, const char *url, const char *cookie_opt)

Open a ws:// or wss:// WebSocket connection (with optional Cookie header).

int bark_ws_send_text (bark_ws_t *ws, const char *text, size_t len)

Send a UTF-8 text frame over an open WebSocket.

int bark_ws_send_bin (bark_ws_t *ws, const uint8_t *bytes, size_t len)

Send a binary frame over an open WebSocket.

int bark_ws_status (const bark_ws_t *ws)

Query the current bark_ws_state_t of ws.

void bark_ws_close (bark_ws_t *ws, int code, const char *reason)

Initiate a graceful WebSocket close with code and optional reason.

int bark_http_get (bark_net_t *net, uint32_t req_id, const char *url, const char *headers_nl)

Issue an asynchronous HTTP(S) GET; response is delivered to on_http_resp with req_id.

int bark_http_post (bark_net_t *net, uint32_t req_id, const char *url, const char *headers_nl, const uint8_t *body, size_t len)

Issue an asynchronous HTTP(S) POST; response is delivered to on_http_resp with req_id.

int bark_http_get_cb (bark_net_t *net, const char *url, const char *headers_nl, bark_http_resp_fn on_resp, void *user)

Issue an asynchronous HTTP(S) GET with a dedicated per-request callback.

int bark_http_post_cb (bark_net_t *net, const char *url, const char *headers_nl, const uint8_t *body, size_t len, bark_http_resp_fn on_resp, void *user)

Issue an asynchronous HTTP(S) POST with a dedicated per-request callback.

int bark_http_download (const char *url, bark_http_chunk_fn on_chunk, bark_http_cancel_fn should_cancel, void *user, int follow_redirects, int *status_out)

Blocking, cancellable streaming HTTP(S) GET (intended for background worker threads).

Detailed Description

Bark asynchronous HTTPS and WebSocket client primitives.

Headless HTTP(S) client and multi-instance RFC 6455 WebSocket API.

All asynchronous callbacks fire exclusively on the main thread inside bark_net_poll(). Works identically on native hosts (libcurl/OpenSSL) and browser WASM (fetch/WebSocket).

Enumeration Type Documentation

enum bark_ws_state

Lifecycle states of a WebSocket connection.

Enumerator

BARK_WS_CLOSED
Socket is closed.
BARK_WS_CONNECTING
TLS/HTTP upgrade handshake in progress.
BARK_WS_OPEN
Connected and ready to send/receive frames.
BARK_WS_CLOSING
Close handshake in progress.

Function Documentation

int bark_http_download (const char * url, bark_http_chunk_fn on_chunk, bark_http_cancel_fn should_cancel, void * user, int follow_redirects, int * status_out)

Blocking, cancellable streaming HTTP(S) GET (intended for background worker threads). Ideal for large asset or model downloads. Returning non-zero from on_chunk or should_cancel aborts the transfer with BARK_ERR_CANCELED.

Author

Generated automatically by Doxygen for Bark from the source code.