Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/ws.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ extern "C" {
/* Opaque client connection type. */
typedef struct ws_connection ws_cli_conn_t;

/**
* @brief Set client context.
* Note that the same `ws_cli_conn_t` instance can be reused across connections.
*/
void ws_set_client_context(ws_cli_conn_t *cli, void *ptr);

/**
* @brief Get client context.
* Note that the same `ws_cli_conn_t` instance can be reused across connections.
*/
void *ws_get_client_context(ws_cli_conn_t *cli);

/**
* @brief events Web Socket events types.
*/
Expand Down Expand Up @@ -274,6 +286,11 @@ extern "C" {
* @brief Server events.
*/
struct ws_events evs;
/**
* @brief Client context.
* Note that the same `ws_cli_conn_t` instance can be reused across connections.
*/
void* client_context;
};

/* Forward declarations. */
Expand Down
18 changes: 18 additions & 0 deletions src/ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ struct ws_connection
pthread_mutex_t mtx_ping;
};

/**
* @brief Set client context.
* Note that the same `ws_cli_conn_t` instance can be reused across connections.
*/
void ws_set_client_context(ws_cli_conn_t *cli, void *ptr)
{
cli->ws_srv.client_context = ptr;
}

/**
* @brief Get client context.
* Note that the same `ws_cli_conn_t` instance can be reused across connections.
*/
void *ws_get_client_context(struct ws_connection* cli)
{
return cli->ws_srv.client_context;
}

/**
* @brief Clients list.
*/
Expand Down