Use small IO buffer

This commit is contained in:
Sergey Lyubka committed 2021-10-27 19:18:19 +01:00
1 parent 6ac09966ba
commit 35f02fdaad
2 files changed
+17 -26

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
PROG ?= example
CFLAGS ?= -DMG_IO_SIZE=8192
CFLAGS ?= -DMG_IO_SIZE=64
MBEDTLS_DIR ?=
ifeq "$(MBEDTLS_DIR)" ""
+16 -25
View File
@@ -32,21 +32,13 @@ static void forward_request(struct mg_http_message *hm,
(int) hm->uri.len, hm->uri.ptr));
}
static void forward_fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
struct mg_connection *c2 = fn_data;
if (ev == MG_EV_READ) {
if (c2 != NULL) {
// All incoming data from the backend, forward to the client
mg_send(c2, c->recv.buf, c->recv.len);
mg_iobuf_del(&c->recv, 0, c->recv.len);
}
} else if (ev == MG_EV_CONNECT) {
if (mg_url_is_ssl(s_backend_url)) {
struct mg_tls_opts opts = {.ca = "ca.pem"};
mg_tls_init(c, &opts);
}
static void fn2(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_READ && fn_data != NULL) {
// All incoming data from the backend, forward to the client
mg_send((struct mg_connection *) fn_data, c->recv.buf, c->recv.len);
mg_iobuf_del(&c->recv, 0, c->recv.len);
}
(void)ev_data;
(void) ev_data;
}
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
@@ -55,18 +47,17 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
// Client request, create backend connection Note that we're passing
// client connection `c` as fn_data for the created backend connection.
c2 = mg_connect(c->mgr, s_backend_url, forward_fn, c);
c->fn_data = c2;
if (c2 != NULL) {
forward_request(hm, c2);
c2 = mg_connect(c->mgr, s_backend_url, fn2, c);
if (c2 == NULL) {
mg_error(c, "Cannot create backend connection");
} else {
c->is_closing = 1;
}
} else if (ev == MG_EV_CONNECT) {
if (mg_url_is_ssl(s_backend_url)) {
struct mg_tls_opts opts = {.ca = "ca.pem"};
mg_tls_init(c, &opts);
if (mg_url_is_ssl(s_backend_url)) {
struct mg_tls_opts opts = {.ca = "ca.pem"};
mg_tls_init(c2, &opts);
}
c->fn_data = c2;
forward_request(hm, c2);
// c2->is_hexdumping = 1;
}
} else if (ev == MG_EV_CLOSE) {
if (c2 != NULL) c2->is_closing = 1;