Skip to content

Commit 84b191e

Browse files
rveerama1jukkar
authored andcommitted
net: sockets: Add timeout to socket connect call
Current socket connect call implementation always takes K_FOREVER timeout value, which blocks TCP connections in case failure. TCP connections waits until it receives SYN ACK. If there is no SYC ACK means, connect call is blocked forever. Added a Kconfig option to define timeout value. Default value is 3000 milliseconds. User can modify it. Signed-off-by: Ravi kumar Veeramally <[email protected]>
1 parent f3b0b44 commit 84b191e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

subsys/net/lib/sockets/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ config NET_SOCKETS_POLL_MAX
3030
help
3131
Maximum number of entries supported for poll() call.
3232

33+
config NET_SOCKETS_CONNECT_TIMEOUT
34+
int "Timeout value in milliseconds to CONNECT"
35+
default 3000
36+
range 0 60000
37+
help
38+
This variable specifies time in milliseconds after connect()
39+
API call will timeout if we have not received SYN-ACK from
40+
peer.
41+
3342
config NET_SOCKETS_DNS_TIMEOUT
3443
int "Timeout value in milliseconds for DNS queries"
3544
default 2000

subsys/net/lib/sockets/sockets.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,9 @@ Z_SYSCALL_HANDLER(zsock_bind, sock, addr, addrlen)
325325
int zsock_connect_ctx(struct net_context *ctx, const struct sockaddr *addr,
326326
socklen_t addrlen)
327327
{
328-
SET_ERRNO(net_context_connect(ctx, addr, addrlen, NULL, K_FOREVER,
329-
NULL));
328+
SET_ERRNO(net_context_connect(ctx, addr, addrlen, NULL,
329+
K_MSEC(CONFIG_NET_SOCKETS_CONNECT_TIMEOUT),
330+
NULL));
330331
SET_ERRNO(net_context_recv(ctx, zsock_received_cb, K_NO_WAIT,
331332
ctx->user_data));
332333

0 commit comments

Comments
 (0)