mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 05:26:15 +08:00
Using mg_connection::callback_param for mg_iterate_over_connection()
This commit is contained in:
parent
c9036f3ac0
commit
a3a63f7e56
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user