Exit faster on recv when TLS connection closed

When a TLS connection is closed by the server it usually sends a
notice. We see this incoming byte with lwip_ioctl and try to read
it. The read returns 0 but we keep trying anyway. Now, we quit
trying when we get zero back. If the connection was still alive
it'd either read a byte or delay until a byte could be read.
This commit is contained in:
Scott Shawcroft 2020-11-24 18:14:22 -08:00
parent e778fc1f87
commit 9a692c3222
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA

View File

@ -103,6 +103,11 @@ mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self,
}
if (available > 0) {
status = esp_tls_conn_read(self->tcp, (void*) buf + received, available);
if (status == 0) {
// Reading zero when something is available indicates a closed
// connection. (The available bytes could have been TLS internal.)
break;
}
if (status > 0) {
received += status;
}