@@ -5497,6 +5497,17 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
5497
5497
return (long) len;
5498
5498
}
5499
5499
5500
+ static void handle_tls_recv(struct mg_connection *c, struct mg_iobuf *io) {
5501
+ long n = mg_tls_recv(c, &io->buf[io->len], io->size - io->len);
5502
+ if (n == MG_IO_ERR) {
5503
+ mg_error(c, "TLS recv error");
5504
+ } else if (n > 0) {
5505
+ // Decrypted successfully - trigger MG_EV_READ
5506
+ io->len += (size_t) n;
5507
+ mg_call(c, MG_EV_READ, &n);
5508
+ }
5509
+ }
5510
+
5500
5511
static void read_conn(struct mg_connection *c, struct pkt *pkt) {
5501
5512
struct connstate *s = (struct connstate *) (c + 1);
5502
5513
struct mg_iobuf *io = c->is_tls ? &c->rtls : &c->recv;
@@ -5575,14 +5586,7 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
5575
5586
mg_error(c, "oom");
5576
5587
} else {
5577
5588
// Decrypt data directly into c->recv
5578
- long n = mg_tls_recv(c, &io->buf[io->len], io->size - io->len);
5579
- if (n == MG_IO_ERR) {
5580
- mg_error(c, "TLS recv error");
5581
- } else if (n > 0) {
5582
- // Decrypted successfully - trigger MG_EV_READ
5583
- io->len += (size_t) n;
5584
- mg_call(c, MG_EV_READ, &n);
5585
- }
5589
+ handle_tls_recv(c, io);
5586
5590
}
5587
5591
} else {
5588
5592
// Plain text connection, data is already in c->recv, trigger
@@ -5993,6 +5997,8 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
5993
5997
MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't',
5994
5998
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
5995
5999
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c'));
6000
+ if (c->is_tls && mg_tls_pending(c) > 0)
6001
+ handle_tls_recv(c, (struct mg_iobuf *) &c->rtls);
5996
6002
if (can_write(c)) write_conn(c);
5997
6003
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
5998
6004
init_closure(c);
0 commit comments