Skip to content

Commit 047af9b

Browse files
committed
cc3200: Remove socket.timeout class, use OSError(ETIMEDOUT) instead.
socket.timeout is a subclass of OSError, and using the latter is more efficient than having a dedicated class. The argument of OSError is ETIMEDOUT so the error can be distinguished from other kinds of OSErrors. This follows how the esp8266 port does it.
1 parent d03f089 commit 047af9b

2 files changed

Lines changed: 2 additions & 6 deletions

File tree

cc3200/mods/modusocket.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ STATIC mp_obj_t socket_recv(mp_obj_t self_in, mp_obj_t len_in) {
520520
mp_int_t ret = wlan_socket_recv(self, (byte*)vstr.buf, len, &_errno);
521521
if (ret < 0) {
522522
if (_errno == MP_EAGAIN && self->sock_base.has_timeout) {
523-
mp_raise_msg(&mp_type_TimeoutError, "timed out");
523+
mp_raise_OSError(MP_ETIMEDOUT);
524524
}
525525
mp_raise_OSError(-_errno);
526526
}
@@ -566,7 +566,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
566566
mp_int_t ret = wlan_socket_recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno);
567567
if (ret < 0) {
568568
if (_errno == MP_EAGAIN && self->sock_base.has_timeout) {
569-
mp_raise_msg(&mp_type_TimeoutError, "timed out");
569+
mp_raise_OSError(MP_ETIMEDOUT);
570570
}
571571
mp_raise_OSError(-_errno);
572572
}
@@ -763,9 +763,6 @@ STATIC const mp_map_elem_t mp_module_usocket_globals_table[] = {
763763
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&socket_type },
764764
{ MP_OBJ_NEW_QSTR(MP_QSTR_getaddrinfo), (mp_obj_t)&mod_usocket_getaddrinfo_obj },
765765

766-
// class exceptions
767-
{ MP_OBJ_NEW_QSTR(MP_QSTR_timeout), (mp_obj_t)&mp_type_TimeoutError },
768-
769766
// class constants
770767
{ MP_OBJ_NEW_QSTR(MP_QSTR_AF_INET), MP_OBJ_NEW_SMALL_INT(SL_AF_INET) },
771768

cc3200/mpconfigport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
#define MICROPY_VFS (1)
8080
#define MICROPY_VFS_FAT (1)
8181
#define MICROPY_PY_ASYNC_AWAIT (0)
82-
#define MICROPY_PY_BUILTINS_TIMEOUTERROR (1)
8382
#define MICROPY_PY_ALL_SPECIAL_METHODS (1)
8483
#define MICROPY_PY_BUILTINS_HELP (1)
8584
#define MICROPY_PY_BUILTINS_HELP_TEXT cc3200_help_text

0 commit comments

Comments
 (0)