mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
Rename struct mg_connection::label -> data. Make its size configurable
This commit is contained in:
1 parent
3d75d71767
commit
da5e8e9778
27 files changed
+3204
-2247
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -78,7 +78,7 @@ static struct user *getuser(struct mg_http_message *hm) {
|
||||
static void send_notification(struct mg_mgr *mgr, const char *fmt, ...) {
|
||||
struct mg_connection *c;
|
||||
for (c = mgr->conns; c != NULL; c = c->next) {
|
||||
if (c->label[0] == 'W') {
|
||||
if (c->data[0] == 'W') {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
mg_ws_vprintf(c, WEBSOCKET_OP_TEXT, fmt, &ap);
|
||||
@@ -201,7 +201,7 @@ void device_dashboard_fn(struct mg_connection *c, int ev, void *ev_data,
|
||||
}
|
||||
mg_http_reply(c, 200, "", "ok\n");
|
||||
} else if (mg_http_match_uri(hm, "/api/watch")) {
|
||||
c->label[0] = 'W'; // Mark ourselves as a event listener
|
||||
c->data[0] = 'W'; // Mark ourselves as a event listener
|
||||
mg_ws_upgrade(c, hm, NULL);
|
||||
} else if (mg_http_match_uri(hm, "/api/login")) {
|
||||
mg_http_reply(c, 200, NULL, "{%Q:%Q,%Q:%Q}\n", "user", u->name, "token",
|
||||
|
||||
@@ -16,10 +16,10 @@ static bool done = false;
|
||||
// Print HTTP response and signal that we're done
|
||||
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
if (ev == MG_EV_OPEN) {
|
||||
// Connection created. Store connect expiration time in c->label
|
||||
*(int64_t *) c->label = mg_millis() + s_timeout_ms;
|
||||
// Connection created. Store connect expiration time in c->data
|
||||
*(int64_t *) c->data = mg_millis() + s_timeout_ms;
|
||||
} else if (ev == MG_EV_POLL) {
|
||||
if (mg_millis() > *(int64_t *) c->label &&
|
||||
if (mg_millis() > *(int64_t *) c->data &&
|
||||
(c->is_connecting || c->is_resolving)) {
|
||||
mg_error(c, "Connect timeout");
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -32,13 +32,13 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||
MG_INFO(("Connected to %s", s_url));
|
||||
MG_INFO(("Subscribing to %s", s_rx_topic));
|
||||
mg_mqtt_sub(c, topic, s_qos);
|
||||
c->label[0] = 'X'; // Set a label that we're logged in
|
||||
c->data[0] = 'X'; // Set a label that we're logged in
|
||||
} else if (ev == MG_EV_MQTT_MSG) {
|
||||
// When we receive MQTT message, print it
|
||||
struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data;
|
||||
MG_INFO(("Received on %.*s : %.*s", (int) mm->topic.len, mm->topic.ptr,
|
||||
(int) mm->data.len, mm->data.ptr));
|
||||
} else if (ev == MG_EV_POLL && c->label[0] == 'X') {
|
||||
} else if (ev == MG_EV_POLL && c->data[0] == 'X') {
|
||||
static unsigned long prev_second;
|
||||
unsigned long now_second = (*(unsigned long *) ev_data) / 1000;
|
||||
if (now_second != prev_second) {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user