diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-11-30 17:04:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-30 17:04:25 +0100 |
commit | 432f68fb32525ee2c5f98e664a4d928651979550 (patch) | |
tree | bbe4fbbb21789d5f31c2524d9d403fc35dc26ade | |
parent | b1b2dd606ba736775868853657e331f287423dee (diff) | |
parent | d40b7831108cbb9ce7000ebb2462fe1587494926 (diff) | |
download | Nim-432f68fb32525ee2c5f98e664a4d928651979550.tar.gz |
Merge pull request #5071 from cheatfate/onemoreasync
async: some fixes more.
-rw-r--r-- | lib/pure/asyncdispatch.nim | 19 | ||||
-rw-r--r-- | lib/upcoming/asyncdispatch.nim | 25 |
2 files changed, 18 insertions, 26 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 01088c2e7..1367bc411 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -893,9 +893,11 @@ when defined(windows) or defined(nimdoc): deallocShared(cast[pointer](pcd)) raiseOSError(osLastError()) else: - # we ref pcd.ovl one more time, because it will be unrefed in - # poll() + # we incref `pcd.ovl` and `protect` callback one more time, + # because it will be unrefed and disposed in `poll()` after + # callback finishes. GC_ref(pcd.ovl) + pcd.ovl.data.cell = system.protect(rawEnv(pcd.ovl.data.cb)) ) # We need to protect our callback environment value, so GC will not free it # accidentally. @@ -956,17 +958,8 @@ when defined(windows) or defined(nimdoc): initAll() else: import selectors - when defined(windows): - import winlean - const - EINTR = WSAEINPROGRESS - EINPROGRESS = WSAEINPROGRESS - EWOULDBLOCK = WSAEWOULDBLOCK - EAGAIN = EINPROGRESS - MSG_NOSIGNAL = 0 - else: - from posix import EINTR, EAGAIN, EINPROGRESS, EWOULDBLOCK, MSG_PEEK, - MSG_NOSIGNAL + from posix import EINTR, EAGAIN, EINPROGRESS, EWOULDBLOCK, MSG_PEEK, + MSG_NOSIGNAL type AsyncFD* = distinct cint diff --git a/lib/upcoming/asyncdispatch.nim b/lib/upcoming/asyncdispatch.nim index 0b5ff89ba..9a35cf3c8 100644 --- a/lib/upcoming/asyncdispatch.nim +++ b/lib/upcoming/asyncdispatch.nim @@ -878,9 +878,11 @@ when defined(windows) or defined(nimdoc): deallocShared(cast[pointer](pcd)) raiseOSError(osLastError()) else: - # we ref pcd.ovl one more time, because it will be unrefed in - # poll() + # we incref `pcd.ovl` and `protect` callback one more time, + # because it will be unrefed and disposed in `poll()` after + # callback finishes. GC_ref(pcd.ovl) + pcd.ovl.data.cell = system.protect(rawEnv(pcd.ovl.data.cb)) ) # We need to protect our callback environment value, so GC will not free it # accidentally. @@ -988,6 +990,9 @@ when defined(windows) or defined(nimdoc): deallocShared(cast[pointer](pcd)) p.handles.excl(fd) else: + # if callback returned `false`, then it wants to be called again, so + # we need to ref and protect `pcd.ovl` again, because it will be + # unrefed and disposed in `poll()`. GC_ref(pcd.ovl) pcd.ovl.data.cell = system.protect(rawEnv(pcd.ovl.data.cb)) @@ -1073,6 +1078,9 @@ when defined(windows) or defined(nimdoc): if ev.hWaiter != 0: unregister(ev) deallocShared(cast[pointer](pcd)) else: + # if callback returned `false`, then it wants to be called again, so + # we need to ref and protect `pcd.ovl` again, because it will be + # unrefed and disposed in `poll()`. GC_ref(pcd.ovl) pcd.ovl.data.cell = system.protect(rawEnv(pcd.ovl.data.cb)) @@ -1082,17 +1090,8 @@ when defined(windows) or defined(nimdoc): initAll() else: import ioselectors - when defined(windows): - import winlean - const - EINTR = WSAEINPROGRESS - EINPROGRESS = WSAEINPROGRESS - EWOULDBLOCK = WSAEWOULDBLOCK - EAGAIN = EINPROGRESS - MSG_NOSIGNAL = 0 - else: - from posix import EINTR, EAGAIN, EINPROGRESS, EWOULDBLOCK, MSG_PEEK, - MSG_NOSIGNAL + from posix import EINTR, EAGAIN, EINPROGRESS, EWOULDBLOCK, MSG_PEEK, + MSG_NOSIGNAL const supportedPlatform = defined(linux) or defined(freebsd) or defined(netbsd) or defined(openbsd) or |