Skip to content

Commit 605c39c

Browse files
committed
Fix ssl.SSLSocket bind() error checking
Non-ssl sockets now return size_t error numbers, not bool. Fixes #8947
1 parent 33b5cc6 commit 605c39c

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

shared-bindings/ssl/SSLSocket.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ STATIC mp_obj_t ssl_sslsocket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
103103
mp_raise_ValueError(MP_ERROR_TEXT("port must be >= 0"));
104104
}
105105

106-
bool ok = common_hal_ssl_sslsocket_bind(self, host, hostlen, (uint32_t)port);
107-
if (!ok) {
108-
mp_raise_ValueError(MP_ERROR_TEXT("Error: Failure to bind"));
106+
size_t error = common_hal_ssl_sslsocket_bind(self, host, hostlen, (uint32_t)port);
107+
if (error != 0) {
108+
mp_raise_OSError(error);
109109
}
110110

111111
return mp_const_none;

shared-bindings/ssl/SSLSocket.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SSL_SSLSOCKET_H
28-
#define MICROPY_INCLUDED_SHARED_BINDINGS_SSL_SSLSOCKET_H
27+
#pragma once
2928

3029
#if CIRCUITPY_SSL_MBEDTLS
3130
#include "shared-module/ssl/SSLSocket.h"
@@ -36,7 +35,7 @@
3635
extern const mp_obj_type_t ssl_sslsocket_type;
3736

3837
ssl_sslsocket_obj_t *common_hal_ssl_sslsocket_accept(ssl_sslsocket_obj_t *self, uint8_t *ip, uint32_t *port);
39-
bool common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port);
38+
size_t common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port);
4039
void common_hal_ssl_sslsocket_close(ssl_sslsocket_obj_t *self);
4140
void common_hal_ssl_sslsocket_connect(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port);
4241
bool common_hal_ssl_sslsocket_get_closed(ssl_sslsocket_obj_t *self);
@@ -45,5 +44,3 @@ bool common_hal_ssl_sslsocket_listen(ssl_sslsocket_obj_t *self, int backlog);
4544
mp_uint_t common_hal_ssl_sslsocket_recv_into(ssl_sslsocket_obj_t *self, uint8_t *buf, uint32_t len);
4645
mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t *self, const uint8_t *buf, uint32_t len);
4746
void common_hal_ssl_sslsocket_settimeout(ssl_sslsocket_obj_t *self, uint32_t timeout_ms);
48-
49-
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SSL_SSLSOCKET_H

shared-module/ssl/SSLSocket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ mp_uint_t common_hal_ssl_sslsocket_send(ssl_sslsocket_obj_t *self, const uint8_t
302302
mp_raise_OSError(ret);
303303
}
304304

305-
bool common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) {
305+
size_t common_hal_ssl_sslsocket_bind(ssl_sslsocket_obj_t *self, const char *host, size_t hostlen, uint32_t port) {
306306
return common_hal_socketpool_socket_bind(self->sock, host, hostlen, port);
307307
}
308308

0 commit comments

Comments
 (0)