mirror of
https://github.com/lunarmodules/luasocket.git
synced 2024-12-25 20:18:21 +01:00
Fixed bug in accept, added tests for it and for connect with timeout.
This commit is contained in:
parent
51fcb5a7bd
commit
87e8737218
@ -259,6 +259,7 @@ const char *inet_tryaccept(p_sock ps, p_tm tm, p_sock pc)
|
||||
/* loop until connection accepted or timeout happens */
|
||||
do err = sock_accept(ps, pc, (SA *) &addr, &addr_len, tm_getretry(tm));
|
||||
while (err == IO_RETRY && tm_getretry(tm) != 0);
|
||||
if (err == IO_RETRY) err = IO_TIMEOUT;
|
||||
return io_strerror(err);
|
||||
}
|
||||
|
||||
|
@ -346,6 +346,39 @@ function test_selectbugs()
|
||||
pass("invalid input: ok")
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
function accept_timeout()
|
||||
local s, e = socket.bind("*", 0, 0)
|
||||
assert(s, e)
|
||||
local t = socket.time()
|
||||
s:settimeout(1)
|
||||
local c, e = s:accept()
|
||||
assert(not c, "should not accept")
|
||||
assert(e == "timeout", "wrong error message")
|
||||
assert(socket.time() - t < 2, "took to long to give up")
|
||||
s:close()
|
||||
pass("good")
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
function connect_timeout()
|
||||
local s, e = socket.bind("*", 0, 0)
|
||||
assert(s, e)
|
||||
i, p = s:getsockname()
|
||||
assert(i, p)
|
||||
local t = socket.time()
|
||||
local c, e = socket.tcp()
|
||||
assert(c, e)
|
||||
c:settimeout(1)
|
||||
local r, e = c:connect("localhost", p)
|
||||
assert(not r and e == "timeout", "wrong error message")
|
||||
assert(socket.time() - t < 2, "took to long to give up")
|
||||
pass("good")
|
||||
s:close()
|
||||
c:close()
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
test("method registration")
|
||||
test_methods(socket.tcp(), {
|
||||
"connect",
|
||||
@ -377,6 +410,24 @@ test_methods(socket.udp(), {
|
||||
"close",
|
||||
})
|
||||
|
||||
test("select function")
|
||||
test_selectbugs()
|
||||
|
||||
test("empty host connect: ")
|
||||
empty_connect()
|
||||
|
||||
test("active close: ")
|
||||
active_close()
|
||||
|
||||
test("closed connection detection: ")
|
||||
test_closed()
|
||||
|
||||
test("accept with timeout (if it hangs, it failed:)")
|
||||
accept_timeout()
|
||||
|
||||
test("accept with timeout (if it hangs, it failed:)")
|
||||
connect_timeout()
|
||||
|
||||
test("mixed patterns")
|
||||
reconnect()
|
||||
test_mixed(1)
|
||||
@ -448,17 +499,6 @@ test_raw(200)
|
||||
test_raw(17)
|
||||
test_raw(1)
|
||||
|
||||
test("select function")
|
||||
test_selectbugs()
|
||||
|
||||
test("empty host connect: ")
|
||||
empty_connect()
|
||||
|
||||
test("active close: ")
|
||||
active_close()
|
||||
|
||||
test("closed connection detection: ")
|
||||
test_closed()
|
||||
|
||||
a = [[
|
||||
test("total timeout on send")
|
||||
|
Loading…
Reference in New Issue
Block a user