mirror of
https://github.com/lammertb/libhttp.git
synced 2025-07-29 21:01:13 +03:00
Clean usage of const/not const mg_context* and mg_connection* handles in the API.
The API had an inconsistant usage of `const mg_connection *` and `mg_connection *`, that may cause warnings (e.g., #109). Now all non-const `mg_connection *` is only required to read/write the connection.
This commit is contained in:
@ -37,13 +37,13 @@ static void send_to_all_websockets(struct mg_context *ctx, const char * data, in
|
||||
void websocket_ready_handler(struct mg_connection *conn) {
|
||||
|
||||
int i;
|
||||
struct mg_request_info * rq = mg_get_request_info(conn);
|
||||
const struct mg_request_info * rq = mg_get_request_info(conn);
|
||||
struct mg_context * ctx = mg_get_context(conn);
|
||||
tWebSockContext *ws_ctx = (tWebSockContext*) mg_get_user_data(ctx);
|
||||
tWebSockInfo * wsock = malloc(sizeof(tWebSockInfo));
|
||||
assert(wsock);
|
||||
wsock->webSockState = 0;
|
||||
rq->conn_data = wsock;
|
||||
mg_set_user_connection_data(conn, wsock);
|
||||
|
||||
mg_lock_context(ctx);
|
||||
for (i=0;i<MAX_NUM_OF_WEBSOCKS;i++) {
|
||||
@ -79,7 +79,7 @@ static void websocket_done(tWebSockContext *ws_ctx, tWebSockInfo * wsock) {
|
||||
|
||||
int websocket_data_handler(struct mg_connection *conn, int flags, char *data, size_t data_len) {
|
||||
|
||||
struct mg_request_info * rq = mg_get_request_info(conn);
|
||||
const struct mg_request_info * rq = mg_get_request_info(conn);
|
||||
tWebSockInfo * wsock = (tWebSockInfo*)rq->conn_data;
|
||||
struct mg_context * ctx = mg_get_context(conn);
|
||||
tWebSockContext *ws_ctx = (tWebSockContext*) mg_get_user_data(ctx);
|
||||
@ -89,7 +89,7 @@ int websocket_data_handler(struct mg_connection *conn, int flags, char *data, si
|
||||
if (flags==136) {
|
||||
// close websock
|
||||
websocket_done(ws_ctx, wsock);
|
||||
rq->conn_data = 0;
|
||||
mg_set_user_connection_data(conn, NULL);
|
||||
mg_unlock_context(ctx);
|
||||
return 1;
|
||||
}
|
||||
@ -129,16 +129,16 @@ int websocket_data_handler(struct mg_connection *conn, int flags, char *data, si
|
||||
}
|
||||
|
||||
|
||||
void connection_close_handler(struct mg_connection *conn) {
|
||||
void connection_close_handler(const struct mg_connection *conn) {
|
||||
|
||||
struct mg_request_info * rq = mg_get_request_info(conn);
|
||||
const struct mg_request_info * rq = mg_get_request_info(conn);
|
||||
tWebSockInfo * wsock = (tWebSockInfo*)rq->conn_data;
|
||||
struct mg_context * ctx = mg_get_context(conn);
|
||||
tWebSockContext *ws_ctx = (tWebSockContext*) mg_get_user_data(ctx);
|
||||
|
||||
mg_lock_context(ctx);
|
||||
websocket_done(ws_ctx, wsock);
|
||||
rq->conn_data = 0;
|
||||
mg_set_user_connection_data(conn, NULL);
|
||||
mg_unlock_context(ctx);
|
||||
}
|
||||
|
||||
@ -174,15 +174,15 @@ void websock_send_broadcast(struct mg_context *ctx, const char * data, int data_
|
||||
}
|
||||
}
|
||||
|
||||
void websock_init_lib(struct mg_context *ctx) {
|
||||
void websock_init_lib(const struct mg_context *ctx) {
|
||||
|
||||
tWebSockContext *ws_ctx = (tWebSockContext*) mg_get_user_data(ctx);
|
||||
memset(ws_ctx,0,sizeof(*ws_ctx));
|
||||
memset(ws_ctx, 0, sizeof(*ws_ctx));
|
||||
/* todo: use mg_start_thread_id instead of mg_start_thread */
|
||||
mg_start_thread(eventMain, ctx);
|
||||
mg_start_thread(eventMain, (void*)ctx);
|
||||
}
|
||||
|
||||
void websock_exit_lib(struct mg_context *ctx) {
|
||||
void websock_exit_lib(const struct mg_context *ctx) {
|
||||
|
||||
tWebSockContext *ws_ctx = (tWebSockContext*) mg_get_user_data(ctx);
|
||||
ws_ctx->runLoop = 0;
|
||||
|
Reference in New Issue
Block a user