mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-14 10:20:01 +00:00
Use small IO buffer
This commit is contained in:
1 parent
6ac09966ba
commit
35f02fdaad
2 files changed
+17
-26
No files matched your search
@@ -1,5 +1,5 @@
|
||||
PROG ?= example
|
||||
CFLAGS ?= -DMG_IO_SIZE=8192
|
||||
CFLAGS ?= -DMG_IO_SIZE=64
|
||||
MBEDTLS_DIR ?=
|
||||
|
||||
ifeq "$(MBEDTLS_DIR)" ""
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user