mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-17 19:30:36 +00:00
Merge pull request #3598 from cesanta/throttlebed
handle partial send after throttled
This commit is contained in:
2 files changed
+12
-16
No files matched your search
+6
-8
@@ -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
@@ -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)
|
||||||
|
|||||||
Reference in new issue
Block a user