mirror of
https://github.com/cesanta/mongoose.git
synced 2024-11-23 18:49:01 +08:00
Move TLS API to tls.h, fix builtin handshake codepath
This commit is contained in:
parent
4fc43cfbf7
commit
6e68124405
@ -5000,8 +5000,7 @@ static size_t trim_len(struct mg_connection *c, size_t len) {
|
||||
}
|
||||
// Ensure the MTU isn't lower than the minimum allowed value
|
||||
if (ifp->mtu < min_mtu) {
|
||||
MG_ERROR(("MTU is lower than minimum possible value. Setting it to %d.",
|
||||
min_mtu));
|
||||
MG_ERROR(("MTU is lower than minimum, capping to %lu", min_mtu));
|
||||
ifp->mtu = (uint16_t) min_mtu;
|
||||
}
|
||||
// If the total packet size exceeds the MTU, trim the length
|
||||
@ -5112,7 +5111,9 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
|
||||
if (s->ttype != MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_ACK);
|
||||
#endif
|
||||
|
||||
if (c->is_tls) {
|
||||
if (c->is_tls && c->is_tls_hs) {
|
||||
mg_tls_handshake(c);
|
||||
} else if (c->is_tls) {
|
||||
// TLS connection. Make room for decrypted data in c->recv
|
||||
io = &c->recv;
|
||||
if (io->size - io->len < pkt->pay.len &&
|
||||
@ -5526,7 +5527,6 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
|
||||
MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't',
|
||||
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
|
||||
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c'));
|
||||
if (c->is_tls_hs) mg_tls_handshake(c);
|
||||
if (can_write(c)) write_conn(c);
|
||||
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
|
||||
init_closure(c);
|
||||
|
10
mongoose.h
10
mongoose.h
@ -1293,11 +1293,6 @@ bool mg_open_listener(struct mg_connection *c, const char *url);
|
||||
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
||||
unsigned flags, void (*fn)(void *), void *arg);
|
||||
|
||||
// Low-level IO primives used by TLS layer
|
||||
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
||||
long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
|
||||
long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1402,6 +1397,11 @@ void mg_tls_handshake(struct mg_connection *);
|
||||
void mg_tls_ctx_init(struct mg_mgr *);
|
||||
void mg_tls_ctx_free(struct mg_mgr *);
|
||||
|
||||
// Low-level IO primives used by TLS layer
|
||||
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
||||
long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
|
||||
long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -99,8 +99,3 @@ bool mg_open_listener(struct mg_connection *c, const char *url);
|
||||
// Utility functions
|
||||
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
||||
unsigned flags, void (*fn)(void *), void *arg);
|
||||
|
||||
// Low-level IO primives used by TLS layer
|
||||
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
||||
long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
|
||||
long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
|
||||
|
@ -557,8 +557,7 @@ static size_t trim_len(struct mg_connection *c, size_t len) {
|
||||
}
|
||||
// Ensure the MTU isn't lower than the minimum allowed value
|
||||
if (ifp->mtu < min_mtu) {
|
||||
MG_ERROR(("MTU is lower than minimum possible value. Setting it to %d.",
|
||||
min_mtu));
|
||||
MG_ERROR(("MTU is lower than minimum, capping to %lu", min_mtu));
|
||||
ifp->mtu = (uint16_t) min_mtu;
|
||||
}
|
||||
// If the total packet size exceeds the MTU, trim the length
|
||||
@ -669,7 +668,9 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
|
||||
if (s->ttype != MIP_TTYPE_ACK) settmout(c, MIP_TTYPE_ACK);
|
||||
#endif
|
||||
|
||||
if (c->is_tls) {
|
||||
if (c->is_tls && c->is_tls_hs) {
|
||||
mg_tls_handshake(c);
|
||||
} else if (c->is_tls) {
|
||||
// TLS connection. Make room for decrypted data in c->recv
|
||||
io = &c->recv;
|
||||
if (io->size - io->len < pkt->pay.len &&
|
||||
@ -1083,7 +1084,6 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
|
||||
MG_VERBOSE(("%lu .. %c%c%c%c%c", c->id, c->is_tls ? 'T' : 't',
|
||||
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
|
||||
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c'));
|
||||
if (c->is_tls_hs) mg_tls_handshake(c);
|
||||
if (can_write(c)) write_conn(c);
|
||||
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
|
||||
init_closure(c);
|
||||
|
@ -31,3 +31,8 @@ void mg_tls_handshake(struct mg_connection *);
|
||||
// Private
|
||||
void mg_tls_ctx_init(struct mg_mgr *);
|
||||
void mg_tls_ctx_free(struct mg_mgr *);
|
||||
|
||||
// Low-level IO primives used by TLS layer
|
||||
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
||||
long mg_io_send(struct mg_connection *c, const void *buf, size_t len);
|
||||
long mg_io_recv(struct mg_connection *c, void *buf, size_t len);
|
||||
|
Loading…
Reference in New Issue
Block a user