diff --git a/docs/API.md b/docs/API.md index 7d74442f..786a9208 100644 --- a/docs/API.md +++ b/docs/API.md @@ -131,9 +131,9 @@ is returned. This is an interface primarily designed to push arbitrary data to websocket connections at any time. This function could be called from the IO thread only. When it returns, an IO thread calls `func()` on each active connection, -passing `param` as an extra parameter. It is allowed to call `mg_send_data()` or -`mg_websocket_write()` within a callback, cause `func` is executed in the -context of the IO thread. +passing `param` as `struct mg_connection::callback_param`. +It is allowed to call `mg_send_data()` or `mg_websocket_write()` within a +callback, cause `func` is executed in the context of the IO thread. void mg_send_status(struct mg_connection *, int status_code); void mg_send_header(struct mg_connection *, const char *name, diff --git a/examples/websocket.c b/examples/websocket.c index 5dbe711b..1c59b2c2 100644 --- a/examples/websocket.c +++ b/examples/websocket.c @@ -6,7 +6,7 @@ extern const char *find_embedded_file(const char *, size_t *); static int iterate_callback(struct mg_connection *c) { if (c->is_websocket) { char buf[20]; - int len = snprintf(buf, sizeof(buf), "%d", * (int *) c->connection_param); + int len = snprintf(buf, sizeof(buf), "%d", * (int *) c->callback_param); mg_websocket_write(c, 1, buf, len); } return MG_REQUEST_PROCESSED; diff --git a/mongoose.c b/mongoose.c index 01cd72ca..57ad3ed3 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3938,7 +3938,7 @@ void mg_iterate_over_connections(struct mg_server *server, mg_handler_t handler, LINKED_LIST_FOREACH(&server->active_connections, lp, tmp) { conn = LINKED_LIST_ENTRY(lp, struct connection, link); - conn->mg_conn.connection_param = param; + conn->mg_conn.callback_param = param; handler(&conn->mg_conn); } } diff --git a/mongoose.h b/mongoose.h index b0c1cfec..b71533b9 100644 --- a/mongoose.h +++ b/mongoose.h @@ -55,6 +55,7 @@ struct mg_connection { int wsbits; // First byte of the websocket frame void *server_param; // Parameter passed to mg_add_uri_handler() void *connection_param; // Placeholder for connection-specific data + void *callback_param; // Used by mg_iterate_over_connections() }; struct mg_server; // Opaque structure describing server instance