manual
API reference
Generated from src/netchan.h for netchan 0.8.0-dev-gedf8999, so it cannot
drift from the code. The full type and constant definitions are in
that header.
Configuration
netchan_cfg_default
void netchan_cfg_default(struct netchan_cfg *cfg)
Connection lifecycle
netchan_open
struct netchan_conn *netchan_open(int server)
netchan_disconnect
void netchan_disconnect(struct netchan_conn *c)
Queue a DISCONNECT for the peer and enter CLOSING, without freeing. Run one netchan_send_next cycle afterward to transmit it, then netchan_close to free. A graceful shutdown that saves the peer an idle timeout. Does nothing unless the connection is CONNECTED, so calling it twice, or on a session that never finished its handshake, is safe and queues nothing. The state is CLOSING afterward, and advances to CLOSED without an event if the peer's own DISCONNECT arrives before netchan_close. Best effort. DISCONNECT is one unreliable control frame and netchan does not retransmit it. If that datagram is lost, or the caller never runs the send cycle, the peer falls back to its idle timeout as before.
netchan_close
void netchan_close(struct netchan_conn *c)
netchan_config
void netchan_config(struct netchan_conn *c, const struct netchan_cfg *cfg)
netchan_state
int netchan_state(struct netchan_conn *c)
netchan_id
uint32_t netchan_id(struct netchan_conn *c)
netchan_connect
int netchan_connect(struct netchan_conn *c, const struct nc_addr *addr)
netchan_accept
int netchan_accept(struct netchan_conn *c)
Packet I/O -- application owns the UDP socket
netchan_peek_id
uint32_t netchan_peek_id(const void *pkt, size_t len)
Extract connection ID from a raw packet without full parsing.
netchan_feed
int netchan_feed(struct netchan_conn *c, const void *pkt, size_t len, const struct nc_addr *from)
Feed a received datagram into the connection. `from` is the transport address it arrived from (NULL if the transport has no source address).
netchan_send_next
size_t netchan_send_next(struct netchan_conn *c, void *buf, size_t buflen, struct nc_addr *to)
Get next outgoing packet. Returns byte count, 0 when nothing pending. `to` receives the peer's transport address.
netchan_service
int netchan_service(struct netchan_conn *c, uint32_t now_ms)
Service timers. Returns ms until the next needed call, or NETCHAN_ERR when idle.
Channel API
netchan_chan_open
struct netchan_chan *netchan_chan_open(struct netchan_conn *c, int type, int dir, const char *content_type)
netchan_chan_close
void netchan_chan_close(struct netchan_chan *ch)
netchan_chan_id
int netchan_chan_id(struct netchan_chan *ch)
netchan_chan_type
int netchan_chan_type(struct netchan_chan *ch)
netchan_chan_content_type
const char *netchan_chan_content_type(struct netchan_chan *ch)
The channel's content-type string, as given to netchan_chan_open() or as carried in the peer's OPEN. Use it to tell apart channels that share a netchan type, e.g. two reliable streams named "control" and "events". Never NULL: a channel opened without one reads back as "".
netchan_chan_state
int netchan_chan_state(struct netchan_chan *ch)
netchan_chan_write
int netchan_chan_write(struct netchan_chan *ch, const void *data, size_t len)
Queue a datagram or stream bytes for sending. Returns bytes queued.
netchan_chan_read
int netchan_chan_read(struct netchan_chan *ch, void *buf, size_t buflen)
Read next datagram or stream bytes. Returns bytes read, 0 if empty.
Events -- call after netchan_feed to drain the event queue
netchan_poll
int netchan_poll(struct netchan_conn *c, struct netchan_event *ev)
Statistics -- for congestion detection and diagnostics
netchan_conn_stats
void netchan_conn_stats(struct netchan_conn *c, struct netchan_conn_stats *s)
netchan_chan_stats
void netchan_chan_stats(struct netchan_chan *ch, struct netchan_chan_stats *s)