diff options
Diffstat (limited to 'lib/upcoming/asyncdispatch.nim')
-rw-r--r-- | lib/upcoming/asyncdispatch.nim | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/upcoming/asyncdispatch.nim b/lib/upcoming/asyncdispatch.nim index f333244c6..ce44e8a6a 100644 --- a/lib/upcoming/asyncdispatch.nim +++ b/lib/upcoming/asyncdispatch.nim @@ -1373,19 +1373,25 @@ else: proc addRead*(fd: AsyncFD, cb: Callback) = let p = getGlobalDispatcher() + var newEvents = {Event.Read} withData(p.selector, fd.SocketHandle, adata) do: adata.readCB = cb + if adata.writeCB != nil: + newEvents.incl(Event.Write) do: raise newException(ValueError, "File descriptor not registered.") - p.selector.updateHandle(fd.SocketHandle, {Event.Read}) + p.selector.updateHandle(fd.SocketHandle, newEvents) proc addWrite*(fd: AsyncFD, cb: Callback) = let p = getGlobalDispatcher() + var newEvents = {Event.Write} withData(p.selector, fd.SocketHandle, adata) do: adata.writeCB = cb + if adata.readCB != nil: + newEvents.incl(Event.Read) do: raise newException(ValueError, "File descriptor not registered.") - p.selector.updateHandle(fd.SocketHandle, {Event.Write}) + p.selector.updateHandle(fd.SocketHandle, newEvents) proc poll*(timeout = 500) = var keys: array[64, ReadyKey[AsyncData]] |