Trying to get non-blocking connect to work.

This commit is contained in:
Diego Nehab 2005-04-20 18:57:47 +00:00
parent 693a201db6
commit 2a00a5ad50
4 changed files with 5 additions and 24 deletions

View File

@ -77,11 +77,11 @@ print("trying to connect peer", who, host, port)
if not ret and err == "timeout" then if not ret and err == "timeout" then
print("got timeout, will wait", who) print("got timeout, will wait", who)
wait(who, "output") wait(who, "output")
ret, err = who:connected() ret, err = who:connect(host, port)
print("connection results arrived", who, ret, err) print("connection results arrived", who, ret, err)
end end
if not ret then if not ret then
print("connection failed", who) print("connection failed", who, err)
kick(who) kick(who)
kick(context[who].peer) kick(context[who].peer)
else else

View File

@ -20,7 +20,6 @@
\*=========================================================================*/ \*=========================================================================*/
static int global_create(lua_State *L); static int global_create(lua_State *L);
static int meth_connect(lua_State *L); static int meth_connect(lua_State *L);
static int meth_connected(lua_State *L);
static int meth_listen(lua_State *L); static int meth_listen(lua_State *L);
static int meth_bind(lua_State *L); static int meth_bind(lua_State *L);
static int meth_send(lua_State *L); static int meth_send(lua_State *L);
@ -46,7 +45,6 @@ static luaL_reg tcp[] = {
{"bind", meth_bind}, {"bind", meth_bind},
{"close", meth_close}, {"close", meth_close},
{"connect", meth_connect}, {"connect", meth_connect},
{"connected", meth_connected},
{"dirty", meth_dirty}, {"dirty", meth_dirty},
{"getfd", meth_getfd}, {"getfd", meth_getfd},
{"getpeername", meth_getpeername}, {"getpeername", meth_getpeername},
@ -226,25 +224,6 @@ static int meth_connect(lua_State *L)
return 1; return 1;
} }
static int meth_connected(lua_State *L)
{
p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1);
int err;
t_tm tm;
tm_init(&tm, 0.1, -1);
tm_markstart(&tm);
err = sock_connected(&tcp->sock, &tm);
if (err != IO_DONE) {
lua_pushnil(L);
lua_pushstring(L, sock_strerror(err));
return 2;
}
/* turn master object into a client object */
aux_setclass(L, "tcp{client}", 1);
lua_pushnumber(L, 1);
return 1;
}
/*-------------------------------------------------------------------------*\ /*-------------------------------------------------------------------------*\
* Closes socket used by object * Closes socket used by object
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
@ -308,7 +287,7 @@ error:
\*-------------------------------------------------------------------------*/ \*-------------------------------------------------------------------------*/
static int meth_getpeername(lua_State *L) static int meth_getpeername(lua_State *L)
{ {
p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{client}", 1); p_tcp tcp = (p_tcp) aux_checkgroup(L, "tcp{any}", 1);
return inet_meth_getpeername(L, &tcp->sock); return inet_meth_getpeername(L, &tcp->sock);
} }

View File

@ -358,6 +358,7 @@ const char *sock_strerror(int err) {
if (err <= 0) return io_strerror(err); if (err <= 0) return io_strerror(err);
switch (err) { switch (err) {
case EADDRINUSE: return "address already in use"; case EADDRINUSE: return "address already in use";
case EISCONN: return "already connected";
case EACCES: return "permission denied"; case EACCES: return "permission denied";
case ECONNREFUSED: return "connection refused"; case ECONNREFUSED: return "connection refused";
case ECONNABORTED: return "closed"; case ECONNABORTED: return "closed";

View File

@ -332,6 +332,7 @@ const char *sock_strerror(int err) {
switch (err) { switch (err) {
case WSAEADDRINUSE: return "address already in use"; case WSAEADDRINUSE: return "address already in use";
case WSAECONNREFUSED: return "connection refused"; case WSAECONNREFUSED: return "connection refused";
case WSAEISCONN: return "already connected";
case WSAEACCES: return "permission denied"; case WSAEACCES: return "permission denied";
case WSAECONNABORTED: return "closed"; case WSAECONNABORTED: return "closed";
case WSAECONNRESET: return "closed"; case WSAECONNRESET: return "closed";