Only run the test for the fixed version of poll(...)

This commit is contained in:
Kay Zheng 2015-04-17 22:40:53 +08:00
commit 3125058b6a

View file

@ -16,47 +16,50 @@ const
testPort = Port(17357) testPort = Port(17357)
proc createListenSocket(host: string, port: Port): TAsyncFD = when defined(windows) or defined(nimdoc):
result = newAsyncRawSocket() discard
else:
proc createListenSocket(host: string, port: Port): TAsyncFD =
result = newAsyncRawSocket()
SocketHandle(result).setSockOptInt(SOL_SOCKET, SO_REUSEADDR, 1) SocketHandle(result).setSockOptInt(SOL_SOCKET, SO_REUSEADDR, 1)
var aiList = getAddrInfo(host, port, AF_INET) var aiList = getAddrInfo(host, port, AF_INET)
if SocketHandle(result).bindAddr(aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32: if SocketHandle(result).bindAddr(aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:
dealloc(aiList) dealloc(aiList)
raiseOSError(osLastError()) raiseOSError(osLastError())
dealloc(aiList) dealloc(aiList)
if SocketHandle(result).listen(1) < 0'i32: if SocketHandle(result).listen(1) < 0'i32:
raiseOSError(osLastError()) raiseOSError(osLastError())
proc testAsyncSend() {.async.} = proc testAsyncSend() {.async.} =
var var
ls = createListenSocket(testHost, testPort) ls = createListenSocket(testHost, testPort)
s = newAsyncSocket() s = newAsyncSocket()
await s.connect(testHost, testPort) await s.connect(testHost, testPort)
var ps = await ls.accept() var ps = await ls.accept()
SocketHandle(ls).close() SocketHandle(ls).close()
await ps.send("test 1", flags={}) await ps.send("test 1", flags={})
s.close() s.close()
# This send should raise EPIPE # This send should raise EPIPE
await ps.send("test 2", flags={}) await ps.send("test 2", flags={})
SocketHandle(ps).close() SocketHandle(ps).close()
# The bug was, when the poll function handled EvError for us, # The bug was, when the poll function handled EvError for us,
# our callbacks may never get executed, thus making the event # our callbacks may never get executed, thus making the event
# loop block indefinitely. This is a timer to keep everything # loop block indefinitely. This is a timer to keep everything
# rolling. 400 ms is an arbitrary value, should be enough though. # rolling. 400 ms is an arbitrary value, should be enough though.
proc timer() {.async.} = proc timer() {.async.} =
await sleepAsync(400) await sleepAsync(400)
echo("Timer expired.") echo("Timer expired.")
quit(2) quit(2)
asyncCheck(testAsyncSend()) asyncCheck(testAsyncSend())
waitFor(timer()) waitFor(timer())