Merge pull request #2988 from cesanta/tlspoll

fix mg_tls_pending
This commit is contained in:
Sergey Lyubka 2024-12-17 14:24:13 +00:00 committed by GitHub
commit 1e1efa2c5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View File

@ -4718,7 +4718,8 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
} }
static void handle_tls_recv(struct mg_connection *c) { static void handle_tls_recv(struct mg_connection *c) {
size_t min = 512; size_t avail = mg_tls_pending(c);
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;
if (io->size - io->len < min && !mg_iobuf_resize(io, io->len + min)) { if (io->size - io->len < min && !mg_iobuf_resize(io, io->len + min)) {
mg_error(c, "oom"); mg_error(c, "oom");
@ -4731,7 +4732,7 @@ static void handle_tls_recv(struct mg_connection *c) {
// Decrypted successfully - trigger MG_EV_READ // Decrypted successfully - trigger MG_EV_READ
io->len += (size_t) n; io->len += (size_t) n;
mg_call(c, MG_EV_READ, &n); mg_call(c, MG_EV_READ, &n);
} } // else n < 0: outstanding data to be moved to c->recv
} }
} }
@ -11334,7 +11335,8 @@ long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) {
} }
size_t mg_tls_pending(struct mg_connection *c) { size_t mg_tls_pending(struct mg_connection *c) {
return mg_tls_got_record(c) ? 1 : 0; struct tls_data *tls = (struct tls_data *) c->tls;
return tls != NULL ? tls->recv_len : 0;
} }
void mg_tls_ctx_init(struct mg_mgr *mgr) { void mg_tls_ctx_init(struct mg_mgr *mgr) {

View File

@ -642,7 +642,8 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
} }
static void handle_tls_recv(struct mg_connection *c) { static void handle_tls_recv(struct mg_connection *c) {
size_t min = 512; size_t avail = mg_tls_pending(c);
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;
if (io->size - io->len < min && !mg_iobuf_resize(io, io->len + min)) { if (io->size - io->len < min && !mg_iobuf_resize(io, io->len + min)) {
mg_error(c, "oom"); mg_error(c, "oom");
@ -655,7 +656,7 @@ static void handle_tls_recv(struct mg_connection *c) {
// Decrypted successfully - trigger MG_EV_READ // Decrypted successfully - trigger MG_EV_READ
io->len += (size_t) n; io->len += (size_t) n;
mg_call(c, MG_EV_READ, &n); mg_call(c, MG_EV_READ, &n);
} } // else n < 0: outstanding data to be moved to c->recv
} }
} }

View File

@ -1390,7 +1390,8 @@ long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) {
} }
size_t mg_tls_pending(struct mg_connection *c) { size_t mg_tls_pending(struct mg_connection *c) {
return mg_tls_got_record(c) ? 1 : 0; struct tls_data *tls = (struct tls_data *) c->tls;
return tls != NULL ? tls->recv_len : 0;
} }
void mg_tls_ctx_init(struct mg_mgr *mgr) { void mg_tls_ctx_init(struct mg_mgr *mgr) {