Rename struct mg_connection::label -> data. Make its size configurable

This commit is contained in:
cpq committed 2023-01-10 08:19:49 +00:00
1 parent 3d75d71767
commit da5e8e9778
27 files changed
+3204 -2247

No files matched your search

+6 -4
View File
@@ -81,14 +81,16 @@
#define MG_ENABLE_PACKED_FS 0
#endif
// Granularity of the send/recv IO buffer growth
#ifndef MG_IO_SIZE
#define MG_IO_SIZE 2048
#define MG_IO_SIZE 2048 // Granularity of the send/recv IO buffer growth
#endif
// Maximum size of the recv IO buffer
#ifndef MG_MAX_RECV_SIZE
#define MG_MAX_RECV_SIZE (3 * 1024 * 1024)
#define MG_MAX_RECV_SIZE (3 * 1024 * 1024) // Maximum recv IO buffer size
#endif
#ifndef MG_DATA_SIZE
#define MG_DATA_SIZE 32 // struct mg_connection :: data size
#endif
#ifndef MG_MAX_HTTP_HEADERS
+5 -5
View File
@@ -355,7 +355,7 @@ static void static_cb(struct mg_connection *c, int ev, void *ev_data,
struct mg_fd *fd = (struct mg_fd *) fn_data;
// Read to send IO buffer directly, avoid extra on-stack buffer
size_t n, max = MG_IO_SIZE, space;
size_t *cl = (size_t *) &c->label[(sizeof(c->label) - sizeof(size_t)) /
size_t *cl = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
sizeof(size_t) * sizeof(size_t)];
if (c->send.size < max) mg_iobuf_resize(&c->send, max);
if (c->send.len >= c->send.size) return; // Rate limit
@@ -527,8 +527,8 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
c->is_resp = 0;
mg_fs_close(fd);
} else {
// Track to-be-sent content length at the end of c->label, aligned
size_t *clp = (size_t *) &c->label[(sizeof(c->label) - sizeof(size_t)) /
// Track to-be-sent content length at the end of c->data, aligned
size_t *clp = (size_t *) &c->data[(sizeof(c->data) - sizeof(size_t)) /
sizeof(size_t) * sizeof(size_t)];
c->pfn = static_cb;
c->pfn_data = fd;
@@ -982,7 +982,7 @@ static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) {
if (mg_http_match_uri(hm, "/quit")) {
mg_http_reply(c, 200, "", "ok\n");
c->is_draining = 1;
c->label[0] = 'X';
c->data[0] = 'X';
} else if (mg_http_match_uri(hm, "/debug")) {
int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level);
@@ -991,7 +991,7 @@ static void mg_hfn(struct mg_connection *c, int ev, void *ev_data, void *fnd) {
mg_http_reply(c, 200, "", "hi\n");
}
} else if (ev == MG_EV_CLOSE) {
if (c->label[0] == 'X') *(bool *) fnd = true;
if (c->data[0] == 'X') *(bool *) fnd = true;
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ struct mg_connection {
void *fn_data; // User-specified function parameter
mg_event_handler_t pfn; // Protocol-specific handler function
void *pfn_data; // Protocol-specific function parameter
char label[50]; // Arbitrary label
char data[MG_DATA_SIZE]; // Arbitrary connection data
void *tls; // TLS specific data
unsigned is_listening : 1; // Listening connection
unsigned is_client : 1; // Outbound (client) connection
+2 -2
View File
@@ -101,8 +101,8 @@ static void iolog(struct mg_connection *c, char *buf, long n, bool r) {
union usa usa;
socklen_t slen = sizeof(usa.sin);
if (getsockname(FD(c), &usa.sa, &slen) < 0) (void) 0; // Ignore result
MG_INFO(("\n-- %lu %I %s %I %s %ld", c->id, 4, &usa.sin.sin_addr,
r ? "<-" : "->", 4, &c->rem.ip, c->label, n));
MG_INFO(("\n-- %lu %I %s %I %ld", c->id, 4, &usa.sin.sin_addr,
r ? "<-" : "->", 4, &c->rem.ip, n));
mg_hexdump(buf, (size_t) n);
}