diff options
-rw-r--r-- | src/inet.c | 1 | ||||
-rw-r--r-- | test/testclnt.lua | 62 |
2 files changed, 52 insertions, 11 deletions
@@ -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") |
347 | end | 347 | end |
348 | 348 | ||
349 | ------------------------------------------------------------------------ | ||
350 | function 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") | ||
361 | end | ||
362 | |||
363 | ------------------------------------------------------------------------ | ||
364 | function 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() | ||
379 | end | ||
380 | |||
381 | ------------------------------------------------------------------------ | ||
349 | test("method registration") | 382 | test("method registration") |
350 | test_methods(socket.tcp(), { | 383 | test_methods(socket.tcp(), { |
351 | "connect", | 384 | "connect", |
@@ -377,6 +410,24 @@ test_methods(socket.udp(), { | |||
377 | "close", | 410 | "close", |
378 | }) | 411 | }) |
379 | 412 | ||
413 | test("select function") | ||
414 | test_selectbugs() | ||
415 | |||
416 | test("empty host connect: ") | ||
417 | empty_connect() | ||
418 | |||
419 | test("active close: ") | ||
420 | active_close() | ||
421 | |||
422 | test("closed connection detection: ") | ||
423 | test_closed() | ||
424 | |||
425 | test("accept with timeout (if it hangs, it failed:)") | ||
426 | accept_timeout() | ||
427 | |||
428 | test("accept with timeout (if it hangs, it failed:)") | ||
429 | connect_timeout() | ||
430 | |||
380 | test("mixed patterns") | 431 | test("mixed patterns") |
381 | reconnect() | 432 | reconnect() |
382 | test_mixed(1) | 433 | test_mixed(1) |
@@ -448,17 +499,6 @@ test_raw(200) | |||
448 | test_raw(17) | 499 | test_raw(17) |
449 | test_raw(1) | 500 | test_raw(1) |
450 | 501 | ||
451 | test("select function") | ||
452 | test_selectbugs() | ||
453 | |||
454 | test("empty host connect: ") | ||
455 | empty_connect() | ||
456 | |||
457 | test("active close: ") | ||
458 | active_close() | ||
459 | |||
460 | test("closed connection detection: ") | ||
461 | test_closed() | ||
462 | 502 | ||
463 | a = [[ | 503 | a = [[ |
464 | test("total timeout on send") | 504 | test("total timeout on send") |