Merge pull request #3598 from cesanta/throttlebed

handle partial send after throttled
This commit is contained in:
Sergio R. Caprile authored and GitHub committed 2026-06-11 07:51:10 -03:00
commit a4d5a77afd
2 files changed
+12 -16

No files matched your search

+6 -8
View File
@@ -19950,27 +19950,25 @@ long mg_tls_send(struct mg_connection *c, const void *buf, size_t len) {
: mbedtls_ssl_write(&tls->ssl, (unsigned char *) buf, : mbedtls_ssl_write(&tls->ssl, (unsigned char *) buf,
len); // encrypt current data len); // encrypt current data
#if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET) #if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
if (n == MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET) { if (n == MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
c->is_tls_throttled = was_throttled;
return MG_IO_WAIT; return MG_IO_WAIT;
}
#endif #endif
c->is_tls_throttled = c->is_tls_throttled =
(n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE); (n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE);
if (was_throttled) return MG_IO_WAIT; // flushed throttled data instead if (was_throttled && c->is_tls_throttled) return MG_IO_WAIT; // no changes
if (c->is_tls_throttled) { if (c->is_tls_throttled) {
tls->throttled_buf = tls->throttled_buf =
(unsigned char *) buf; // MbedTLS code actually ignores (unsigned char *) buf; // MbedTLS code actually ignores
tls->throttled_len = len; // these, but let's play API rules tls->throttled_len = len; // these, but let's play API rules
return (long) len; // already encripted that when throttled return MG_IO_WAIT;
} // if last chunk fails to be sent, it needs to be flushed }
if (n <= 0) return MG_IO_ERR; if (n <= 0) return MG_IO_ERR;
return n; return n;
} }
void mg_tls_flush(struct mg_connection *c) { void mg_tls_flush(struct mg_connection *c) {
struct mg_tls *tls = (struct mg_tls *) c->tls; struct mg_tls *tls = (struct mg_tls *) c->tls;
if (c->is_tls_throttled) { if (c->is_tls_throttled && c->is_draining) {
long n = long n =
mbedtls_ssl_write(&tls->ssl, tls->throttled_buf, tls->throttled_len); mbedtls_ssl_write(&tls->ssl, tls->throttled_buf, tls->throttled_len);
#if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET) #if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
+6 -8
View File
@@ -222,27 +222,25 @@ long mg_tls_send(struct mg_connection *c, const void *buf, size_t len) {
: mbedtls_ssl_write(&tls->ssl, (unsigned char *) buf, : mbedtls_ssl_write(&tls->ssl, (unsigned char *) buf,
len); // encrypt current data len); // encrypt current data
#if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET) #if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
if (n == MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET) { if (n == MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
c->is_tls_throttled = was_throttled;
return MG_IO_WAIT; return MG_IO_WAIT;
}
#endif #endif
c->is_tls_throttled = c->is_tls_throttled =
(n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE); (n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE);
if (was_throttled) return MG_IO_WAIT; // flushed throttled data instead if (was_throttled && c->is_tls_throttled) return MG_IO_WAIT; // no changes
if (c->is_tls_throttled) { if (c->is_tls_throttled) {
tls->throttled_buf = tls->throttled_buf =
(unsigned char *) buf; // MbedTLS code actually ignores (unsigned char *) buf; // MbedTLS code actually ignores
tls->throttled_len = len; // these, but let's play API rules tls->throttled_len = len; // these, but let's play API rules
return (long) len; // already encripted that when throttled return MG_IO_WAIT;
} // if last chunk fails to be sent, it needs to be flushed }
if (n <= 0) return MG_IO_ERR; if (n <= 0) return MG_IO_ERR;
return n; return n;
} }
void mg_tls_flush(struct mg_connection *c) { void mg_tls_flush(struct mg_connection *c) {
struct mg_tls *tls = (struct mg_tls *) c->tls; struct mg_tls *tls = (struct mg_tls *) c->tls;
if (c->is_tls_throttled) { if (c->is_tls_throttled && c->is_draining) {
long n = long n =
mbedtls_ssl_write(&tls->ssl, tls->throttled_buf, tls->throttled_len); mbedtls_ssl_write(&tls->ssl, tls->throttled_buf, tls->throttled_len);
#if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET) #if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)