aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/inet.c1
-rw-r--r--test/testclnt.lua62
2 files changed, 52 insertions, 11 deletions
diff --git a/src/inet.c b/src/inet.c
index 80c488b..282d616 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -259,6 +259,7 @@ const char *inet_tryaccept(p_sock ps, p_tm tm, p_sock pc)
259 /* loop until connection accepted or timeout happens */ 259 /* loop until connection accepted or timeout happens */
260 do err = sock_accept(ps, pc, (SA *) &addr, &addr_len, tm_getretry(tm)); 260 do err = sock_accept(ps, pc, (SA *) &addr, &addr_len, tm_getretry(tm));
261 while (err == IO_RETRY && tm_getretry(tm) != 0); 261 while (err == IO_RETRY && tm_getretry(tm) != 0);
262 if (err == IO_RETRY) err = IO_TIMEOUT;
262 return io_strerror(err); 263 return io_strerror(err);
263} 264}
264 265
diff --git a/test/testclnt.lua b/test/testclnt.lua
index 3dea831..4d66193 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -346,6 +346,39 @@ function test_selectbugs()
346 pass("invalid input: ok") 346 pass("invalid input: ok")
347end 347end
348 348
349------------------------------------------------------------------------
350function accept_timeout()
351 local s, e = socket.bind("*", 0, 0)
352 assert(s, e)
353 local t = socket.time()
354 s:settimeout(1)
355 local c, e = s:accept()
356 assert(not c, "should not accept")
357 assert(e == "timeout", "wrong error message")
358 assert(socket.time() - t < 2, "took to long to give up")
359 s:close()
360 pass("good")
361end
362
363------------------------------------------------------------------------
364function connect_timeout()
365 local s, e = socket.bind("*", 0, 0)
366 assert(s, e)
367 i, p = s:getsockname()
368 assert(i, p)
369 local t = socket.time()
370 local c, e = socket.tcp()
371 assert(c, e)
372 c:settimeout(1)
373 local r, e = c:connect("localhost", p)
374 assert(not r and e == "timeout", "wrong error message")
375 assert(socket.time() - t < 2, "took to long to give up")
376 pass("good")
377 s:close()
378 c:close()
379end
380
381------------------------------------------------------------------------
349test("method registration") 382test("method registration")
350test_methods(socket.tcp(), { 383test_methods(socket.tcp(), {
351 "connect", 384 "connect",
@@ -377,6 +410,24 @@ test_methods(socket.udp(), {
377 "close", 410 "close",
378}) 411})
379 412
413test("select function")
414test_selectbugs()
415
416test("empty host connect: ")
417empty_connect()
418
419test("active close: ")
420active_close()
421
422test("closed connection detection: ")
423test_closed()
424
425test("accept with timeout (if it hangs, it failed:)")
426accept_timeout()
427
428test("accept with timeout (if it hangs, it failed:)")
429connect_timeout()
430
380test("mixed patterns") 431test("mixed patterns")
381reconnect() 432reconnect()
382test_mixed(1) 433test_mixed(1)
@@ -448,17 +499,6 @@ test_raw(200)
448test_raw(17) 499test_raw(17)
449test_raw(1) 500test_raw(1)
450 501
451test("select function")
452test_selectbugs()
453
454test("empty host connect: ")
455empty_connect()
456
457test("active close: ")
458active_close()
459
460test("closed connection detection: ")
461test_closed()
462 502
463a = [[ 503a = [[
464test("total timeout on send") 504test("total timeout on send")