Skip to content

Commit 9a692c3

Browse files
committed
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.
1 parent e778fc1 commit 9a692c3

File tree

1 file changed

+5
-0
lines changed
  • ports/esp32s2/common-hal/socketpool

1 file changed

+5
-0
lines changed

ports/esp32s2/common-hal/socketpool/Socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self,
103103
}
104104
if (available > 0) {
105105
status = esp_tls_conn_read(self->tcp, (void*) buf + received, available);
106+
if (status == 0) {
107+
// Reading zero when something is available indicates a closed
108+
// connection. (The available bytes could have been TLS internal.)
109+
break;
110+
}
106111
if (status > 0) {
107112
received += status;
108113
}

0 commit comments

Comments
 (0)