Functions
mk_host_broadcastfunction
void mk_host_broadcast(mk_host_t *host, uint8_t channel, const void *data, uint32_t len)
Perform the host broadcast operation.
| Parameter | Type | Description |
|---|
host | mk_host_t * | Value for host. |
channel | uint8_t | Value for channel. |
data | const void * | Data buffer. |
len | uint32_t | Value for len. |
mk_host_broadcast_exceptfunction
void mk_host_broadcast_except(mk_host_t *host, mk_peer_t *except, uint8_t channel, const void *data, uint32_t len)
Perform the host broadcast except operation.
| Parameter | Type | Description |
|---|
host | mk_host_t * | Value for host. |
except | mk_peer_t * | Value for except. |
channel | uint8_t | Value for channel. |
data | const void * | Data buffer. |
len | uint32_t | Value for len. |
mk_host_connectfunction
mk_peer_t * mk_host_connect(mk_host_t *host, const char *remote, uint16_t port)
Client: initiate a connection.
Returns a peer in the CONNECTING state; a
| Parameter | Type | Description |
|---|
host | mk_host_t * | Value for host. |
remote | const char * | Value for remote. |
port | uint16_t | Value for port. |
Returns A borrowed pointer, or NULL when unavailable. MK_PEER_EVENT_CONNECT (or DISCONNECT on failure) follows from service().
mk_host_connect_urlfunction
mk_peer_t * mk_host_connect_url(mk_host_t *host, const char *url)
Client: connect a WebSocket host using an absolute ws:// or wss:// URL.
The URL may include a path, query, explicit port, or bracketed IPv6 address. Returns NULL for an invalid URL, non-client host, or non-WebSocket transport.
| Parameter | Type | Description |
|---|
host | mk_host_t * | Value for host. |
url | const char * | Value for URL. |
Returns A borrowed pointer, or NULL when unavailable.
mk_host_createfunction
mk_host_t * mk_host_create(const mk_host_desc *desc)
Create host.
| Parameter | Type | Description |
|---|
desc | const mk_host_desc * | Configuration descriptor. |
Returns A borrowed pointer, or NULL when unavailable.
mk_host_destroyfunction
void mk_host_destroy(mk_host_t *host)
Destroy the host.
| Parameter | Type | Description |
|---|
host | mk_host_t * | Value for host. |
mk_host_peer_countfunction
uint32_t mk_host_peer_count(mk_host_t *host)
Number of peers currently attached to a host.
| Parameter | Type | Description |
|---|
host | mk_host_t * | Value for host. |
Returns The resulting value.
mk_host_peer_firstfunction
mk_peer_t * mk_host_peer_first(mk_host_t *host)
First attached peer, or NULL.
| Parameter | Type | Description |
|---|
host | mk_host_t * | Value for host. |
Returns A borrowed pointer, or NULL when unavailable.
mk_host_servicefunction
int mk_host_service(mk_host_t *host, mk_peer_event *out, uint32_t timeout_ms)
Pump the network and dequeue ONE event.
Call repeatedly until it returns 0. Drives the transport event loop. timeout_ms 0 = non-blocking (clients/frame
| Parameter | Type | Description |
|---|
host | mk_host_t * | Value for host. |
out | mk_peer_event * | Value for out. |
timeout_ms | uint32_t | Value for timeout ms. |
Returns The resulting value. loop); >0 may block up to that long waiting for I/O (headless server tick).
mk_peer_addressfunction
bool mk_peer_address(mk_peer_t *peer, char *host, size_t cap, uint16_t *port)
Perform the peer address operation.
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
host | char * | Value for host. |
cap | size_t | Value for cap. |
port | uint16_t * | Value for port. |
Returns True when the operation succeeds.
mk_peer_disconnectfunction
void mk_peer_disconnect(mk_peer_t *peer, mk_disconnect_reason_t reason)
Perform the peer disconnect operation.
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
reason | mk_disconnect_reason_t | Value for reason. |
mk_peer_get_userfunction
uint64_t mk_peer_get_user(mk_peer_t *peer)
Get user from the peer.
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
Returns The resulting value.
mk_peer_get_user_ptrfunction
void * mk_peer_get_user_ptr(mk_peer_t *peer)
Get user ptr from the peer.
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
Returns A borrowed pointer, or NULL when unavailable.
mk_peer_hostfunction
mk_host_t * mk_peer_host(mk_peer_t *peer)
Perform the peer host operation.
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
Returns A borrowed pointer, or NULL when unavailable.
mk_peer_nextfunction
mk_peer_t * mk_peer_next(mk_peer_t *peer)
Next peer in the host's list, or NULL at the end.
The iteration is invalidated by mk_host_service(), which is when
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
Returns A borrowed pointer, or NULL when unavailable. disconnected peers are retired; re-walk it rather than holding pointers.
mk_peer_rtt_msfunction
uint32_t mk_peer_rtt_ms(mk_peer_t *peer)
0 if unknown
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
Returns The resulting value. 0 if unknown
mk_peer_sendfunction
bool mk_peer_send(mk_peer_t *peer, uint8_t channel, const void *data, uint32_t len)
Send peer.
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
channel | uint8_t | Value for channel. |
data | const void * | Data buffer. |
len | uint32_t | Value for len. |
Returns True when the operation succeeds.
mk_peer_set_userfunction
void mk_peer_set_user(mk_peer_t *peer, uint64_t user)
Set user on the peer.
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
user | uint64_t | Caller-provided context. |
mk_peer_set_user_ptrfunction
void mk_peer_set_user_ptr(mk_peer_t *peer, void *ptr)
A second, pointer-sized slot of per-peer application state.
One uint64 is
| Parameter | Type | Description |
|---|
peer | mk_peer_t * | Value for peer. |
ptr | void * | Value for ptr. not enough once a peer carries both a platform identity and an app object. |