mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-16 10:39:49 +00:00
fix no room
This commit is contained in:
1 parent
db658918c6
commit
416dc7beae
4 files changed
+16
-10
No files matched your search
+8
-5
@@ -8712,13 +8712,16 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||
}
|
||||
|
||||
static void handle_tls_recv(struct mg_connection *c) {
|
||||
size_t avail = mg_tls_pending(c);
|
||||
size_t avail = mg_tls_pending(c); // will change after mg_tls_recv()
|
||||
size_t min = avail > MG_MAX_RECV_SIZE ? MG_MAX_RECV_SIZE : avail;
|
||||
struct mg_iobuf *io = &c->recv;
|
||||
struct mg_iobuf *io = &c->recv; // allocated on first avail > 0
|
||||
if (io->size - io->len < min && !mg_iobuf_resize(io, io->len + min)) {
|
||||
mg_error(c, "oom");
|
||||
} else {
|
||||
// Decrypt data directly into c->recv
|
||||
// Decrypt data directly into c->recv. If io->buf = NULL or
|
||||
// io->len = io->size (no room), there can be outstanding data that can't be
|
||||
// moved (mg_tls_pending() > 0 after mg_tls_recv() returns). So mg_tls_recv()
|
||||
// takes care of returning 0 in this case (commented as "MIP")
|
||||
long n = mg_tls_recv(c, io->buf != NULL ? &io->buf[io->len] : io->buf,
|
||||
io->size - io->len);
|
||||
if (n == MG_IO_ERR) {
|
||||
@@ -19631,7 +19634,7 @@ size_t mg_tls_pending(struct mg_connection *c) {
|
||||
long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) {
|
||||
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
||||
long n = mbedtls_ssl_read(&tls->ssl, (unsigned char *) buf, len);
|
||||
if (!c->is_tls_hs && buf == NULL && n == 0) return 0; // TODO(): MIP
|
||||
if (!c->is_tls_hs && (buf == NULL || len == 0) && n == 0) return 0; // MIP
|
||||
if (n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE)
|
||||
return MG_IO_WAIT;
|
||||
#if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
|
||||
@@ -20027,7 +20030,7 @@ size_t mg_tls_pending(struct mg_connection *c) {
|
||||
long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) {
|
||||
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
||||
int n = SSL_read(tls->ssl, buf, (int) len);
|
||||
if (!c->is_tls_hs && buf == NULL && n == 0) return 0; // TODO(): MIP
|
||||
if (!c->is_tls_hs && (buf == NULL || len == 0) && n == 0) return 0; // MIP
|
||||
if (n < 0 && mg_tls_err(c, tls, n) == 0) return MG_IO_WAIT;
|
||||
if (n <= 0) return MG_IO_ERR;
|
||||
return n;
|
||||
|
||||
+6
-3
@@ -1403,13 +1403,16 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
|
||||
}
|
||||
|
||||
static void handle_tls_recv(struct mg_connection *c) {
|
||||
size_t avail = mg_tls_pending(c);
|
||||
size_t avail = mg_tls_pending(c); // will change after mg_tls_recv()
|
||||
size_t min = avail > MG_MAX_RECV_SIZE ? MG_MAX_RECV_SIZE : avail;
|
||||
struct mg_iobuf *io = &c->recv;
|
||||
struct mg_iobuf *io = &c->recv; // allocated on first avail > 0
|
||||
if (io->size - io->len < min && !mg_iobuf_resize(io, io->len + min)) {
|
||||
mg_error(c, "oom");
|
||||
} else {
|
||||
// Decrypt data directly into c->recv
|
||||
// Decrypt data directly into c->recv. If io->buf = NULL or
|
||||
// io->len = io->size (no room), there can be outstanding data that can't be
|
||||
// moved (mg_tls_pending() > 0 after mg_tls_recv() returns). So mg_tls_recv()
|
||||
// takes care of returning 0 in this case (commented as "MIP")
|
||||
long n = mg_tls_recv(c, io->buf != NULL ? &io->buf[io->len] : io->buf,
|
||||
io->size - io->len);
|
||||
if (n == MG_IO_ERR) {
|
||||
|
||||
+1
-1
@@ -201,7 +201,7 @@ size_t mg_tls_pending(struct mg_connection *c) {
|
||||
long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) {
|
||||
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
||||
long n = mbedtls_ssl_read(&tls->ssl, (unsigned char *) buf, len);
|
||||
if (!c->is_tls_hs && buf == NULL && n == 0) return 0; // TODO(): MIP
|
||||
if (!c->is_tls_hs && (buf == NULL || len == 0) && n == 0) return 0; // MIP
|
||||
if (n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE)
|
||||
return MG_IO_WAIT;
|
||||
#if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
|
||||
|
||||
+1
-1
@@ -293,7 +293,7 @@ size_t mg_tls_pending(struct mg_connection *c) {
|
||||
long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) {
|
||||
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
||||
int n = SSL_read(tls->ssl, buf, (int) len);
|
||||
if (!c->is_tls_hs && buf == NULL && n == 0) return 0; // TODO(): MIP
|
||||
if (!c->is_tls_hs && (buf == NULL || len == 0) && n == 0) return 0; // MIP
|
||||
if (n < 0 && mg_tls_err(c, tls, n) == 0) return MG_IO_WAIT;
|
||||
if (n <= 0) return MG_IO_ERR;
|
||||
return n;
|
||||
|
||||
Reference in new issue
Block a user