Fix asyncloop, to properly clear reader/writer data.

This commit is contained in:
cheatfate 2018-06-08 08:42:48 +03:00
parent de7e0f41e9
commit 179e6cf834
1 changed files with 8 additions and 4 deletions

View File

@ -466,8 +466,7 @@ else:
withData(p.selector, int(fd), adata) do: withData(p.selector, int(fd), adata) do:
let acb = AsyncCallback(function: cb, udata: addr adata.rdata) let acb = AsyncCallback(function: cb, udata: addr adata.rdata)
adata.reader = acb adata.reader = acb
adata.rdata.fd = fd adata.rdata = CompletionData(fd: fd, udata: udata)
adata.rdata.udata = udata
newEvents.incl(Event.Read) newEvents.incl(Event.Read)
if not isNil(adata.writer.function): newEvents.incl(Event.Write) if not isNil(adata.writer.function): newEvents.incl(Event.Write)
do: do:
@ -479,6 +478,9 @@ else:
let p = getGlobalDispatcher() let p = getGlobalDispatcher()
var newEvents: set[Event] var newEvents: set[Event]
withData(p.selector, int(fd), adata) do: 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) if not isNil(adata.writer.function): newEvents.incl(Event.Write)
do: do:
raise newException(ValueError, "File descriptor not registered.") raise newException(ValueError, "File descriptor not registered.")
@ -492,8 +494,7 @@ else:
withData(p.selector, int(fd), adata) do: withData(p.selector, int(fd), adata) do:
let acb = AsyncCallback(function: cb, udata: addr adata.wdata) let acb = AsyncCallback(function: cb, udata: addr adata.wdata)
adata.writer = acb adata.writer = acb
adata.wdata.fd = fd adata.wdata = CompletionData(fd: fd, udata: udata)
adata.wdata.udata = udata
newEvents.incl(Event.Write) newEvents.incl(Event.Write)
if not isNil(adata.reader.function): newEvents.incl(Event.Read) if not isNil(adata.reader.function): newEvents.incl(Event.Read)
do: do:
@ -505,6 +506,9 @@ else:
let p = getGlobalDispatcher() let p = getGlobalDispatcher()
var newEvents: set[Event] var newEvents: set[Event]
withData(p.selector, int(fd), adata) do: 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) if not isNil(adata.reader.function): newEvents.incl(Event.Read)
do: do:
raise newException(ValueError, "File descriptor not registered.") raise newException(ValueError, "File descriptor not registered.")