Fix hash, close, error bugs
This commit is contained in:
parent
a724f6f954
commit
8277ffca86
@ -3,7 +3,6 @@
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||
* Copyright (c) 2020 Lucian Copeland for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@ -198,10 +197,6 @@ bool common_hal_socketpool_socket_get_connected(socketpool_socket_obj_t* self) {
|
||||
return self->connected;
|
||||
}
|
||||
|
||||
mp_uint_t common_hal_socketpool_socket_get_hash(socketpool_socket_obj_t* self) {
|
||||
return self->num;
|
||||
}
|
||||
|
||||
bool common_hal_socketpool_socket_listen(socketpool_socket_obj_t* self, int backlog) {
|
||||
return lwip_listen(self->num, backlog) == 0;
|
||||
}
|
||||
@ -289,7 +284,7 @@ mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t* self, const
|
||||
}
|
||||
|
||||
if (sent < 0) {
|
||||
mp_raise_OSError(MP_ENOTCONN);
|
||||
mp_raise_OSError(errno);
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
|
||||
* Copyright (c) 2021 Lucian Copeland for Adafruit Industries
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@ -51,7 +52,7 @@ bool common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t* self,
|
||||
}
|
||||
|
||||
void common_hal_ssl_sslsocket_close(ssl_sslsocket_obj_t* self) {
|
||||
self->sock->connected = false;
|
||||
common_hal_socketpool_socket_close(self->sock);
|
||||
esp_tls_conn_destroy(self->tls);
|
||||
self->tls = NULL;
|
||||
}
|
||||
@ -99,10 +100,6 @@ bool common_hal_ssl_sslsocket_get_connected(ssl_sslsocket_obj_t* self) {
|
||||
return self->sock->connected;
|
||||
}
|
||||
|
||||
mp_uint_t common_hal_ssl_sslsocket_get_hash(ssl_sslsocket_obj_t* self) {
|
||||
return self->sock->num;
|
||||
}
|
||||
|
||||
bool common_hal_ssl_sslsocket_listen(ssl_sslsocket_obj_t* self, int backlog) {
|
||||
return common_hal_socketpool_socket_listen(self->sock, backlog);
|
||||
}
|
||||
@ -163,7 +160,17 @@ mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t* self, const uint8_t
|
||||
sent = esp_tls_conn_write(self->tls, buf, len);
|
||||
|
||||
if (sent < 0) {
|
||||
mp_raise_OSError(MP_ENOTCONN);
|
||||
int esp_tls_code;
|
||||
int flags;
|
||||
esp_err_t err = esp_tls_get_and_clear_last_error(self->tls->error_handle, &esp_tls_code, &flags);
|
||||
|
||||
if (err == ESP_ERR_MBEDTLS_SSL_SETUP_FAILED) {
|
||||
mp_raise_espidf_MemoryError();
|
||||
} else if (ESP_ERR_MBEDTLS_SSL_HANDSHAKE_FAILED) {
|
||||
mp_raise_OSError_msg_varg(translate("Failed SSL handshake"));
|
||||
} else {
|
||||
mp_raise_OSError_msg_varg(translate("Unhandled ESP TLS error %d %d %x %d"), esp_tls_code, flags, err, sent);
|
||||
}
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_settimeout_obj, socketpool_so
|
||||
STATIC mp_obj_t socketpool_socket_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
switch (op) {
|
||||
case MP_UNARY_OP_HASH: {
|
||||
return MP_OBJ_NEW_SMALL_INT(common_hal_socketpool_socket_get_hash(MP_OBJ_TO_PTR(self_in)));
|
||||
return mp_obj_id(self_in);
|
||||
}
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
|
@ -37,7 +37,6 @@ void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self);
|
||||
bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const char* host, size_t hostlen, mp_int_t port);
|
||||
bool common_hal_socketpool_socket_get_closed(socketpool_socket_obj_t* self);
|
||||
bool common_hal_socketpool_socket_get_connected(socketpool_socket_obj_t* self);
|
||||
mp_uint_t common_hal_socketpool_socket_get_hash(socketpool_socket_obj_t* self);
|
||||
mp_uint_t common_hal_socketpool_socket_get_timeout(socketpool_socket_obj_t* self);
|
||||
bool common_hal_socketpool_socket_listen(socketpool_socket_obj_t* self, int backlog);
|
||||
mp_uint_t common_hal_socketpool_socket_recvfrom_into(socketpool_socket_obj_t* self,
|
||||
|
@ -286,7 +286,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(ssl_sslsocket_setblocking_obj, ssl_sslsocket_se
|
||||
STATIC mp_obj_t ssl_sslsocket_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
switch (op) {
|
||||
case MP_UNARY_OP_HASH: {
|
||||
return MP_OBJ_NEW_SMALL_INT(common_hal_ssl_sslsocket_get_hash(MP_OBJ_TO_PTR(self_in)));
|
||||
return mp_obj_id(self_in);
|
||||
}
|
||||
default:
|
||||
return MP_OBJ_NULL; // op not supported
|
||||
|
@ -37,7 +37,6 @@ void common_hal_ssl_sslsocket_close(ssl_sslsocket_obj_t* self);
|
||||
bool common_hal_ssl_sslsocket_connect(ssl_sslsocket_obj_t* self, const char* host, size_t hostlen, mp_int_t port);
|
||||
bool common_hal_ssl_sslsocket_get_closed(ssl_sslsocket_obj_t* self);
|
||||
bool common_hal_ssl_sslsocket_get_connected(ssl_sslsocket_obj_t* self);
|
||||
mp_uint_t common_hal_ssl_sslsocket_get_hash(ssl_sslsocket_obj_t* self);
|
||||
bool common_hal_ssl_sslsocket_listen(ssl_sslsocket_obj_t* self, int backlog);
|
||||
mp_uint_t common_hal_ssl_sslsocket_recv_into(ssl_sslsocket_obj_t* self, const uint8_t* buf, mp_uint_t len);
|
||||
mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t* self, const uint8_t* buf, mp_uint_t len);
|
||||
|
Loading…
Reference in New Issue
Block a user