Close async socket on error (instead of looping on epoll_wait with 100% CPU)
This commit is contained in:
parent
5ee4806aa3
commit
d60d007281
2 changed files with 8 additions and 1 deletions
|
|
@ -23,7 +23,7 @@ proc `$`*(x: SocketHandle): string {.borrow.}
|
|||
|
||||
type
|
||||
Event* = enum
|
||||
EvRead, EvWrite
|
||||
EvRead, EvWrite, EvError
|
||||
|
||||
SelectorKey* = ref object
|
||||
fd*: SocketHandle
|
||||
|
|
@ -152,6 +152,9 @@ elif defined(linux):
|
|||
let fd = s.events[i].data.fd.SocketHandle
|
||||
|
||||
var evSet: set[Event] = {}
|
||||
if (s.events[i].events and EPOLLERR) != 0: evSet = evSet + {EvError}
|
||||
if (s.events[i].events and EPOLLHUP) != 0: evSet = evSet + {EvError}
|
||||
if (s.events[i].events and EPOLLRDHUP) != 0: evSet = evSet + {EvError}
|
||||
if (s.events[i].events and EPOLLIN) != 0: evSet = evSet + {EvRead}
|
||||
if (s.events[i].events and EPOLLOUT) != 0: evSet = evSet + {EvWrite}
|
||||
let selectorKey = s.fds[fd]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue