From 4b630c452d238895385fb044e91b3496359a8dde Mon Sep 17 00:00:00 2001 From: danicampora Date: Tue, 20 Oct 2015 15:03:35 +0200 Subject: [PATCH] cc3200: Make socket.listen([backlog]) compliant with Python 3.5. --- cc3200/mods/modusocket.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cc3200/mods/modusocket.c b/cc3200/mods/modusocket.c index f7677ae31b..ad59493ea6 100644 --- a/cc3200/mods/modusocket.c +++ b/cc3200/mods/modusocket.c @@ -185,17 +185,23 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_bind_obj, socket_bind); -// method socket.listen(backlog) -STATIC mp_obj_t socket_listen(mp_obj_t self_in, mp_obj_t backlog) { - mod_network_socket_obj_t *self = self_in; +// method socket.listen([backlog]) +STATIC mp_obj_t socket_listen(mp_uint_t n_args, const mp_obj_t *args) { + mod_network_socket_obj_t *self = args[0]; + + int32_t backlog = 0; + if (n_args > 1) { + backlog = mp_obj_get_int(args[1]); + backlog = (backlog < 0) ? 0 : backlog; + } int _errno; - if (wlan_socket_listen(self, mp_obj_get_int(backlog), &_errno) != 0) { + if (wlan_socket_listen(self, backlog, &_errno) != 0) { nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(-_errno))); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(socket_listen_obj, socket_listen); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socket_listen_obj, 1, 2, socket_listen); // method socket.accept() STATIC mp_obj_t socket_accept(mp_obj_t self_in) {