From 7fd73c7d39399042ad6ed3bfe5b1c64da05c964e Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 28 Oct 2020 18:08:31 -0700 Subject: [PATCH 1/6] Initial UDP work. Need to test --- ports/esp32s2/common-hal/socketpool/Socket.c | 63 +++++++++- .../common-hal/socketpool/SocketPool.c | 7 +- shared-bindings/socketpool/Socket.c | 118 ++++++++---------- shared-bindings/socketpool/Socket.h | 4 + 4 files changed, 120 insertions(+), 72 deletions(-) diff --git a/ports/esp32s2/common-hal/socketpool/Socket.c b/ports/esp32s2/common-hal/socketpool/Socket.c index 0a994c604e..7f031521f7 100644 --- a/ports/esp32s2/common-hal/socketpool/Socket.c +++ b/ports/esp32s2/common-hal/socketpool/Socket.c @@ -121,16 +121,77 @@ mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self, return received; } +mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t* self, + const char* host, size_t hostlen, uint8_t port, const uint8_t* buf, mp_uint_t len) { + + struct sockaddr_in dest_addr; + dest_addr.sin_addr.s_addr = inet_addr(HOST_IP_ADDR); + dest_addr.sin_family = AF_INET; + dest_addr.sin_port = htons(port); + + + const struct addrinfo hints = { + .ai_family = AF_INET, + .ai_socktype = SOCK_STREAM, + }; + struct addrinfo *res; + int err = getaddrinfo(host, NULL, &hints, &res); + if (err != 0 || res == NULL) { + return mp_const_none; + } + + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + struct in_addr *addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; + #pragma GCC diagnostic pop + char ip_str[IP4ADDR_STRLEN_MAX]; + inet_ntoa_r(*addr, ip_str, IP4ADDR_STRLEN_MAX); + mp_obj_t ip_obj = mp_obj_new_str(ip_str, strlen(ip_str)); + freeaddrinfo(res); + + + + int err = lwip_sendto(self->num, buf, len, 0 /* flags */, + (struct sockaddr *)&dest_addr, sizeof(dest_addr)); +} + +mp_uint_t common_hal_socketpool_socket_recvfrom_into(socketpool_socket_obj_t* self, + const uint8_t* buf, mp_uint_t len, uint8_t* ip, uint8_t port) { + + const struct addrinfo hints = { + .ai_family = AF_INET, + .ai_socktype = SOCK_STREAM, + }; + struct addrinfo *res; + int err = getaddrinfo(host, NULL, &hints, &res); + if (err != 0 || res == NULL) { + return mp_const_none; + } + + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + struct in_addr *addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; + #pragma GCC diagnostic pop + char ip_str[IP4ADDR_STRLEN_MAX]; + inet_ntoa_r(*addr, ip_str, IP4ADDR_STRLEN_MAX); + mp_obj_t ip_obj = mp_obj_new_str(ip_str, strlen(ip_str)); + freeaddrinfo(res); +} + void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self) { self->connected = false; if (self->tcp != NULL) { esp_tls_conn_destroy(self->tcp); self->tcp = NULL; } + if (self->num >= 0) { + lwip_shutdown(self->num, 0); + lwip_close(self->num); + } } bool common_hal_socketpool_socket_get_closed(socketpool_socket_obj_t* self) { - return self->tcp == NULL; + return self->tcp == NULL && self->num < 0; } diff --git a/ports/esp32s2/common-hal/socketpool/SocketPool.c b/ports/esp32s2/common-hal/socketpool/SocketPool.c index 1d4d04b034..3bec5f337f 100644 --- a/ports/esp32s2/common-hal/socketpool/SocketPool.c +++ b/ports/esp32s2/common-hal/socketpool/SocketPool.c @@ -61,15 +61,14 @@ socketpool_socket_obj_t* common_hal_socketpool_socket(socketpool_socketpool_obj_ socket_type = SOCK_RAW; } - if (socket_type == SOCK_DGRAM || socket_type == SOCK_RAW || - addr_family == AF_INET6 || ipproto == IPPROTO_IPV6) { - mp_raise_NotImplementedError(translate("Only IPv4 SOCK_STREAM sockets supported")); + if (addr_family == AF_INET6 || ipproto == IPPROTO_IPV6) { + mp_raise_NotImplementedError(translate("Only IPv4 sockets supported")); } int socknum = -1; esp_tls_t* tcp_handle = NULL; if (socket_type == SOCK_DGRAM || socket_type == SOCK_RAW) { - // socknum = lwip_socket(addr_family, socket_type, ipproto); + socknum = lwip_socket(addr_family, socket_type, ipproto); } else { tcp_handle = esp_tls_init(); diff --git a/shared-bindings/socketpool/Socket.c b/shared-bindings/socketpool/Socket.c index e7b31842d2..2e369d442b 100644 --- a/shared-bindings/socketpool/Socket.c +++ b/shared-bindings/socketpool/Socket.c @@ -274,79 +274,63 @@ STATIC mp_obj_t socketpool_socket_recv_into(size_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socketpool_socket_recv_into_obj, 2, 3, socketpool_socket_recv_into); -// //| def sendto(self, bytes: ReadableBuffer, address: tuple) -> int: -// //| """Send some bytes to a specific address. -// //| Suits sockets of type SOCK_DGRAM -// //| -// //| :param ~bytes bytes: some bytes to send -// //| :param ~tuple address: tuple of (remote_address, remote_port)""" -// //| ... -// //| +//| def sendto(self, bytes: ReadableBuffer, address: tuple) -> int: +//| """Send some bytes to a specific address. +//| Suits sockets of type SOCK_DGRAM +//| +//| :param ~bytes bytes: some bytes to send +//| :param ~tuple address: tuple of (remote_address, remote_port)""" +//| ... +//| -// STATIC mp_obj_t socketpool_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { -// // mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t socketpool_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_in) { + socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); -// // // get the data -// // mp_buffer_info_t bufinfo; -// // mp_get_buffer_raise(data_in, &bufinfo, MP_BUFFER_READ); + // get the data + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(data_in, &bufinfo, MP_BUFFER_READ); -// // // get address -// // uint8_t ip[MOD_NETWORK_IPADDR_BUF_SIZE]; -// // mp_uint_t port = netutils_parse_inet_addr(addr_in, ip, NETUTILS_BIG); + mp_obj_t *addr_items; + mp_obj_get_array_fixed_n(addr_in, 2, &addr_items); -// // // check if we need to select a NIC -// // socket_select_nic(self, ip); + size_t hostlen; + const char* host = mp_obj_str_get_data(addr_items[0], &hostlen); + mp_int_t port = mp_obj_get_int(addr_items[1]); -// // // call the NIC to sendto -// // int _errno; -// // mp_int_t ret = self->nic_type->sendto(self, bufinfo.buf, bufinfo.len, ip, port, &_errno); -// // if (ret == -1) { -// // mp_raise_OSError(_errno); -// // } -// mp_int_t ret = 0; + mp_int_t ret = common_hal_socketpool_socket_sendto(self, host, hostlen, port, bufinfo.buf, bufinfo.len); + if (!ok) { + mp_raise_OSError(0); + } -// return mp_obj_new_int(ret); -// } -// STATIC MP_DEFINE_CONST_FUN_OBJ_3(socketpool_socket_sendto_obj, socketpool_socket_sendto); + return mp_obj_new_int_from_uint(ret); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_3(socketpool_socket_sendto_obj, socketpool_socket_sendto); -// //| def recvfrom(self, bufsize: int) -> Tuple[bytes, tuple]: -// //| """Reads some bytes from the connected remote address. -// //| Suits sockets of type SOCK_STREAM -// //| -// //| Returns a tuple containing -// //| * a bytes() of length <= bufsize -// //| * a remote_address, which is a tuple of ip address and port number -// //| -// //| :param ~int bufsize: maximum number of bytes to receive""" -// //| ... -// //| +//| def recvfrom_into(self, buffer) -> Tuple[int, tuple]: +//| """Reads some bytes from a remote address. +//| +//| Returns a tuple containing +//| * the number of bytes received into the given buffer +//| * a remote_address, which is a tuple of ip address and port number +//| +//| :param object buffer: buffer to read into""" +//| ... +//| +STATIC mp_obj_t socketpool_socket_recvfrom_into(mp_obj_t self_in, mp_obj_t data_in) { + socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(data_in, &bufinfo, MP_BUFFER_WRITE); -// STATIC mp_obj_t socketpool_socket_recvfrom_into(mp_obj_t self_in, mp_obj_t len_in) { -// // mod_network_socket_obj_t *self = MP_OBJ_TO_PTR(self_in); -// // if (self->nic == MP_OBJ_NULL) { -// // // not connected -// // mp_raise_OSError(MP_ENOTCONN); -// // } -// // vstr_t vstr; -// // vstr_init_len(&vstr, mp_obj_get_int(len_in)); -// // byte ip[4]; -// // mp_uint_t port; -// // int _errno; -// // mp_int_t ret = self->nic_type->recvfrom(self, (byte*)vstr.buf, vstr.len, ip, &port, &_errno); -// // if (ret == -1) { -// // mp_raise_OSError(_errno); -// // } -// mp_obj_t tuple[2]; -// // if (ret == 0) { -// // tuple[0] = mp_const_empty_bytes; -// // } else { -// // vstr.len = ret; -// // tuple[0] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr); -// // } -// // tuple[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG); -// return mp_obj_new_tuple(2, tuple); -// } -// STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_recvfrom_into_obj, socketpool_socket_recvfrom_into); + byte ip[4]; + mp_uint_t port; + mp_int_t ret = common_hal_socketpool_socket_recvfrom_into(self, + (byte*)bufinfo.buf, len, ip, &port); + mp_obj_t tuple_contents[2]; + tuple_contents[0] = mp_obj_new_int_from_uint(ret); + tuple_contents[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG); + return mp_obj_new_tuple(2, tuple); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_recvfrom_into_obj, socketpool_socket_recvfrom_into); // //| def setsockopt(self, level: int, optname: int, value: int) -> None: // //| """Sets socket options""" @@ -449,8 +433,8 @@ STATIC const mp_rom_map_elem_t socketpool_socket_locals_dict_table[] = { // { MP_ROM_QSTR(MP_QSTR_accept), MP_ROM_PTR(&socketpool_socket_accept_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&socketpool_socket_connect_obj) }, { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&socketpool_socket_send_obj) }, - // { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socketpool_socket_sendto_obj) }, - // { MP_ROM_QSTR(MP_QSTR_recvfrom_into), MP_ROM_PTR(&socketpool_socket_recvfrom_into_obj) }, + { MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socketpool_socket_sendto_obj) }, + { MP_ROM_QSTR(MP_QSTR_recvfrom_into), MP_ROM_PTR(&socketpool_socket_recvfrom_into_obj) }, { MP_ROM_QSTR(MP_QSTR_recv_into), MP_ROM_PTR(&socketpool_socket_recv_into_obj) }, // { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socketpool_socket_setsockopt_obj) }, { MP_ROM_QSTR(MP_QSTR_settimeout), MP_ROM_PTR(&socketpool_socket_settimeout_obj) }, diff --git a/shared-bindings/socketpool/Socket.h b/shared-bindings/socketpool/Socket.h index f0be95c925..72a4c9e3c3 100644 --- a/shared-bindings/socketpool/Socket.h +++ b/shared-bindings/socketpool/Socket.h @@ -35,6 +35,10 @@ void common_hal_socketpool_socket_settimeout(socketpool_socket_obj_t* self, mp_u bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const char* host, size_t hostlen, mp_int_t port); mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len); mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len); +mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t* self, + const uint8_t* host, size_t hostlen, uint8_t port, const uint8_t* buf, mp_uint_t len); +mp_uint_t common_hal_socketpool_socket_recvfrom_into(socketpool_socket_obj_t* self, + const uint8_t* buf, mp_uint_t len, uint8_t* ip, uint8_t port); void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self); bool common_hal_socketpool_socket_get_closed(socketpool_socket_obj_t* self); bool common_hal_socketpool_socket_get_connected(socketpool_socket_obj_t* self); From 0bbdf05936c1b36bee6ef4f9f81bd3b9ea40fbc6 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Fri, 13 Nov 2020 13:12:07 -0500 Subject: [PATCH 2/6] Implement recvfrom_into and sendto for UDP --- ports/esp32s2/Makefile | 1 + ports/esp32s2/common-hal/socketpool/Socket.c | 86 ++++++++++---------- shared-bindings/socketpool/Socket.c | 8 +- shared-bindings/socketpool/Socket.h | 4 +- 4 files changed, 52 insertions(+), 47 deletions(-) diff --git a/ports/esp32s2/Makefile b/ports/esp32s2/Makefile index 55d6e91d44..a2e6cb73d9 100644 --- a/ports/esp32s2/Makefile +++ b/ports/esp32s2/Makefile @@ -188,6 +188,7 @@ SRC_C += \ lib/utils/pyexec.c \ lib/utils/stdout_helpers.c \ lib/utils/sys_stdio_mphal.c \ + lib/netutils/netutils.c \ peripherals/pcnt.c \ peripherals/pins.c \ peripherals/rmt.c \ diff --git a/ports/esp32s2/common-hal/socketpool/Socket.c b/ports/esp32s2/common-hal/socketpool/Socket.c index de9e6ad31b..937d199f21 100644 --- a/ports/esp32s2/common-hal/socketpool/Socket.c +++ b/ports/esp32s2/common-hal/socketpool/Socket.c @@ -32,6 +32,11 @@ #include "py/runtime.h" #include "supervisor/shared/tick.h" +#include "components/lwip/lwip/src/include/lwip/err.h" +#include "components/lwip/lwip/src/include/lwip/sockets.h" +#include "components/lwip/lwip/src/include/lwip/sys.h" +#include "components/lwip/lwip/src/include/lwip/netdb.h" + void common_hal_socketpool_socket_settimeout(socketpool_socket_obj_t* self, mp_uint_t timeout_ms) { self->timeout_ms = timeout_ms; } @@ -122,58 +127,55 @@ mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self, mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t* self, const char* host, size_t hostlen, uint8_t port, const uint8_t* buf, mp_uint_t len) { + // Get the IP address string + const struct addrinfo hints = { + .ai_family = AF_INET, + .ai_socktype = SOCK_STREAM, + }; + struct addrinfo *result; + int error = lwip_getaddrinfo(host, NULL, &hints, &result); + if (error != 0 || result == NULL) { + return 0; + } + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + struct in_addr *addr = &((struct sockaddr_in *)result->ai_addr)->sin_addr; + #pragma GCC diagnostic pop + char ip_str[IP4ADDR_STRLEN_MAX]; + inet_ntoa_r(*addr, ip_str, IP4ADDR_STRLEN_MAX); + freeaddrinfo(result); + + // Set parameters struct sockaddr_in dest_addr; - dest_addr.sin_addr.s_addr = inet_addr(HOST_IP_ADDR); + dest_addr.sin_addr.s_addr = inet_addr((const char *)ip_str); dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(port); - - const struct addrinfo hints = { - .ai_family = AF_INET, - .ai_socktype = SOCK_STREAM, - }; - struct addrinfo *res; - int err = getaddrinfo(host, NULL, &hints, &res); - if (err != 0 || res == NULL) { - return mp_const_none; + int bytes_sent = lwip_sendto(self->num, buf, len, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); + if (bytes_sent < 0) { + mp_raise_BrokenPipeError(); + return 0; } - - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wcast-align" - struct in_addr *addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; - #pragma GCC diagnostic pop - char ip_str[IP4ADDR_STRLEN_MAX]; - inet_ntoa_r(*addr, ip_str, IP4ADDR_STRLEN_MAX); - mp_obj_t ip_obj = mp_obj_new_str(ip_str, strlen(ip_str)); - freeaddrinfo(res); - - - - int err = lwip_sendto(self->num, buf, len, 0 /* flags */, - (struct sockaddr *)&dest_addr, sizeof(dest_addr)); + return bytes_sent; } mp_uint_t common_hal_socketpool_socket_recvfrom_into(socketpool_socket_obj_t* self, - const uint8_t* buf, mp_uint_t len, uint8_t* ip, uint8_t port) { + uint8_t* buf, mp_uint_t len, uint8_t* ip, uint *port) { - const struct addrinfo hints = { - .ai_family = AF_INET, - .ai_socktype = SOCK_STREAM, - }; - struct addrinfo *res; - int err = getaddrinfo(host, NULL, &hints, &res); - if (err != 0 || res == NULL) { - return mp_const_none; + struct sockaddr_in source_addr; + socklen_t socklen = sizeof(source_addr); + int bytes_received = lwip_recvfrom(self->num, buf, len - 1, 0, (struct sockaddr *)&source_addr, &socklen); + + memcpy((void *)ip, (void*)&source_addr.sin_addr.s_addr, sizeof source_addr.sin_addr.s_addr); + *port = source_addr.sin_port; + + if (bytes_received < 0) { + mp_raise_BrokenPipeError(); + return 0; + } else { + buf[bytes_received] = 0; // Null-terminate whatever we received + return bytes_received; } - - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wcast-align" - struct in_addr *addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; - #pragma GCC diagnostic pop - char ip_str[IP4ADDR_STRLEN_MAX]; - inet_ntoa_r(*addr, ip_str, IP4ADDR_STRLEN_MAX); - mp_obj_t ip_obj = mp_obj_new_str(ip_str, strlen(ip_str)); - freeaddrinfo(res); } void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self) { diff --git a/shared-bindings/socketpool/Socket.c b/shared-bindings/socketpool/Socket.c index 591b7d8bbd..99e2c8fccb 100644 --- a/shared-bindings/socketpool/Socket.c +++ b/shared-bindings/socketpool/Socket.c @@ -36,6 +36,8 @@ #include "py/runtime.h" #include "py/mperrno.h" +#include "lib/netutils/netutils.h" + //| class Socket: //| """TCP, UDP and RAW socket. Cannot be created directly. Instead, call //| `SocketPool.socket()`. @@ -298,7 +300,7 @@ STATIC mp_obj_t socketpool_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_ mp_int_t port = mp_obj_get_int(addr_items[1]); mp_int_t ret = common_hal_socketpool_socket_sendto(self, host, hostlen, port, bufinfo.buf, bufinfo.len); - if (!ok) { + if (!ret) { mp_raise_OSError(0); } @@ -324,11 +326,11 @@ STATIC mp_obj_t socketpool_socket_recvfrom_into(mp_obj_t self_in, mp_obj_t data_ byte ip[4]; mp_uint_t port; mp_int_t ret = common_hal_socketpool_socket_recvfrom_into(self, - (byte*)bufinfo.buf, len, ip, &port); + (byte*)bufinfo.buf, bufinfo.len, ip, &port); mp_obj_t tuple_contents[2]; tuple_contents[0] = mp_obj_new_int_from_uint(ret); tuple_contents[1] = netutils_format_inet_addr(ip, port, NETUTILS_BIG); - return mp_obj_new_tuple(2, tuple); + return mp_obj_new_tuple(2, tuple_contents); } STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_recvfrom_into_obj, socketpool_socket_recvfrom_into); diff --git a/shared-bindings/socketpool/Socket.h b/shared-bindings/socketpool/Socket.h index 72a4c9e3c3..54fbe59b28 100644 --- a/shared-bindings/socketpool/Socket.h +++ b/shared-bindings/socketpool/Socket.h @@ -36,9 +36,9 @@ bool common_hal_socketpool_socket_connect(socketpool_socket_obj_t* self, const c mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len); mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len); mp_uint_t common_hal_socketpool_socket_sendto(socketpool_socket_obj_t* self, - const uint8_t* host, size_t hostlen, uint8_t port, const uint8_t* buf, mp_uint_t len); + const char* host, size_t hostlen, uint8_t port, const uint8_t* buf, mp_uint_t len); mp_uint_t common_hal_socketpool_socket_recvfrom_into(socketpool_socket_obj_t* self, - const uint8_t* buf, mp_uint_t len, uint8_t* ip, uint8_t port); + uint8_t* buf, mp_uint_t len, uint8_t* ip, uint *port); void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self); bool common_hal_socketpool_socket_get_closed(socketpool_socket_obj_t* self); bool common_hal_socketpool_socket_get_connected(socketpool_socket_obj_t* self); From ba6e15b0700093933826c054ea44d45993751036 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 24 Nov 2020 11:32:18 -0500 Subject: [PATCH 3/6] Fix stubs --- shared-bindings/socketpool/Socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/socketpool/Socket.c b/shared-bindings/socketpool/Socket.c index 99e2c8fccb..0e6968d5f4 100644 --- a/shared-bindings/socketpool/Socket.c +++ b/shared-bindings/socketpool/Socket.c @@ -276,7 +276,7 @@ STATIC mp_obj_t socketpool_socket_recv_into(size_t n_args, const mp_obj_t *args) } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(socketpool_socket_recv_into_obj, 2, 3, socketpool_socket_recv_into); -//| def sendto(self, bytes: ReadableBuffer, address: tuple) -> int: +//| def sendto(self, bytes: ReadableBuffer, address: Tuple[str, int]) -> int: //| """Send some bytes to a specific address. //| Suits sockets of type SOCK_DGRAM //| @@ -308,7 +308,7 @@ STATIC mp_obj_t socketpool_socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_ } STATIC MP_DEFINE_CONST_FUN_OBJ_3(socketpool_socket_sendto_obj, socketpool_socket_sendto); -//| def recvfrom_into(self, buffer) -> Tuple[int, tuple]: +//| def recvfrom_into(self, buffer: WriteableBuffer) -> Tuple[int, Tuple[str, int]]: //| """Reads some bytes from a remote address. //| //| Returns a tuple containing From 1031fe299254e0b46afa9d500fd298e2382f2183 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 24 Nov 2020 14:46:43 -0500 Subject: [PATCH 4/6] correct submodule --- ports/esp32s2/esp-idf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32s2/esp-idf b/ports/esp32s2/esp-idf index 8bc19ba893..d06744f5ef 160000 --- a/ports/esp32s2/esp-idf +++ b/ports/esp32s2/esp-idf @@ -1 +1 @@ -Subproject commit 8bc19ba893e5544d571a753d82b44a84799b94b1 +Subproject commit d06744f5efc382c61cbad8758107cec308feef09 From 0c5e0954dbf2c725cadf12260e56f51a967f9e50 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 24 Nov 2020 14:51:06 -0500 Subject: [PATCH 5/6] Add closed socket identification --- ports/esp32s2/common-hal/socketpool/Socket.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/esp32s2/common-hal/socketpool/Socket.c b/ports/esp32s2/common-hal/socketpool/Socket.c index 937d199f21..1e22193330 100644 --- a/ports/esp32s2/common-hal/socketpool/Socket.c +++ b/ports/esp32s2/common-hal/socketpool/Socket.c @@ -187,6 +187,7 @@ void common_hal_socketpool_socket_close(socketpool_socket_obj_t* self) { if (self->num >= 0) { lwip_shutdown(self->num, 0); lwip_close(self->num); + self->num = -1; } } From e83c481f0fbf6d1ed052b7bba12163e80d64ad4a Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 24 Nov 2020 15:40:27 -0500 Subject: [PATCH 6/6] translations --- locale/circuitpython.pot | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index c184d69313..034fc2ab24 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-11-23 10:10-0600\n" +"POT-Creation-Date: 2020-11-24 15:40-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -297,6 +297,7 @@ msgid "All I2C peripherals are in use" msgstr "" #: ports/esp32s2/common-hal/countio/Counter.c +#: ports/esp32s2/common-hal/frequencyio/FrequencyIn.c #: ports/esp32s2/common-hal/rotaryio/IncrementalEncoder.c msgid "All PCNT units in use" msgstr "" @@ -333,6 +334,7 @@ msgstr "" #: ports/atmel-samd/common-hal/pulseio/PulseIn.c #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/esp32s2/common-hal/frequencyio/FrequencyIn.c #: ports/esp32s2/common-hal/neopixel_write/__init__.c #: ports/esp32s2/common-hal/pulseio/PulseIn.c #: ports/esp32s2/common-hal/pulseio/PulseOut.c @@ -1086,6 +1088,7 @@ msgid "Invalid byteorder string" msgstr "" #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c +#: ports/esp32s2/common-hal/frequencyio/FrequencyIn.c msgid "Invalid capture period. Valid range: 1 - 500" msgstr "" @@ -1412,14 +1415,14 @@ msgstr "" msgid "Only 8 or 16 bit mono with " msgstr "" -#: ports/esp32s2/common-hal/socketpool/SocketPool.c -msgid "Only IPv4 SOCK_STREAM sockets supported" -msgstr "" - #: ports/esp32s2/common-hal/wifi/__init__.c msgid "Only IPv4 addresses supported" msgstr "" +#: ports/esp32s2/common-hal/socketpool/SocketPool.c +msgid "Only IPv4 sockets supported" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c #, c-format msgid ""