From 134abf8e1f6e1572741a1be46960ccd5f9e06bb3 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Tue, 30 Jun 2020 11:30:27 +0300 Subject: [PATCH 1/2] LWIPStack: set sockets non-blocking When sockets were opened, they were not set non-blocking, but only had their timeout set to 1ms. TCP sockets were set to non-blocking on connect or accept, but UDP sockets were left blocking with 1ms timeout. This led to unnecessary delays when checking for data from an empty UDP socket. Change sockets to be non-blocking on open instead of setting the timeout. As TCP sockets were already non-blocking, the necessary event handling is already in place, and no other changes are required. --- features/lwipstack/LWIPStack.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/features/lwipstack/LWIPStack.cpp b/features/lwipstack/LWIPStack.cpp index 350387083a..c3e6e79775 100644 --- a/features/lwipstack/LWIPStack.cpp +++ b/features/lwipstack/LWIPStack.cpp @@ -271,7 +271,7 @@ nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) return NSAPI_ERROR_NO_SOCKET; } - netconn_set_recvtimeout(s->conn, 1); + netconn_set_nonblocking(s->conn, true); *(struct mbed_lwip_socket **)handle = s; return 0; } @@ -376,7 +376,7 @@ nsapi_error_t LWIP::socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, return err_remap(err); } - netconn_set_recvtimeout(ns->conn, 1); + netconn_set_nonblocking(ns->conn, true); *(struct mbed_lwip_socket **)handle = ns; ip_addr_t peer_addr; @@ -390,8 +390,6 @@ nsapi_error_t LWIP::socket_accept(nsapi_socket_t server, nsapi_socket_t *handle, address->set_port(port); } - netconn_set_nonblocking(ns->conn, true); - return 0; #else return NSAPI_ERROR_UNSUPPORTED; From c2c2b19ecfefec1951c42d372cb859d63415b68c Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Tue, 30 Jun 2020 11:48:13 +0300 Subject: [PATCH 2/2] Turn off LWIP_SO_RCVTIMEO We no longer use the receive timeout option in lwIP, so disable it to save a small amount of ROM+RAM. --- features/lwipstack/lwipopts.h | 1 - 1 file changed, 1 deletion(-) diff --git a/features/lwipstack/lwipopts.h b/features/lwipstack/lwipopts.h index 628ae49822..f0cbb5ef26 100644 --- a/features/lwipstack/lwipopts.h +++ b/features/lwipstack/lwipopts.h @@ -201,7 +201,6 @@ #define LWIP_COMPAT_SOCKETS 0 #define LWIP_POSIX_SOCKETS_IO_NAMES 0 -#define LWIP_SO_RCVTIMEO 1 #define LWIP_BROADCAST_PING 1