Commit 3654ea02 authored by Allan Stephens's avatar Allan Stephens Committed by David S. Miller

[TIPC]: Improve socket time conversions

This patch modifies TIPC's socket code to use standard kernel
routines to handle time conversions between jiffies and ms.
This ensures proper operation even when HZ isn't 1000.

Acknowledgements to Eric Sesterhenn <snakebyte@gmx.de> for
identifying this issue and proposing a solution.
Signed-off-by: default avatarAllan Stephens <allan.stephens@windriver.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 96736932
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#define SS_READY -2 /* socket is connectionless */ #define SS_READY -2 /* socket is connectionless */
#define OVERLOAD_LIMIT_BASE 5000 #define OVERLOAD_LIMIT_BASE 5000
#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
struct tipc_sock { struct tipc_sock {
struct sock sk; struct sock sk;
...@@ -170,7 +171,7 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol) ...@@ -170,7 +171,7 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol)
} }
sock_init_data(sock, sk); sock_init_data(sock, sk);
sk->sk_rcvtimeo = 8 * HZ; /* default connect timeout = 8s */ sk->sk_rcvtimeo = msecs_to_jiffies(CONN_TIMEOUT_DEFAULT);
tsock = tipc_sk(sk); tsock = tipc_sk(sk);
port = tipc_get_port(ref); port = tipc_get_port(ref);
...@@ -1529,7 +1530,7 @@ static int setsockopt(struct socket *sock, ...@@ -1529,7 +1530,7 @@ static int setsockopt(struct socket *sock,
res = tipc_set_portunreturnable(tsock->p->ref, value); res = tipc_set_portunreturnable(tsock->p->ref, value);
break; break;
case TIPC_CONN_TIMEOUT: case TIPC_CONN_TIMEOUT:
sock->sk->sk_rcvtimeo = (value * HZ / 1000); sock->sk->sk_rcvtimeo = msecs_to_jiffies(value);
break; break;
default: default:
res = -EINVAL; res = -EINVAL;
...@@ -1582,7 +1583,7 @@ static int getsockopt(struct socket *sock, ...@@ -1582,7 +1583,7 @@ static int getsockopt(struct socket *sock,
res = tipc_portunreturnable(tsock->p->ref, &value); res = tipc_portunreturnable(tsock->p->ref, &value);
break; break;
case TIPC_CONN_TIMEOUT: case TIPC_CONN_TIMEOUT:
value = (sock->sk->sk_rcvtimeo * 1000) / HZ; value = jiffies_to_msecs(sock->sk->sk_rcvtimeo);
break; break;
default: default:
res = -EINVAL; res = -EINVAL;
......
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