Skip to content

Commit 134abf8

Browse files
committed
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.
1 parent a6207ca commit 134abf8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

features/lwipstack/LWIPStack.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ nsapi_error_t LWIP::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
271271
return NSAPI_ERROR_NO_SOCKET;
272272
}
273273

274-
netconn_set_recvtimeout(s->conn, 1);
274+
netconn_set_nonblocking(s->conn, true);
275275
*(struct mbed_lwip_socket **)handle = s;
276276
return 0;
277277
}
@@ -376,7 +376,7 @@ nsapi_error_t LWIP::socket_accept(nsapi_socket_t server, nsapi_socket_t *handle,
376376
return err_remap(err);
377377
}
378378

379-
netconn_set_recvtimeout(ns->conn, 1);
379+
netconn_set_nonblocking(ns->conn, true);
380380
*(struct mbed_lwip_socket **)handle = ns;
381381

382382
ip_addr_t peer_addr;
@@ -390,8 +390,6 @@ nsapi_error_t LWIP::socket_accept(nsapi_socket_t server, nsapi_socket_t *handle,
390390
address->set_port(port);
391391
}
392392

393-
netconn_set_nonblocking(ns->conn, true);
394-
395393
return 0;
396394
#else
397395
return NSAPI_ERROR_UNSUPPORTED;

0 commit comments

Comments
 (0)