Fixed bug in accept, added tests for it and for connect with timeout.

This commit is contained in:
Diego Nehab 2004-01-18 05:35:56 +00:00
parent 51fcb5a7bd
commit 87e8737218
2 changed files with 52 additions and 11 deletions

View File

@ -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);
}

View File

@ -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")