diff options
author | Ruslan Mustakov <r.mustakov@gmail.com> | 2017-01-30 13:18:32 +0700 |
---|---|---|
committer | Ruslan Mustakov <r.mustakov@gmail.com> | 2017-02-01 18:18:44 +0700 |
commit | fb8168d338cedd04bad6876538ffa02fd975568b (patch) | |
tree | 303aeaa2da61613d1437f64a197b5c5f1dac7bc0 /tests/async/tacceptcloserace.nim | |
parent | c57fcf42df4206229de10c8ed0463fe94517bd4b (diff) | |
download | Nim-fb8168d338cedd04bad6876538ffa02fd975568b.tar.gz |
Fix Windows accept() to fail future instead of raising
Resolves: #5279
Diffstat (limited to 'tests/async/tacceptcloserace.nim')
-rw-r--r-- | tests/async/tacceptcloserace.nim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/async/tacceptcloserace.nim b/tests/async/tacceptcloserace.nim new file mode 100644 index 000000000..899136b42 --- /dev/null +++ b/tests/async/tacceptcloserace.nim @@ -0,0 +1,29 @@ +import asyncdispatch, net, os, nativesockets + +# bug: https://github.com/nim-lang/Nim/issues/5279 + +proc setupServerSocket(hostname: string, port: Port): AsyncFD = + let fd = newNativeSocket() + setSockOptInt(fd, SOL_SOCKET, SO_REUSEADDR, 1) + var aiList = getAddrInfo(hostname, port) + if bindAddr(fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32: + freeAddrInfo(aiList) + raiseOSError(osLastError()) + freeAddrInfo(aiList) + if listen(fd) != 0: + raiseOSError(osLastError()) + setBlocking(fd, false) + result = fd.AsyncFD + register(result) + +const port = Port(5614) +for i in 0..100: + let serverFd = setupServerSocket("localhost", port) + serverFd.accept().callback = proc(fut: Future[AsyncFD]) = + if not fut.failed: + fut.read().closeSocket() + + var fd = newAsyncNativeSocket() + waitFor fd.connect("localhost", port) + serverFd.closeSocket() + fd.closeSocket() |