summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authordef <dennis@felsin9.de>2015-01-04 22:59:41 +0100
committerdef <dennis@felsin9.de>2015-01-04 22:59:41 +0100
commitd60d0072813046dae7a00874fca601c7fce71e29 (patch)
tree71630f08271b4d75780ae6bf314f72db69161b8a /lib/pure
parent5ee4806aa322a0943efdd0fb89b5c2d1b1c1ce40 (diff)
downloadNim-d60d0072813046dae7a00874fca601c7fce71e29.tar.gz
Close async socket on error (instead of looping on epoll_wait with 100% CPU)
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/asyncdispatch.nim4
-rw-r--r--lib/pure/selectors.nim5
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim
index 4bdce9cfb..c4abdf9f3 100644
--- a/lib/pure/asyncdispatch.nim
+++ b/lib/pure/asyncdispatch.nim
@@ -878,6 +878,10 @@ else:
       let data = PData(info.key.data)
       assert data.fd == info.key.fd.TAsyncFD
       #echo("In poll ", data.fd.cint)
+      if EvError in info.events:
+        closeSocket(data.fd)
+        continue
+
       if EvRead in info.events:
         # Callback may add items to ``data.readCBs`` which causes issues if
         # we are iterating over ``data.readCBs`` at the same time. We therefore
diff --git a/lib/pure/selectors.nim b/lib/pure/selectors.nim
index 1c988c609..b796dca7a 100644
--- a/lib/pure/selectors.nim
+++ b/lib/pure/selectors.nim
@@ -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]