Commit 564e83b5 authored by Allan Stephens's avatar Allan Stephens Committed by David S. Miller

tipc: Allow connect() to wait indefinitely

Cause a socket whose TIPC_CONN_TIMEOUT option is zero to wait
indefinitely for a response to a connection request using connect().
Previously, specifying a timeout of 0 ms resulted in an immediate
timeout, which was inconsistent with the behavior specified by Posix
for a socket's receive and send timeout.
Signed-off-by: default avatarAllan Stephens <allan.stephens@windriver.com>
Signed-off-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c2de5814
...@@ -64,6 +64,7 @@ struct tipc_sock { ...@@ -64,6 +64,7 @@ struct tipc_sock {
struct sock sk; struct sock sk;
struct tipc_port *p; struct tipc_port *p;
struct tipc_portid peer_name; struct tipc_portid peer_name;
long conn_timeout;
}; };
#define tipc_sk(sk) ((struct tipc_sock *)(sk)) #define tipc_sk(sk) ((struct tipc_sock *)(sk))
...@@ -240,9 +241,9 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol, ...@@ -240,9 +241,9 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol,
sock->state = state; sock->state = state;
sock_init_data(sock, sk); sock_init_data(sock, sk);
sk->sk_rcvtimeo = msecs_to_jiffies(CONN_TIMEOUT_DEFAULT);
sk->sk_backlog_rcv = backlog_rcv; sk->sk_backlog_rcv = backlog_rcv;
tipc_sk(sk)->p = tp_ptr; tipc_sk(sk)->p = tp_ptr;
tipc_sk(sk)->conn_timeout = msecs_to_jiffies(CONN_TIMEOUT_DEFAULT);
spin_unlock_bh(tp_ptr->lock); spin_unlock_bh(tp_ptr->lock);
...@@ -1385,6 +1386,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, ...@@ -1385,6 +1386,7 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
struct msghdr m = {NULL,}; struct msghdr m = {NULL,};
struct sk_buff *buf; struct sk_buff *buf;
struct tipc_msg *msg; struct tipc_msg *msg;
long timeout;
int res; int res;
lock_sock(sk); lock_sock(sk);
...@@ -1445,11 +1447,12 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen, ...@@ -1445,11 +1447,12 @@ static int connect(struct socket *sock, struct sockaddr *dest, int destlen,
/* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */ /* Wait until an 'ACK' or 'RST' arrives, or a timeout occurs */
timeout = tipc_sk(sk)->conn_timeout;
release_sock(sk); release_sock(sk);
res = wait_event_interruptible_timeout(*sk_sleep(sk), res = wait_event_interruptible_timeout(*sk_sleep(sk),
(!skb_queue_empty(&sk->sk_receive_queue) || (!skb_queue_empty(&sk->sk_receive_queue) ||
(sock->state != SS_CONNECTING)), (sock->state != SS_CONNECTING)),
sk->sk_rcvtimeo); timeout ? timeout : MAX_SCHEDULE_TIMEOUT);
lock_sock(sk); lock_sock(sk);
if (res > 0) { if (res > 0) {
...@@ -1712,7 +1715,7 @@ static int setsockopt(struct socket *sock, ...@@ -1712,7 +1715,7 @@ static int setsockopt(struct socket *sock,
res = tipc_set_portunreturnable(tport->ref, value); res = tipc_set_portunreturnable(tport->ref, value);
break; break;
case TIPC_CONN_TIMEOUT: case TIPC_CONN_TIMEOUT:
sk->sk_rcvtimeo = msecs_to_jiffies(value); tipc_sk(sk)->conn_timeout = msecs_to_jiffies(value);
/* no need to set "res", since already 0 at this point */ /* no need to set "res", since already 0 at this point */
break; break;
default: default:
...@@ -1767,7 +1770,7 @@ static int getsockopt(struct socket *sock, ...@@ -1767,7 +1770,7 @@ static int getsockopt(struct socket *sock,
res = tipc_portunreturnable(tport->ref, &value); res = tipc_portunreturnable(tport->ref, &value);
break; break;
case TIPC_CONN_TIMEOUT: case TIPC_CONN_TIMEOUT:
value = jiffies_to_msecs(sk->sk_rcvtimeo); value = jiffies_to_msecs(tipc_sk(sk)->conn_timeout);
/* no need to set "res", since already 0 at this point */ /* no need to set "res", since already 0 at this point */
break; break;
case TIPC_NODE_RECVQ_DEPTH: case TIPC_NODE_RECVQ_DEPTH:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment