diff options
| author | Diego Nehab <diego.nehab@gmail.com> | 2019-02-24 17:55:27 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-24 17:55:27 -0300 |
| commit | 699c36c0193c4c9fb4ae8d90c032280f6bacdaf3 (patch) | |
| tree | 568f11832751f7bca69c419c000494256b6b3348 | |
| parent | f6ba23d463fde40c47862efafb32de231844c099 (diff) | |
| parent | 2906d6a5227df25f14305c373fdde057f388d363 (diff) | |
| download | luasocket-699c36c0193c4c9fb4ae8d90c032280f6bacdaf3.tar.gz luasocket-699c36c0193c4c9fb4ae8d90c032280f6bacdaf3.tar.bz2 luasocket-699c36c0193c4c9fb4ae8d90c032280f6bacdaf3.zip | |
Merge pull request #116 from linuxmaniac/master
Add "tcp-keepidle", "tcp-keepcnt" and "tcp-keepintvl" 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 c6c6eb2..6050a5f 100644 --- a/doc/tcp.html +++ b/doc/tcp.html | |||
| @@ -477,6 +477,12 @@ used in validating addresses supplied in a call to | |||
| 477 | <li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> | 477 | <li> '<tt>tcp-nodelay</tt>': Setting this option to <tt>true</tt> |
| 478 | disables the Nagle's algorithm for the connection; | 478 | disables the Nagle's algorithm for the connection; |
| 479 | 479 | ||
| 480 | <li> '<tt>tcp-keepidle</tt>': value in seconds for <tt>TCP_KEEPIDLE</tt> Linux only!! | ||
| 481 | |||
| 482 | <li> '<tt>tcp-keepcnt</tt>': value for <tt>TCP_KEEPCNT</tt> Linux only!! | ||
| 483 | |||
| 484 | <li> '<tt>tcp-keepintvl</tt>': value for <tt>TCP_KEEPINTVL</tt> Linux only!! | ||
| 485 | |||
| 480 | <li> '<tt>ipv6-v6only</tt>': | 486 | <li> '<tt>ipv6-v6only</tt>': |
| 481 | Setting this option to <tt>true</tt> restricts an <tt>inet6</tt> socket to | 487 | Setting this option to <tt>true</tt> restricts an <tt>inet6</tt> socket to |
| 482 | sending and receiving only IPv6 packets. | 488 | sending and receiving only IPv6 packets. |
diff --git a/src/options.c b/src/options.c index fabfe8c..90e6d2d 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 19ba0df..2ecc696 100644 --- a/src/options.h +++ b/src/options.h | |||
| @@ -22,6 +22,15 @@ typedef t_opt *p_opt; | |||
| 22 | int opt_set_dontroute(lua_State *L, p_socket ps); | 22 | 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_tcp_nodelay(lua_State *L, p_socket ps); | 24 | int opt_set_tcp_nodelay(lua_State *L, p_socket ps); |
| 25 | #ifdef TCP_KEEPIDLE | ||
| 26 | int opt_set_tcp_keepidle(lua_State *L, p_socket ps); | ||
| 27 | #endif | ||
| 28 | #ifdef TCP_KEEPCNT | ||
| 29 | int opt_set_tcp_keepcnt(lua_State *L, p_socket ps); | ||
| 30 | #endif | ||
| 31 | #ifdef TCP_KEEPINTVL | ||
| 32 | int opt_set_tcp_keepintvl(lua_State *L, p_socket ps); | ||
| 33 | #endif | ||
| 25 | int opt_set_keepalive(lua_State *L, p_socket ps); | 34 | int opt_set_keepalive(lua_State *L, p_socket ps); |
| 26 | int opt_set_linger(lua_State *L, p_socket ps); | 35 | int opt_set_linger(lua_State *L, p_socket ps); |
| 27 | int opt_set_reuseaddr(lua_State *L, p_socket ps); | 36 | int opt_set_reuseaddr(lua_State *L, p_socket ps); |
| @@ -44,6 +53,15 @@ int opt_get_broadcast(lua_State *L, p_socket ps); | |||
| 44 | int opt_get_reuseaddr(lua_State *L, p_socket ps); | 53 | int opt_get_reuseaddr(lua_State *L, p_socket ps); |
| 45 | int opt_get_reuseport(lua_State *L, p_socket ps); | 54 | int opt_get_reuseport(lua_State *L, p_socket ps); |
| 46 | int opt_get_tcp_nodelay(lua_State *L, p_socket ps); | 55 | int opt_get_tcp_nodelay(lua_State *L, p_socket ps); |
| 56 | #ifdef TCP_KEEPIDLE | ||
| 57 | int opt_get_tcp_keepidle(lua_State *L, p_socket ps); | ||
| 58 | #endif | ||
| 59 | #ifdef TCP_KEEPCNT | ||
| 60 | int opt_get_tcp_keepcnt(lua_State *L, p_socket ps); | ||
| 61 | #endif | ||
| 62 | #ifdef TCP_KEEPINTVL | ||
| 63 | int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); | ||
| 64 | #endif | ||
| 47 | int opt_get_keepalive(lua_State *L, p_socket ps); | 65 | int opt_get_keepalive(lua_State *L, p_socket ps); |
| 48 | int opt_get_linger(lua_State *L, p_socket ps); | 66 | int opt_get_linger(lua_State *L, p_socket ps); |
| 49 | int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); | 67 | int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); |
| @@ -77,6 +77,15 @@ static t_opt optget[] = { | |||
| 77 | {"reuseaddr", opt_get_reuseaddr}, | 77 | {"reuseaddr", opt_get_reuseaddr}, |
| 78 | {"reuseport", opt_get_reuseport}, | 78 | {"reuseport", opt_get_reuseport}, |
| 79 | {"tcp-nodelay", opt_get_tcp_nodelay}, | 79 | {"tcp-nodelay", opt_get_tcp_nodelay}, |
| 80 | #ifdef TCP_KEEPIDLE | ||
| 81 | {"tcp-keepidle", opt_get_tcp_keepidle}, | ||
| 82 | #endif | ||
| 83 | #ifdef TCP_KEEPCNT | ||
| 84 | {"tcp-keepcnt", opt_get_tcp_keepcnt}, | ||
| 85 | #endif | ||
| 86 | #ifdef TCP_KEEPINTVL | ||
| 87 | {"tcp-keepintvl", opt_get_tcp_keepintvl}, | ||
| 88 | #endif | ||
| 80 | {"linger", opt_get_linger}, | 89 | {"linger", opt_get_linger}, |
| 81 | {"error", opt_get_error}, | 90 | {"error", opt_get_error}, |
| 82 | {NULL, NULL} | 91 | {NULL, NULL} |
| @@ -87,6 +96,15 @@ static t_opt optset[] = { | |||
| 87 | {"reuseaddr", opt_set_reuseaddr}, | 96 | {"reuseaddr", opt_set_reuseaddr}, |
| 88 | {"reuseport", opt_set_reuseport}, | 97 | {"reuseport", opt_set_reuseport}, |
| 89 | {"tcp-nodelay", opt_set_tcp_nodelay}, | 98 | {"tcp-nodelay", opt_set_tcp_nodelay}, |
| 99 | #ifdef TCP_KEEPIDLE | ||
| 100 | {"tcp-keepidle", opt_set_tcp_keepidle}, | ||
| 101 | #endif | ||
| 102 | #ifdef TCP_KEEPCNT | ||
| 103 | {"tcp-keepcnt", opt_set_tcp_keepcnt}, | ||
| 104 | #endif | ||
| 105 | #ifdef TCP_KEEPINTVL | ||
| 106 | {"tcp-keepintvl", opt_set_tcp_keepintvl}, | ||
| 107 | #endif | ||
| 90 | {"ipv6-v6only", opt_set_ip6_v6only}, | 108 | {"ipv6-v6only", opt_set_ip6_v6only}, |
| 91 | {"linger", opt_set_linger}, | 109 | {"linger", opt_set_linger}, |
| 92 | {NULL, NULL} | 110 | {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 | ||
