3232#include "py/runtime.h"
3333#include "supervisor/shared/tick.h"
3434
35- #include "esp_log.h"
36- static const char * TAG = "socket" ;
37-
3835void common_hal_socketpool_socket_settimeout (socketpool_socket_obj_t * self , mp_uint_t timeout_ms ) {
3936 self -> timeout_ms = timeout_ms ;
4037}
@@ -49,7 +46,6 @@ bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const c
4946 tls_config = & self -> ssl_context -> ssl_config ;
5047 }
5148 int result = esp_tls_conn_new_sync (host , hostlen , port , tls_config , self -> tcp );
52- ESP_EARLY_LOGW (TAG , "connect result %d" , result );
5349 self -> connected = result >= 0 ;
5450 if (result < 0 ) {
5551 int esp_tls_code ;
@@ -58,8 +54,11 @@ bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const c
5854
5955 if (err == ESP_ERR_MBEDTLS_SSL_SETUP_FAILED ) {
6056 mp_raise_espidf_MemoryError ();
57+ } else if (ESP_ERR_MBEDTLS_SSL_HANDSHAKE_FAILED ) {
58+ // What should this error be?
59+ mp_raise_OSError_msg_varg (translate ("Failed SSL handshake" ));
6160 } else {
62- mp_raise_OSError_msg_varg (translate ("Unhandled ESP TLS error %d %d %x" ), esp_tls_code , flags , err );
61+ mp_raise_OSError_msg_varg (translate ("Unhandled ESP TLS error %d %d %x %d " ), esp_tls_code , flags , err , result );
6362 }
6463 }
6564
@@ -99,37 +98,31 @@ mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self,
9998 // and between encrypted TLS blocks.
10099 int status = lwip_ioctl (sockfd , FIONREAD , & available );
101100 if (status < 0 ) {
102- // ESP_EARLY_LOGW(TAG, "ioctl fail. socket %d status %d errno %d available %d", sockfd, status, errno, available);
103101 last_read = status ;
104102 break ;
105103 }
106104 }
107- // ESP_EARLY_LOGW(TAG, "available %d", available);
108105 size_t remaining = len - received ;
109106 if (available > remaining ) {
110107 available = remaining ;
111108 }
112109 if (available > 0 ) {
113110 last_read = esp_tls_conn_read (self -> tcp , (void * ) buf + received , available );
114- // ESP_EARLY_LOGW(TAG, "read %d out of %d", last_read, available);
115111 received += last_read ;
116112 }
117113 }
118114
119115 if (last_read == 0 ) {
120116 // socket closed
121- ESP_EARLY_LOGW (TAG , "receive close %d %d" , received , len );
122117 common_hal_socketpool_socket_close (self );
123118 }
124119 if (last_read < 0 ) {
125- // ESP_EARLY_LOGI(TAG, "received %d", received);
126120 mp_raise_BrokenPipeError ();
127121 }
128122 return received ;
129123}
130124
131125void common_hal_socketpool_socket_close (socketpool_socket_obj_t * self ) {
132- // ESP_EARLY_LOGW(TAG, "close");
133126 if (self -> connected ) {
134127 self -> connected = false;
135128 }
@@ -144,6 +137,10 @@ void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self) {
144137}
145138
146139bool common_hal_socketpool_socket_get_closed (socketpool_socket_obj_t * self ) {
147- // ESP_EARLY_LOGW(TAG, "tcp %p", self->tcp);
148140 return self -> tcp == NULL ;
149141}
142+
143+
144+ mp_uint_t common_hal_socketpool_socket_get_hash (socketpool_socket_obj_t * self ) {
145+ return self -> num ;
146+ }
0 commit comments