diff --git a/samples/forward.lua b/samples/forward.lua index 46f51c8..fe0d20a 100644 --- a/samples/forward.lua +++ b/samples/forward.lua @@ -57,7 +57,7 @@ function init() assert(iport, "invalid arguments") -- create our server socket local server = assert(socket.bind("*", iport)) - server:settimeout(0.1) -- we don't want to be killed by bad luck + server:settimeout(0) -- we don't want to be killed by bad luck -- make sure server is tested for readability receiving:insert(server) -- add server context @@ -71,7 +71,7 @@ end -- starts a connection in a non-blocking way function connect(who, host, port) - who:settimeout(0.1) + who:settimeout(0) print("trying to connect peer", who, host, port) local ret, err = who:connect(host, port) if not ret and err == "timeout" then @@ -89,12 +89,11 @@ print("connection failed", who) end end --- gets rid of a client and its peer +-- gets rid of a client function kick(who) if who and context[who] then sending:remove(who) receiving:remove(who) - local peer = context[who].peer context[who] = nil who:close() end diff --git a/src/buffer.c b/src/buffer.c index 45cd0f2..62211d8 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -77,7 +77,7 @@ int buf_meth_send(lua_State *L, p_buf buf) { int top = lua_gettop(L); p_tm tm = tm_markstart(buf->tm); int err = IO_DONE; - size_t size, sent; + size_t size = 0, sent = 0; const char *data = luaL_checklstring(L, 2, &size); long start = (long) luaL_optnumber(L, 3, 1); long end = (long) luaL_optnumber(L, 4, -1); diff --git a/src/tcp.c b/src/tcp.c index 7ff3054..3aa1538 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -228,10 +228,12 @@ static int meth_connect(lua_State *L) static int meth_connected(lua_State *L) { - p_tcp tcp; + p_tcp tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1); int err; - tcp = (p_tcp) aux_checkclass(L, "tcp{master}", 1); - err = sock_connected(&tcp->sock, &tcp->tm); + 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)); diff --git a/src/timeout.h b/src/timeout.h index 595aac2..d2f9be0 100644 --- a/src/timeout.h +++ b/src/timeout.h @@ -10,8 +10,8 @@ /* timeout control structure */ typedef struct t_tm_ { - double total; /* total number of miliseconds for operation */ double block; /* maximum time for blocking calls */ + double total; /* total number of miliseconds for operation */ double start; /* time of start of operation */ } t_tm; typedef t_tm *p_tm; diff --git a/src/wsocket.c b/src/wsocket.c index 8b00fa5..2c30fbb 100644 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -129,10 +129,11 @@ int sock_connect(p_sock ps, SA *addr, socklen_t len, p_tm tm) { \*-------------------------------------------------------------------------*/ int sock_connected(p_sock ps, p_tm tm) { int err; + /* give windows time to find out what is up (yes, disgusting) */ if ((err = sock_waitfd(ps, WAITFD_C, tm)) == IO_CLOSED) { int len = sizeof(err); /* give windows time to set the error (yes, disgusting) */ - Sleep(0); + Sleep(10); /* find out why we failed */ getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len); /* we KNOW there was an error. if 'why' is 0, we will return