Test + fix for epoll and kqueue selector modules to properly unregister
event handles that have the key type "User"
This commit is contained in:
parent
5be8e0b088
commit
adc1419499
3 changed files with 26 additions and 3 deletions
|
|
@ -197,7 +197,7 @@ proc unregister*[T](s: Selector[T], fd: int|SocketHandle) =
|
||||||
"Descriptor $# is not registered in the selector!" % $fdi)
|
"Descriptor $# is not registered in the selector!" % $fdi)
|
||||||
if pkey.events != {}:
|
if pkey.events != {}:
|
||||||
when not defined(android):
|
when not defined(android):
|
||||||
if pkey.events * {Event.Read, Event.Write} != {}:
|
if pkey.events * {Event.Read, Event.Write, Event.User} != {}:
|
||||||
var epv = EpollEvent()
|
var epv = EpollEvent()
|
||||||
# TODO: Refactor all these EPOLL_CTL_DEL + dec(s.count) into a proc.
|
# TODO: Refactor all these EPOLL_CTL_DEL + dec(s.count) into a proc.
|
||||||
if epoll_ctl(s.epollFD, EPOLL_CTL_DEL, fdi.cint, addr epv) != 0:
|
if epoll_ctl(s.epollFD, EPOLL_CTL_DEL, fdi.cint, addr epv) != 0:
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ proc unregister*[T](s: Selector[T], fd: int|SocketHandle) =
|
||||||
"Descriptor [" & $fdi & "] is not registered in the queue!")
|
"Descriptor [" & $fdi & "] is not registered in the queue!")
|
||||||
|
|
||||||
if pkey.events != {}:
|
if pkey.events != {}:
|
||||||
if pkey.events * {Event.Read, Event.Write} != {}:
|
if pkey.events * {Event.Read, Event.Write, Event.User} != {}:
|
||||||
if Event.Read in pkey.events:
|
if Event.Read in pkey.events:
|
||||||
modifyKQueue(s, uint(fdi), EVFILT_READ, EV_DELETE, 0, 0, nil)
|
modifyKQueue(s, uint(fdi), EVFILT_READ, EV_DELETE, 0, 0, nil)
|
||||||
dec(s.count)
|
dec(s.count)
|
||||||
|
|
|
||||||
23
tests/async/testmanyasyncevents.nim
Normal file
23
tests/async/testmanyasyncevents.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
hasPendingOperations: false
|
||||||
|
triggerCount: 512
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncDispatch
|
||||||
|
|
||||||
|
var triggerCount = 0
|
||||||
|
var evs = newSeq[AsyncEvent]()
|
||||||
|
|
||||||
|
for i in 0 ..< 512: # has to be lower than the typical physical fd limit
|
||||||
|
var ev = newAsyncEvent()
|
||||||
|
evs.add(ev)
|
||||||
|
addEvent(ev, proc(fd: AsyncFD): bool {.gcsafe,closure.} = triggerCount += 1; true)
|
||||||
|
|
||||||
|
for ev in evs:
|
||||||
|
ev.trigger()
|
||||||
|
|
||||||
|
drain()
|
||||||
|
echo "hasPendingOperations: ", hasPendingOperations()
|
||||||
|
echo "triggerCount: ", triggerCount
|
||||||
Loading…
Add table
Add a link
Reference in a new issue