diff --git a/mongoose.c b/mongoose.c index e13bcf7c..50c99cd6 100644 --- a/mongoose.c +++ b/mongoose.c @@ -5238,7 +5238,8 @@ size_t mg_tls_pending(struct mg_connection *c) { long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) { struct mg_tls *tls = (struct mg_tls *) c->tls; long n = mbedtls_ssl_read(&tls->ssl, (unsigned char *) buf, len); - if (n == MBEDTLS_ERR_SSL_WANT_READ) return MG_IO_WAIT; + if (n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE) + return MG_IO_WAIT; if (n <= 0) return MG_IO_ERR; return n; } @@ -5246,7 +5247,8 @@ long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) { long mg_tls_send(struct mg_connection *c, const void *buf, size_t len) { struct mg_tls *tls = (struct mg_tls *) c->tls; long n = mbedtls_ssl_write(&tls->ssl, (unsigned char *) buf, len); - if (n == MBEDTLS_ERR_SSL_WANT_WRITE) return MG_IO_WAIT; + if (n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE) + return MG_IO_WAIT; if (n <= 0) return MG_IO_ERR; return n; } diff --git a/src/tls_mbed.c b/src/tls_mbed.c index 8caf4d65..edfa91a4 100644 --- a/src/tls_mbed.c +++ b/src/tls_mbed.c @@ -185,7 +185,8 @@ size_t mg_tls_pending(struct mg_connection *c) { long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) { struct mg_tls *tls = (struct mg_tls *) c->tls; long n = mbedtls_ssl_read(&tls->ssl, (unsigned char *) buf, len); - if (n == MBEDTLS_ERR_SSL_WANT_READ) return MG_IO_WAIT; + if (n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE) + return MG_IO_WAIT; if (n <= 0) return MG_IO_ERR; return n; } @@ -193,7 +194,8 @@ long mg_tls_recv(struct mg_connection *c, void *buf, size_t len) { long mg_tls_send(struct mg_connection *c, const void *buf, size_t len) { struct mg_tls *tls = (struct mg_tls *) c->tls; long n = mbedtls_ssl_write(&tls->ssl, (unsigned char *) buf, len); - if (n == MBEDTLS_ERR_SSL_WANT_WRITE) return MG_IO_WAIT; + if (n == MBEDTLS_ERR_SSL_WANT_READ || n == MBEDTLS_ERR_SSL_WANT_WRITE) + return MG_IO_WAIT; if (n <= 0) return MG_IO_ERR; return n; }