mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 07:21:19 +00:00
Test + fix for epoll and kqueue selector modules to properly unregister
event handles that have the key type "User"
This commit is contained in:
@@ -197,7 +197,7 @@ proc unregister*[T](s: Selector[T], fd: int|SocketHandle) =
|
||||
"Descriptor $# is not registered in the selector!" % $fdi)
|
||||
if pkey.events != {}:
|
||||
when not defined(android):
|
||||
if pkey.events * {Event.Read, Event.Write} != {}:
|
||||
if pkey.events * {Event.Read, Event.Write, Event.User} != {}:
|
||||
var epv = EpollEvent()
|
||||
# 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:
|
||||
|
||||
@@ -375,7 +375,7 @@ proc unregister*[T](s: Selector[T], fd: int|SocketHandle) =
|
||||
"Descriptor [" & $fdi & "] is not registered in the queue!")
|
||||
|
||||
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:
|
||||
modifyKQueue(s, uint(fdi), EVFILT_READ, EV_DELETE, 0, 0, nil)
|
||||
dec(s.count)
|
||||
@@ -632,4 +632,4 @@ template withData*[T](s: Selector[T], fd: SocketHandle|int, value, body1,
|
||||
|
||||
|
||||
proc getFd*[T](s: Selector[T]): int =
|
||||
return s.kqFD.int
|
||||
return s.kqFD.int
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user