Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added client context, with a disclaimer that it can be re-used. #91

Merged
merged 1 commit into from
Aug 8, 2024
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