mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-15 02:08:08 +08:00
Restored void * parameter for iterate_over_connections()
This commit is contained in:
parent
367f5df328
commit
94f63787bb
@ -9,10 +9,10 @@
|
|||||||
extern const char *find_embedded_file(const char *, size_t *);
|
extern const char *find_embedded_file(const char *, size_t *);
|
||||||
|
|
||||||
static int iterate_callback(struct mg_connection *c, enum mg_event ev) {
|
static int iterate_callback(struct mg_connection *c, enum mg_event ev) {
|
||||||
static int counter = 0;
|
|
||||||
if (ev == MG_POLL && c->is_websocket) {
|
if (ev == MG_POLL && c->is_websocket) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
int len = snprintf(buf, sizeof(buf), "%d", counter++);
|
int len = snprintf(buf, sizeof(buf), "%lu",
|
||||||
|
(unsigned long) * (time_t *) c->callback_param);
|
||||||
mg_websocket_write(c, 1, buf, len);
|
mg_websocket_write(c, 1, buf, len);
|
||||||
}
|
}
|
||||||
return MG_TRUE;
|
return MG_TRUE;
|
||||||
@ -58,7 +58,7 @@ int main(void) {
|
|||||||
current_timer = time(NULL);
|
current_timer = time(NULL);
|
||||||
if (current_timer - last_timer > 0) {
|
if (current_timer - last_timer > 0) {
|
||||||
last_timer = current_timer;
|
last_timer = current_timer;
|
||||||
mg_iterate_over_connections(server, iterate_callback);
|
mg_iterate_over_connections(server, iterate_callback, ¤t_timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
mongoose.c
13
mongoose.c
@ -4254,20 +4254,21 @@ struct mg_iterator {
|
|||||||
mg_handler_t cb;
|
mg_handler_t cb;
|
||||||
void *param;
|
void *param;
|
||||||
};
|
};
|
||||||
union variant { mg_handler_t cb; void *p; };
|
|
||||||
|
|
||||||
static void iter(struct ns_connection *nsconn, enum ns_event ev, void *param) {
|
static void iter(struct ns_connection *nsconn, enum ns_event ev, void *param) {
|
||||||
if (ev == NS_POLL) {
|
if (ev == NS_POLL) {
|
||||||
union variant *variant = (union variant *) param;
|
struct mg_iterator *it = (struct mg_iterator *) param;
|
||||||
struct connection *c = (struct connection *) nsconn->connection_data;
|
struct connection *c = (struct connection *) nsconn->connection_data;
|
||||||
variant->cb(&c->mg_conn, MG_POLL);
|
c->mg_conn.callback_param = it->param;
|
||||||
|
it->cb(&c->mg_conn, MG_POLL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply function to all active connections.
|
// Apply function to all active connections.
|
||||||
void mg_iterate_over_connections(struct mg_server *server, mg_handler_t cb) {
|
void mg_iterate_over_connections(struct mg_server *server, mg_handler_t cb,
|
||||||
union variant variant = { cb };
|
void *param) {
|
||||||
ns_iterate(&server->ns_server, iter, &variant);
|
struct mg_iterator it = { cb, param };
|
||||||
|
ns_iterate(&server->ns_server, iter, &it);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_var(const char *data, size_t data_len, const char *name,
|
static int get_var(const char *data, size_t data_len, const char *name,
|
||||||
|
@ -48,13 +48,14 @@ struct mg_connection {
|
|||||||
} http_headers[30];
|
} http_headers[30];
|
||||||
|
|
||||||
char *content; // POST (or websocket message) data, or NULL
|
char *content; // POST (or websocket message) data, or NULL
|
||||||
size_t content_len; // content length
|
size_t content_len; // Data length
|
||||||
|
|
||||||
int is_websocket; // Connection is a websocket connection
|
int is_websocket; // Connection is a websocket connection
|
||||||
int status_code; // HTTP status code for HTTP error handler
|
int status_code; // HTTP status code for HTTP error handler
|
||||||
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; // Needed by mg_iterate_over_connections()
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mg_server; // Opaque structure describing server instance
|
struct mg_server; // Opaque structure describing server instance
|
||||||
@ -80,7 +81,7 @@ const char **mg_get_valid_option_names(void);
|
|||||||
const char *mg_get_option(const struct mg_server *server, const char *name);
|
const char *mg_get_option(const struct mg_server *server, const char *name);
|
||||||
void mg_set_listening_socket(struct mg_server *, int sock);
|
void mg_set_listening_socket(struct mg_server *, int sock);
|
||||||
int mg_get_listening_socket(struct mg_server *);
|
int mg_get_listening_socket(struct mg_server *);
|
||||||
void mg_iterate_over_connections(struct mg_server *, mg_handler_t);
|
void mg_iterate_over_connections(struct mg_server *, mg_handler_t, void *);
|
||||||
void mg_wakeup_server(struct mg_server *);
|
void mg_wakeup_server(struct mg_server *);
|
||||||
struct mg_connection *mg_connect(struct mg_server *, const char *, int, int);
|
struct mg_connection *mg_connect(struct mg_server *, const char *, int, int);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user