fixes based on code review by @dom96
- For clarity: Changed the unregister if statement to use the in operator instead of the set intersection operator in ioselectors_epoll.nim and ioselectors_select.nim. - Fixed unregister of Event.User case on the Android branch.
This commit is contained in:
parent
233455a685
commit
bef1c4437d
2 changed files with 4 additions and 4 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, Event.User} != {}:
|
if Event.Read in pkey.events or Event.Write in pkey.events or Event.User in pkey.events:
|
||||||
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:
|
||||||
|
|
@ -237,7 +237,7 @@ proc unregister*[T](s: Selector[T], fd: int|SocketHandle) =
|
||||||
if posix.close(cint(fdi)) != 0:
|
if posix.close(cint(fdi)) != 0:
|
||||||
raiseIOSelectorsError(osLastError())
|
raiseIOSelectorsError(osLastError())
|
||||||
else:
|
else:
|
||||||
if pkey.events * {Event.Read, Event.Write} != {}:
|
if Event.Read in pkey.events or Event.Write in pkey.events or Event.User in pkey.events:
|
||||||
var epv = EpollEvent()
|
var epv = EpollEvent()
|
||||||
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:
|
||||||
raiseIOSelectorsError(osLastError())
|
raiseIOSelectorsError(osLastError())
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ proc unregister*[T](s: Selector[T], fd: SocketHandle|int) =
|
||||||
s.withSelectLock():
|
s.withSelectLock():
|
||||||
let fd = fd.SocketHandle
|
let fd = fd.SocketHandle
|
||||||
var pkey = s.getKey(fd)
|
var pkey = s.getKey(fd)
|
||||||
if pkey.events * {Event.Read, Event.User} != {}:
|
if Event.Read in pkey.events or Event.User in pkey.events:
|
||||||
IOFD_CLR(fd, addr s.rSet)
|
IOFD_CLR(fd, addr s.rSet)
|
||||||
dec(s.count)
|
dec(s.count)
|
||||||
if Event.Write in pkey.events:
|
if Event.Write in pkey.events:
|
||||||
|
|
@ -462,4 +462,4 @@ template withData*[T](s: Selector[T], fd: SocketHandle|int, value,
|
||||||
|
|
||||||
|
|
||||||
proc getFd*[T](s: Selector[T]): int =
|
proc getFd*[T](s: Selector[T]): int =
|
||||||
return -1
|
return -1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue