diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2012-04-11 14:18:20 -0700 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2012-04-11 14:18:20 -0700 |
commit | 4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc (patch) | |
tree | ba92aa753ae1b145760cb1c5e69c886d3bf11328 /src/options.c | |
parent | f399ab25fcecad2ff96a5977e8eaf069bb45473c (diff) | |
parent | 195b2a74bb3f368b1f31f9c8bbc1ce0f54de2035 (diff) | |
download | luasocket-4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc.tar.gz luasocket-4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc.tar.bz2 luasocket-4b671f4551e98ac9e1d9a7407d3dffdd7eb1d3dc.zip |
Merge branch 'git-sam' into diego-sam-mwild-integration
Conflicts in options.c were just due to independent small functions
being close to each other.
unix.c in mwild was broken, it wasn't using LUASOCKET_API.
serial.c needed luaL_reg renamed, and to use LUASOCKET_API.
makefile didn't respect standard DESTDIR and prefix makefile
variables, and didn't allow LUAV variable to select lua version to build
against.
I've tested the top-level install-both target builds and installs
against both lua5.1 and lua5.2, but not done further testing.
Conflicts:
README
config
gem/ltn012.tex
makefile
src/makefile
src/options.c
src/options.h
src/tcp.c
src/usocket.c
Diffstat (limited to 'src/options.c')
-rw-r--r-- | src/options.c | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/src/options.c b/src/options.c index 801adf9..ab9e621 100644 --- a/src/options.c +++ b/src/options.c | |||
@@ -21,6 +21,8 @@ static int opt_setboolean(lua_State *L, p_socket ps, int level, int name); | |||
21 | static int opt_getboolean(lua_State *L, p_socket ps, int level, int name); | 21 | static int opt_getboolean(lua_State *L, p_socket ps, int level, int name); |
22 | static int opt_set(lua_State *L, p_socket ps, int level, int name, | 22 | static int opt_set(lua_State *L, p_socket ps, int level, int name, |
23 | void *val, int len); | 23 | void *val, int len); |
24 | static int opt_get(lua_State *L, p_socket ps, int level, int name, | ||
25 | void *val, int* len); | ||
24 | 26 | ||
25 | /*=========================================================================*\ | 27 | /*=========================================================================*\ |
26 | * Exported functions | 28 | * Exported functions |
@@ -60,23 +62,43 @@ int opt_set_reuseaddr(lua_State *L, p_socket ps) | |||
60 | return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); | 62 | return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); |
61 | } | 63 | } |
62 | 64 | ||
65 | int opt_get_reuseaddr(lua_State *L, p_socket ps) | ||
66 | { | ||
67 | return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); | ||
68 | } | ||
69 | |||
63 | /* enables reuse of local port */ | 70 | /* enables reuse of local port */ |
64 | int opt_set_reuseport(lua_State *L, p_socket ps) | 71 | int opt_set_reuseport(lua_State *L, p_socket ps) |
65 | { | 72 | { |
66 | return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); | 73 | return opt_setboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); |
67 | } | 74 | } |
68 | 75 | ||
76 | int opt_get_reuseport(lua_State *L, p_socket ps) | ||
77 | { | ||
78 | return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); | ||
79 | } | ||
80 | |||
69 | /* disables the Naggle algorithm */ | 81 | /* disables the Naggle algorithm */ |
70 | int opt_set_tcp_nodelay(lua_State *L, p_socket ps) | 82 | int opt_set_tcp_nodelay(lua_State *L, p_socket ps) |
71 | { | 83 | { |
72 | return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); | 84 | return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); |
73 | } | 85 | } |
74 | 86 | ||
87 | int opt_get_tcp_nodelay(lua_State *L, p_socket ps) | ||
88 | { | ||
89 | return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); | ||
90 | } | ||
91 | |||
75 | int opt_set_keepalive(lua_State *L, p_socket ps) | 92 | int opt_set_keepalive(lua_State *L, p_socket ps) |
76 | { | 93 | { |
77 | return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); | 94 | return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); |
78 | } | 95 | } |
79 | 96 | ||
97 | int opt_get_keepalive(lua_State *L, p_socket ps) | ||
98 | { | ||
99 | return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); | ||
100 | } | ||
101 | |||
80 | int opt_set_dontroute(lua_State *L, p_socket ps) | 102 | int opt_set_dontroute(lua_State *L, p_socket ps) |
81 | { | 103 | { |
82 | return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); | 104 | return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); |
@@ -114,6 +136,21 @@ int opt_set_linger(lua_State *L, p_socket ps) | |||
114 | return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li)); | 136 | return opt_set(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(li)); |
115 | } | 137 | } |
116 | 138 | ||
139 | int opt_get_linger(lua_State *L, p_socket ps) | ||
140 | { | ||
141 | struct linger li; /* obj, name */ | ||
142 | int len = sizeof(li); | ||
143 | int err = opt_get(L, ps, SOL_SOCKET, SO_LINGER, (char *) &li, &len); | ||
144 | if (err) | ||
145 | return err; | ||
146 | lua_newtable(L); | ||
147 | lua_pushboolean(L, li.l_onoff); | ||
148 | lua_setfield(L, -2, "on"); | ||
149 | lua_pushinteger(L, li.l_linger); | ||
150 | lua_setfield(L, -2, "timeout"); | ||
151 | return 1; | ||
152 | } | ||
153 | |||
117 | int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) | 154 | int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) |
118 | { | 155 | { |
119 | int val = (int) luaL_checknumber(L, 3); /* obj, name, int */ | 156 | int val = (int) luaL_checknumber(L, 3); /* obj, name, int */ |
@@ -185,6 +222,19 @@ static int opt_setmembership(lua_State *L, p_socket ps, int level, int name) | |||
185 | } | 222 | } |
186 | 223 | ||
187 | static | 224 | static |
225 | int opt_get(lua_State *L, p_socket ps, int level, int name, void *val, int* len) | ||
226 | { | ||
227 | socklen_t socklen = *len; | ||
228 | if (getsockopt(*ps, level, name, (char *) val, &socklen) < 0) { | ||
229 | lua_pushnil(L); | ||
230 | lua_pushstring(L, "getsockopt failed"); | ||
231 | return 2; | ||
232 | } | ||
233 | *len = socklen; | ||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | static | ||
188 | int opt_set(lua_State *L, p_socket ps, int level, int name, void *val, int len) | 238 | int opt_set(lua_State *L, p_socket ps, int level, int name, void *val, int len) |
189 | { | 239 | { |
190 | if (setsockopt(*ps, level, name, (char *) val, len) < 0) { | 240 | if (setsockopt(*ps, level, name, (char *) val, len) < 0) { |
@@ -199,12 +249,10 @@ int opt_set(lua_State *L, p_socket ps, int level, int name, void *val, int len) | |||
199 | static int opt_getboolean(lua_State *L, p_socket ps, int level, int name) | 249 | static int opt_getboolean(lua_State *L, p_socket ps, int level, int name) |
200 | { | 250 | { |
201 | int val = 0; | 251 | int val = 0; |
202 | socklen_t len = sizeof(val); | 252 | int len = sizeof(val); |
203 | if (getsockopt(*ps, level, name, (char *) &val, &len) < 0) { | 253 | int err = opt_get(L, ps, level, name, (char *) &val, &len); |
204 | lua_pushnil(L); | 254 | if (err) |
205 | lua_pushstring(L, "getsockopt failed"); | 255 | return err; |
206 | return 2; | ||
207 | } | ||
208 | lua_pushboolean(L, val); | 256 | lua_pushboolean(L, val); |
209 | return 1; | 257 | return 1; |
210 | } | 258 | } |