diff options
-rw-r--r-- | doc/tcp.html | 6 | ||||
-rw-r--r-- | src/options.c | 36 | ||||
-rw-r--r-- | src/options.h | 18 | ||||
-rw-r--r-- | src/tcp.c | 18 | ||||
-rwxr-xr-x | test/tcp-getoptions | 4 |
5 files changed, 81 insertions, 1 deletions
diff --git a/doc/tcp.html b/doc/tcp.html index 4226d78..4307234 100644 --- a/doc/tcp.html +++ b/doc/tcp.html | |||
@@ -433,6 +433,12 @@ used in validating addresses supplied in a call to | |||
433 | <li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> | 433 | <li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> |
434 | disables the Nagle's algorithm for the connection; | 434 | disables the Nagle's algorithm for the connection; |
435 | 435 | ||
436 | <li> '<tt>tcp-keepidle</tt>': value in seconds for <tt>TCP_KEEPIDLE</tt> Linux only!! | ||
437 | |||
438 | <li> '<tt>tcp-keepcnt</tt>': value for <tt>TCP_KEEPCNT</tt> Linux only!! | ||
439 | |||
440 | <li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!! | ||
441 | |||
436 | <li> '<tt>ipv6-v6only</tt>': | 442 | <li> '<tt>ipv6-v6only</tt>': |
437 | Setting this option to <tt>true</tt> restricts an <tt>inet6</tt> socket to | 443 | Setting this option to <tt>true</tt> restricts an <tt>inet6</tt> socket to |
438 | sending and receiving only IPv6 packets. | 444 | sending and receiving only IPv6 packets. |
diff --git a/src/options.c b/src/options.c index 8ac2a14..28fc08a 100644 --- a/src/options.c +++ b/src/options.c | |||
@@ -90,6 +90,42 @@ int opt_get_tcp_nodelay(lua_State *L, p_socket ps) | |||
90 | return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); | 90 | return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); |
91 | } | 91 | } |
92 | 92 | ||
93 | #ifdef TCP_KEEPIDLE | ||
94 | int opt_get_tcp_keepidle(lua_State *L, p_socket ps) | ||
95 | { | ||
96 | return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); | ||
97 | } | ||
98 | |||
99 | int opt_set_tcp_keepidle(lua_State *L, p_socket ps) | ||
100 | { | ||
101 | return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); | ||
102 | } | ||
103 | #endif | ||
104 | |||
105 | #ifdef TCP_KEEPCNT | ||
106 | int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) | ||
107 | { | ||
108 | return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); | ||
109 | } | ||
110 | |||
111 | int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) | ||
112 | { | ||
113 | return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); | ||
114 | } | ||
115 | #endif | ||
116 | |||
117 | #ifdef TCP_KEEPINTVL | ||
118 | int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) | ||
119 | { | ||
120 | return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); | ||
121 | } | ||
122 | |||
123 | int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) | ||
124 | { | ||
125 | return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); | ||
126 | } | ||
127 | #endif | ||
128 | |||
93 | int opt_set_keepalive(lua_State *L, p_socket ps) | 129 | int opt_set_keepalive(lua_State *L, p_socket ps) |
94 | { | 130 | { |
95 | return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); | 131 | return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); |
diff --git a/src/options.h b/src/options.h index 5657a06..2b6697b 100644 --- a/src/options.h +++ b/src/options.h | |||
@@ -23,6 +23,15 @@ int opt_set_dontroute(lua_State *L, p_socket ps); | |||
23 | int opt_set_broadcast(lua_State *L, p_socket ps); | 23 | int opt_set_broadcast(lua_State *L, p_socket ps); |
24 | int opt_set_reuseaddr(lua_State *L, p_socket ps); | 24 | int opt_set_reuseaddr(lua_State *L, p_socket ps); |
25 | int opt_set_tcp_nodelay(lua_State *L, p_socket ps); | 25 | int opt_set_tcp_nodelay(lua_State *L, p_socket ps); |
26 | #ifdef TCP_KEEPIDLE | ||
27 | int opt_set_tcp_keepidle(lua_State *L, p_socket ps); | ||
28 | #endif | ||
29 | #ifdef TCP_KEEPCNT | ||
30 | int opt_set_tcp_keepcnt(lua_State *L, p_socket ps); | ||
31 | #endif | ||
32 | #ifdef TCP_KEEPINTVL | ||
33 | int opt_set_tcp_keepintvl(lua_State *L, p_socket ps); | ||
34 | #endif | ||
26 | int opt_set_keepalive(lua_State *L, p_socket ps); | 35 | int opt_set_keepalive(lua_State *L, p_socket ps); |
27 | int opt_set_linger(lua_State *L, p_socket ps); | 36 | int opt_set_linger(lua_State *L, p_socket ps); |
28 | int opt_set_reuseaddr(lua_State *L, p_socket ps); | 37 | int opt_set_reuseaddr(lua_State *L, p_socket ps); |
@@ -42,6 +51,15 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps); | |||
42 | /* supported options for getoption */ | 51 | /* supported options for getoption */ |
43 | int opt_get_reuseaddr(lua_State *L, p_socket ps); | 52 | int opt_get_reuseaddr(lua_State *L, p_socket ps); |
44 | int opt_get_tcp_nodelay(lua_State *L, p_socket ps); | 53 | int opt_get_tcp_nodelay(lua_State *L, p_socket ps); |
54 | #ifdef TCP_KEEPIDLE | ||
55 | int opt_get_tcp_keepidle(lua_State *L, p_socket ps); | ||
56 | #endif | ||
57 | #ifdef TCP_KEEPCNT | ||
58 | int opt_get_tcp_keepcnt(lua_State *L, p_socket ps); | ||
59 | #endif | ||
60 | #ifdef TCP_KEEPINTVL | ||
61 | int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); | ||
62 | #endif | ||
45 | int opt_get_keepalive(lua_State *L, p_socket ps); | 63 | int opt_get_keepalive(lua_State *L, p_socket ps); |
46 | int opt_get_linger(lua_State *L, p_socket ps); | 64 | int opt_get_linger(lua_State *L, p_socket ps); |
47 | int opt_get_reuseaddr(lua_State *L, p_socket ps); | 65 | int opt_get_reuseaddr(lua_State *L, p_socket ps); |
@@ -72,6 +72,15 @@ static t_opt optget[] = { | |||
72 | {"keepalive", opt_get_keepalive}, | 72 | {"keepalive", opt_get_keepalive}, |
73 | {"reuseaddr", opt_get_reuseaddr}, | 73 | {"reuseaddr", opt_get_reuseaddr}, |
74 | {"tcp-nodelay", opt_get_tcp_nodelay}, | 74 | {"tcp-nodelay", opt_get_tcp_nodelay}, |
75 | #ifdef TCP_KEEPIDLE | ||
76 | {"tcp-keepidle", opt_get_tcp_keepidle}, | ||
77 | #endif | ||
78 | #ifdef TCP_KEEPCNT | ||
79 | {"tcp-keepcnt", opt_get_tcp_keepcnt}, | ||
80 | #endif | ||
81 | #ifdef TCP_KEEPINTVL | ||
82 | {"tcp-keepintvl", opt_get_tcp_keepintvl}, | ||
83 | #endif | ||
75 | {"linger", opt_get_linger}, | 84 | {"linger", opt_get_linger}, |
76 | {"error", opt_get_error}, | 85 | {"error", opt_get_error}, |
77 | {NULL, NULL} | 86 | {NULL, NULL} |
@@ -81,6 +90,15 @@ static t_opt optset[] = { | |||
81 | {"keepalive", opt_set_keepalive}, | 90 | {"keepalive", opt_set_keepalive}, |
82 | {"reuseaddr", opt_set_reuseaddr}, | 91 | {"reuseaddr", opt_set_reuseaddr}, |
83 | {"tcp-nodelay", opt_set_tcp_nodelay}, | 92 | {"tcp-nodelay", opt_set_tcp_nodelay}, |
93 | #ifdef TCP_KEEPIDLE | ||
94 | {"tcp-keepidle", opt_set_tcp_keepidle}, | ||
95 | #endif | ||
96 | #ifdef TCP_KEEPCNT | ||
97 | {"tcp-keepcnt", opt_set_tcp_keepcnt}, | ||
98 | #endif | ||
99 | #ifdef TCP_KEEPINTVL | ||
100 | {"tcp-keepintvl", opt_set_tcp_keepintvl}, | ||
101 | #endif | ||
84 | {"ipv6-v6only", opt_set_ip6_v6only}, | 102 | {"ipv6-v6only", opt_set_ip6_v6only}, |
85 | {"linger", opt_set_linger}, | 103 | {"linger", opt_set_linger}, |
86 | {NULL, NULL} | 104 | {NULL, NULL} |
diff --git a/test/tcp-getoptions b/test/tcp-getoptions index f9b3d1b..777ccc3 100755 --- a/test/tcp-getoptions +++ b/test/tcp-getoptions | |||
@@ -7,7 +7,9 @@ port = 8765 | |||
7 | function options(o) | 7 | function options(o) |
8 | print("options for", o) | 8 | print("options for", o) |
9 | 9 | ||
10 | for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do | 10 | for _, opt in ipairs{ |
11 | "keepalive", "reuseaddr", | ||
12 | "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do | ||
11 | print("getoption", opt, o:getoption(opt)) | 13 | print("getoption", opt, o:getoption(opt)) |
12 | end | 14 | end |
13 | 15 | ||