From 5cb91afb9b3b34bbf0ee022a3f69af90c01d1d54 Mon Sep 17 00:00:00 2001 From: PTH Date: Fri, 12 Feb 2021 15:08:02 +0100 Subject: [PATCH] zephyr/modusocket: Fix parameter in calls to net_context_get_XXX(). The following simple usocket example throws an error EINVAL on connect import usocket s = usocket.socket() s.connect(usocket.getaddrinfo('www.micropython.org', 80)[0][-1]) Traceback (most recent call last): File "", line 1, in OSError: [Errno 22] EINVAL Fixing the context parameter in calls of net_context_get_family() and net_context_get_type(), the connect works fine. Tested on a nucleo_h743zi board. --- ports/zephyr/modusocket.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ports/zephyr/modusocket.c b/ports/zephyr/modusocket.c index 6c900753c8..f9fc96a2b1 100644 --- a/ports/zephyr/modusocket.c +++ b/ports/zephyr/modusocket.c @@ -79,7 +79,8 @@ STATIC void parse_inet_addr(socket_obj_t *socket, mp_obj_t addr_in, struct socka mp_obj_t *addr_items; mp_obj_get_array_fixed_n(addr_in, 2, &addr_items); - sockaddr_in->sin_family = net_context_get_family((void *)socket->ctx); + void *context = zsock_get_context_object(socket->ctx); + sockaddr_in->sin_family = net_context_get_family(context); RAISE_ERRNO(net_addr_pton(sockaddr_in->sin_family, mp_obj_str_get_str(addr_items[0]), &sockaddr_in->sin_addr)); sockaddr_in->sin_port = htons(mp_obj_get_int(addr_items[1])); } @@ -119,8 +120,8 @@ STATIC void socket_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin if (self->ctx == -1) { mp_printf(print, ""); } else { - struct net_context *ctx = (void *)self->ctx; - mp_printf(print, "", ctx, net_context_get_type(ctx)); + void *context = zsock_get_context_object(self->ctx); + mp_printf(print, "", self->ctx, net_context_get_type(context)); } }