diff options
-rw-r--r-- | samples/forward.lua | 4 | ||||
-rw-r--r-- | src/tcp.c | 23 | ||||
-rw-r--r-- | src/usocket.c | 1 | ||||
-rw-r--r-- | src/wsocket.c | 1 |
4 files changed, 5 insertions, 24 deletions
diff --git a/samples/forward.lua b/samples/forward.lua index 0f79ee2..c213a59 100644 --- a/samples/forward.lua +++ b/samples/forward.lua | |||
@@ -77,11 +77,11 @@ print("trying to connect peer", who, host, port) | |||
77 | if not ret and err == "timeout" then | 77 | if not ret and err == "timeout" then |
78 | print("got timeout, will wait", who) | 78 | print("got timeout, will wait", who) |
79 | wait(who, "output") | 79 | wait(who, "output") |
80 | ret, err = who:connected() | 80 | ret, err = who:connect(host, port) |
81 | print("connection results arrived", who, ret, err) | 81 | print("connection results arrived", who, ret, err) |
82 | end | 82 | end |
83 | if not ret then | 83 | if not ret then |
84 | print("connection failed", who) | 84 | print("connection failed", who, err) |
85 | kick(who) | 85 | kick(who) |
86 | kick(context[who].peer) | 86 | kick(context[who].peer) |
87 | else | 87 | else |
@@ -20,7 +20,6 @@ | |||
20 | \*=========================================================================*/ | 20 | \*=========================================================================*/ |
21 | static int global_create(lua_State *L); | 21 | static int global_create(lua_State *L); |
22 | static int meth_connect(lua_State *L); | 22 | static int meth_connect(lua_State *L); |
23 | static int meth_connected(lua_State *L); | ||
24 | static int meth_listen(lua_State *L); | 23 | static int meth_listen(lua_State *L); |
25 | static int meth_bind(lua_State *L); | 24 | static int meth_bind(lua_State *L); |
26 | static int meth_send(lua_State *L); | 25 | static int meth_send(lua_State *L); |
@@ -46,7 +45,6 @@ static luaL_reg tcp[] = { | |||
46 | {"bind", meth_bind}, | 45 | {"bind", meth_bind}, |
47 | {"close", meth_close}, | 46 | {"close", meth_close}, |
48 | {"connect", meth_connect}, | 47 | {"connect", meth_connect}, |
49 | {"connected", meth_connected}, | ||
50 | {"dirty", meth_dirty}, | 48 | {"dirty", meth_dirty}, |
51 | {"getfd", meth_getfd}, | 49 | {"getfd", meth_getfd}, |
52 | {"getpeername", meth_getpeername}, | 50 | {"getpeername", meth_getpeername}, |
@@ -226,25 +224,6 @@ static int meth_connect(lua_State *L) | |||
226 | return 1; | 224 | return 1; |
227 | } | 225 | } |
228 | 226 | ||
229 | static int meth_connected(lua_State *L) | ||
230 | { | ||
231 | p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1); | ||
232 | int err; | ||
233 | t_tm tm; | ||
234 | tm_init(&tm, 0.1, -1); | ||
235 | tm_markstart(&tm); | ||
236 | err = sock_connected(&tcp->sock, &tm); | ||
237 | if (err != IO_DONE) { | ||
238 | lua_pushnil(L); | ||
239 | lua_pushstring(L, sock_strerror(err)); | ||
240 | return 2; | ||
241 | } | ||
242 | /* turn master object into a client object */ | ||
243 | aux_setclass(L, "tcp{client}", 1); | ||
244 | lua_pushnumber(L, 1); | ||
245 | return 1; | ||
246 | } | ||
247 | |||
248 | /*-------------------------------------------------------------------------*\ | 227 | /*-------------------------------------------------------------------------*\ |
249 | * Closes socket used by object | 228 | * Closes socket used by object |
250 | \*-------------------------------------------------------------------------*/ | 229 | \*-------------------------------------------------------------------------*/ |
@@ -308,7 +287,7 @@ error: | |||
308 | \*-------------------------------------------------------------------------*/ | 287 | \*-------------------------------------------------------------------------*/ |
309 | static int meth_getpeername(lua_State *L) | 288 | static int meth_getpeername(lua_State *L) |
310 | { | 289 | { |
311 | p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1); | 290 | p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1); |
312 | return inet_meth_getpeername(L, &tcp->sock); | 291 | return inet_meth_getpeername(L, &tcp->sock); |
313 | } | 292 | } |
314 | 293 | ||
diff --git a/src/usocket.c b/src/usocket.c index 3e151bf..dcb40e6 100644 --- a/src/usocket.c +++ b/src/usocket.c | |||
@@ -358,6 +358,7 @@ const char *sock_strerror(int err) { | |||
358 | if (err <= 0) return io_strerror(err); | 358 | if (err <= 0) return io_strerror(err); |
359 | switch (err) { | 359 | switch (err) { |
360 | case EADDRINUSE: return "address already in use"; | 360 | case EADDRINUSE: return "address already in use"; |
361 | case EISCONN: return "already connected"; | ||
361 | case EACCES: return "permission denied"; | 362 | case EACCES: return "permission denied"; |
362 | case ECONNREFUSED: return "connection refused"; | 363 | case ECONNREFUSED: return "connection refused"; |
363 | case ECONNABORTED: return "closed"; | 364 | case ECONNABORTED: return "closed"; |
diff --git a/src/wsocket.c b/src/wsocket.c index 2c30fbb..2cbd073 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
@@ -332,6 +332,7 @@ const char *sock_strerror(int err) { | |||
332 | switch (err) { | 332 | switch (err) { |
333 | case WSAEADDRINUSE: return "address already in use"; | 333 | case WSAEADDRINUSE: return "address already in use"; |
334 | case WSAECONNREFUSED: return "connection refused"; | 334 | case WSAECONNREFUSED: return "connection refused"; |
335 | case WSAEISCONN: return "already connected"; | ||
335 | case WSAEACCES: return "permission denied"; | 336 | case WSAEACCES: return "permission denied"; |
336 | case WSAECONNABORTED: return "closed"; | 337 | case WSAECONNABORTED: return "closed"; |
337 | case WSAECONNRESET: return "closed"; | 338 | case WSAECONNRESET: return "closed"; |