mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-10 16:31:44 +00:00
fix mg_send() failing on 0 length
This commit is contained in:
1 parent
b503915ca5
commit
236724ea29
5 files changed
+20
-8
No files matched your search
+4
-4
@@ -6225,9 +6225,9 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
len = trim_len(c, len); // Trimming length if necessary
|
len = trim_len(c, len); // Trimming length if necessary
|
||||||
res = udp_send(c, buf, len);
|
res = udp_send(c, buf, len);
|
||||||
} else {
|
} else {
|
||||||
res = (bool) mg_iobuf_add(&c->send, c->send.len, buf, len);
|
res = len == 0 || mg_iobuf_add(&c->send, c->send.len, buf, len) > 0;
|
||||||
// res == 0 means an OOM condition (iobuf couldn't resize), yet this is so
|
// returning 0 means an OOM condition (iobuf couldn't resize), yet this is
|
||||||
// far recoverable, let the caller decide
|
// so far recoverable, let the caller decide
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -9582,7 +9582,7 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
iolog(c, (char *) buf, n, false);
|
iolog(c, (char *) buf, n, false);
|
||||||
return n > 0;
|
return n > 0;
|
||||||
} else {
|
} else {
|
||||||
return (bool) mg_iobuf_add(&c->send, c->send.len, buf, len);
|
return len == 0 || mg_iobuf_add(&c->send, c->send.len, buf, len) > 0;
|
||||||
// returning 0 means an OOM condition (iobuf couldn't resize), yet this is
|
// returning 0 means an OOM condition (iobuf couldn't resize), yet this is
|
||||||
// so far recoverable, let the caller decide
|
// so far recoverable, let the caller decide
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -2019,9 +2019,9 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
len = trim_len(c, len); // Trimming length if necessary
|
len = trim_len(c, len); // Trimming length if necessary
|
||||||
res = udp_send(c, buf, len);
|
res = udp_send(c, buf, len);
|
||||||
} else {
|
} else {
|
||||||
res = (bool) mg_iobuf_add(&c->send, c->send.len, buf, len);
|
res = len == 0 || mg_iobuf_add(&c->send, c->send.len, buf, len) > 0;
|
||||||
// res == 0 means an OOM condition (iobuf couldn't resize), yet this is so
|
// returning 0 means an OOM condition (iobuf couldn't resize), yet this is
|
||||||
// far recoverable, let the caller decide
|
// so far recoverable, let the caller decide
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -141,7 +141,7 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
iolog(c, (char *) buf, n, false);
|
iolog(c, (char *) buf, n, false);
|
||||||
return n > 0;
|
return n > 0;
|
||||||
} else {
|
} else {
|
||||||
return (bool) mg_iobuf_add(&c->send, c->send.len, buf, len);
|
return len == 0 || mg_iobuf_add(&c->send, c->send.len, buf, len) > 0;
|
||||||
// returning 0 means an OOM condition (iobuf couldn't resize), yet this is
|
// returning 0 means an OOM condition (iobuf couldn't resize), yet this is
|
||||||
// so far recoverable, let the caller decide
|
// so far recoverable, let the caller decide
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -413,6 +413,7 @@ static void test_http_server(struct mg_mgr *mgr) {
|
|||||||
mg_mprintf("./mip_curl.sh http://%M:12347", mg_print_ip4, &mgr->ifp->ip);
|
mg_mprintf("./mip_curl.sh http://%M:12347", mg_print_ip4, &mgr->ifp->ip);
|
||||||
#endif
|
#endif
|
||||||
ASSERT(c != NULL);
|
ASSERT(c != NULL);
|
||||||
|
ASSERT (mg_send(c, "NADA", 0)); // check mg_send allows len=0
|
||||||
pthread_create(&thread_id, NULL, poll_thread,
|
pthread_create(&thread_id, NULL, poll_thread,
|
||||||
mgr); // simpler this way, no concurrency anyway
|
mgr); // simpler this way, no concurrency anyway
|
||||||
MG_DEBUG(("CURL"));
|
MG_DEBUG(("CURL"));
|
||||||
|
|||||||
@@ -2977,6 +2977,14 @@ static void eZ(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
(void) ev_data;
|
(void) ev_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void eS(struct mg_connection *c, int ev, void *ev_data) {
|
||||||
|
if (ev == MG_EV_HTTP_MSG) {
|
||||||
|
ASSERT (mg_send(c, "NADA", 0));
|
||||||
|
mg_http_reply(c, 200, "", "abcd");
|
||||||
|
}
|
||||||
|
(void) ev_data;
|
||||||
|
}
|
||||||
|
|
||||||
// Do not delete chunks as they arrive
|
// Do not delete chunks as they arrive
|
||||||
static void eh4(struct mg_connection *c, int ev, void *ev_data) {
|
static void eh4(struct mg_connection *c, int ev, void *ev_data) {
|
||||||
uint32_t *crc = (uint32_t *) c->fn_data;
|
uint32_t *crc = (uint32_t *) c->fn_data;
|
||||||
@@ -3012,6 +3020,9 @@ static void test_http_chunked_case(mg_event_handler_t s, mg_event_handler_t c,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_http_chunked(void) {
|
static void test_http_chunked(void) {
|
||||||
|
// test mg_send allows calls with 0 length
|
||||||
|
test_http_chunked_case(eS, eh4, 1, "abcd");
|
||||||
|
|
||||||
// Non-chunked encoding
|
// Non-chunked encoding
|
||||||
test_http_chunked_case(eY, eh4, 1, "abcd"); // Chunks not deleted
|
test_http_chunked_case(eY, eh4, 1, "abcd"); // Chunks not deleted
|
||||||
test_http_chunked_case(eY, eh4, 2, "abcdabcd");
|
test_http_chunked_case(eY, eh4, 2, "abcdabcd");
|
||||||
|
|||||||
Reference in new issue
Block a user