mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-04 21:58:22 +00:00
Using mg_connection::callback_param for mg_iterate_over_connection()
This commit is contained in:
1 parent
c9036f3ac0
commit
a3a63f7e56
4 files changed
+6
-5
No files matched your search
+3
-3
@@ -131,9 +131,9 @@ is returned.
|
|||||||
This is an interface primarily designed to push arbitrary data to websocket
|
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.
|
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,
|
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
|
passing `param` as `struct mg_connection::callback_param`.
|
||||||
`mg_websocket_write()` within a callback, cause `func` is executed in the
|
It is allowed to call `mg_send_data()` or `mg_websocket_write()` within a
|
||||||
context of the IO thread.
|
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_status(struct mg_connection *, int status_code);
|
||||||
void mg_send_header(struct mg_connection *, const char *name,
|
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) {
|
static int iterate_callback(struct mg_connection *c) {
|
||||||
if (c->is_websocket) {
|
if (c->is_websocket) {
|
||||||
char buf[20];
|
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);
|
mg_websocket_write(c, 1, buf, len);
|
||||||
}
|
}
|
||||||
return MG_REQUEST_PROCESSED;
|
return MG_REQUEST_PROCESSED;
|
||||||
|
|||||||
+1
-1
@@ -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) {
|
LINKED_LIST_FOREACH(&server->active_connections, lp, tmp) {
|
||||||
conn = LINKED_LIST_ENTRY(lp, struct connection, link);
|
conn = LINKED_LIST_ENTRY(lp, struct connection, link);
|
||||||
conn->mg_conn.connection_param = param;
|
conn->mg_conn.callback_param = param;
|
||||||
handler(&conn->mg_conn);
|
handler(&conn->mg_conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ struct mg_connection {
|
|||||||
int wsbits; // First byte of the websocket frame
|
int wsbits; // First byte of the websocket frame
|
||||||
void *server_param; // Parameter passed to mg_add_uri_handler()
|
void *server_param; // Parameter passed to mg_add_uri_handler()
|
||||||
void *connection_param; // Placeholder for connection-specific data
|
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
|
struct mg_server; // Opaque structure describing server instance
|
||||||
|
|||||||
Reference in new issue
Block a user