mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-26 22:41:03 +08:00
improve close on TLS
This commit is contained in:
parent
4f6a78cde8
commit
3ffe5e958f
10
mongoose.c
10
mongoose.c
@ -7529,9 +7529,13 @@ static void read_conn(struct mg_connection *c) {
|
|||||||
if (!ioalloc(c, &c->rtls)) return;
|
if (!ioalloc(c, &c->rtls)) return;
|
||||||
n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len],
|
n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len],
|
||||||
c->rtls.size - c->rtls.len);
|
c->rtls.size - c->rtls.len);
|
||||||
if (n == MG_IO_ERR && mg_tls_pending(c) == 0) {
|
if (n == MG_IO_ERR) {
|
||||||
// Close only if we have fully drained both raw (rtls) and TLS buffers
|
if (c->rtls.len == 0 || c->is_io_err) {
|
||||||
c->is_closing = 1;
|
// Close only when we have fully drained both rtls and TLS buffers
|
||||||
|
c->is_closing = 1; // or there's nothing we can do about it.
|
||||||
|
} else { // TLS buffer is capped to max record size, mark and
|
||||||
|
c->is_io_err = 1; // give TLS a chance to process that.
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (n > 0) c->rtls.len += (size_t) n;
|
if (n > 0) c->rtls.len += (size_t) n;
|
||||||
if (c->is_tls_hs) mg_tls_handshake(c);
|
if (c->is_tls_hs) mg_tls_handshake(c);
|
||||||
|
@ -2157,6 +2157,7 @@ struct mg_connection {
|
|||||||
unsigned is_resp : 1; // Response is still being generated
|
unsigned is_resp : 1; // Response is still being generated
|
||||||
unsigned is_readable : 1; // Connection is ready to read
|
unsigned is_readable : 1; // Connection is ready to read
|
||||||
unsigned is_writable : 1; // Connection is ready to write
|
unsigned is_writable : 1; // Connection is ready to write
|
||||||
|
unsigned is_io_err : 1; // Remember IO_ERR condition for later use
|
||||||
};
|
};
|
||||||
|
|
||||||
void mg_mgr_poll(struct mg_mgr *, int ms);
|
void mg_mgr_poll(struct mg_mgr *, int ms);
|
||||||
|
@ -76,6 +76,7 @@ struct mg_connection {
|
|||||||
unsigned is_resp : 1; // Response is still being generated
|
unsigned is_resp : 1; // Response is still being generated
|
||||||
unsigned is_readable : 1; // Connection is ready to read
|
unsigned is_readable : 1; // Connection is ready to read
|
||||||
unsigned is_writable : 1; // Connection is ready to write
|
unsigned is_writable : 1; // Connection is ready to write
|
||||||
|
unsigned is_io_err : 1; // Remember IO_ERR condition for later use
|
||||||
};
|
};
|
||||||
|
|
||||||
void mg_mgr_poll(struct mg_mgr *, int ms);
|
void mg_mgr_poll(struct mg_mgr *, int ms);
|
||||||
|
10
src/sock.c
10
src/sock.c
@ -282,9 +282,13 @@ static void read_conn(struct mg_connection *c) {
|
|||||||
if (!ioalloc(c, &c->rtls)) return;
|
if (!ioalloc(c, &c->rtls)) return;
|
||||||
n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len],
|
n = recv_raw(c, (char *) &c->rtls.buf[c->rtls.len],
|
||||||
c->rtls.size - c->rtls.len);
|
c->rtls.size - c->rtls.len);
|
||||||
if (n == MG_IO_ERR && mg_tls_pending(c) == 0) {
|
if (n == MG_IO_ERR) {
|
||||||
// Close only if we have fully drained both raw (rtls) and TLS buffers
|
if (c->rtls.len == 0 || c->is_io_err) {
|
||||||
c->is_closing = 1;
|
// Close only when we have fully drained both rtls and TLS buffers
|
||||||
|
c->is_closing = 1; // or there's nothing we can do about it.
|
||||||
|
} else { // TLS buffer is capped to max record size, mark and
|
||||||
|
c->is_io_err = 1; // give TLS a chance to process that.
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (n > 0) c->rtls.len += (size_t) n;
|
if (n > 0) c->rtls.len += (size_t) n;
|
||||||
if (c->is_tls_hs) mg_tls_handshake(c);
|
if (c->is_tls_hs) mg_tls_handshake(c);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user