From 179e6cf834092ef4938c6580750136cbf24085f4 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Fri, 8 Jun 2018 08:42:48 +0300 Subject: [PATCH] Fix asyncloop, to properly clear reader/writer data. --- asyncdispatch2/asyncloop.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/asyncdispatch2/asyncloop.nim b/asyncdispatch2/asyncloop.nim index 52bb7449..c8052201 100644 --- a/asyncdispatch2/asyncloop.nim +++ b/asyncdispatch2/asyncloop.nim @@ -466,8 +466,7 @@ else: withData(p.selector, int(fd), adata) do: let acb = AsyncCallback(function: cb, udata: addr adata.rdata) adata.reader = acb - adata.rdata.fd = fd - adata.rdata.udata = udata + adata.rdata = CompletionData(fd: fd, udata: udata) newEvents.incl(Event.Read) if not isNil(adata.writer.function): newEvents.incl(Event.Write) do: @@ -479,6 +478,9 @@ else: let p = getGlobalDispatcher() var newEvents: set[Event] withData(p.selector, int(fd), adata) do: + # We need to clear `reader` data, because `selectors` don't do it + adata.reader = AsyncCallback() + adata.rdata = CompletionData() if not isNil(adata.writer.function): newEvents.incl(Event.Write) do: raise newException(ValueError, "File descriptor not registered.") @@ -492,8 +494,7 @@ else: withData(p.selector, int(fd), adata) do: let acb = AsyncCallback(function: cb, udata: addr adata.wdata) adata.writer = acb - adata.wdata.fd = fd - adata.wdata.udata = udata + adata.wdata = CompletionData(fd: fd, udata: udata) newEvents.incl(Event.Write) if not isNil(adata.reader.function): newEvents.incl(Event.Read) do: @@ -505,6 +506,9 @@ else: let p = getGlobalDispatcher() var newEvents: set[Event] withData(p.selector, int(fd), adata) do: + # We need to clear `writer` data, because `selectors` don't do it + adata.writer = AsyncCallback() + adata.wdata = CompletionData() if not isNil(adata.reader.function): newEvents.incl(Event.Read) do: raise newException(ValueError, "File descriptor not registered.")