Skip to content

Commit

Permalink
net: sockets: Add timeout to socket connect call
Browse files Browse the repository at this point in the history
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 <ravikumar.veeramally@linux.intel.com>
  • Loading branch information
rveerama1 authored and jukkar committed Jul 1, 2019
1 parent f3b0b44 commit 84b191e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions subsys/net/lib/sockets/Kconfig
Expand Up @@ -30,6 +30,15 @@ config NET_SOCKETS_POLL_MAX
help
Maximum number of entries supported for poll() call.

config NET_SOCKETS_CONNECT_TIMEOUT
int "Timeout value in milliseconds to CONNECT"
default 3000
range 0 60000
help
This variable specifies time in milliseconds after connect()
API call will timeout if we have not received SYN-ACK from
peer.

config NET_SOCKETS_DNS_TIMEOUT
int "Timeout value in milliseconds for DNS queries"
default 2000
Expand Down
5 changes: 3 additions & 2 deletions subsys/net/lib/sockets/sockets.c
Expand Up @@ -325,8 +325,9 @@ Z_SYSCALL_HANDLER(zsock_bind, sock, addr, addrlen)
int zsock_connect_ctx(struct net_context *ctx, const struct sockaddr *addr,
socklen_t addrlen)
{
SET_ERRNO(net_context_connect(ctx, addr, addrlen, NULL, K_FOREVER,
NULL));
SET_ERRNO(net_context_connect(ctx, addr, addrlen, NULL,
K_MSEC(CONFIG_NET_SOCKETS_CONNECT_TIMEOUT),
NULL));
SET_ERRNO(net_context_recv(ctx, zsock_received_cb, K_NO_WAIT,
ctx->user_data));

Expand Down

0 comments on commit 84b191e

Please sign in to comment.