about summary refs log tree commit diff stats
path: root/src/buffer
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-05 14:04:46 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-05 14:05:20 +0200
commitc5d774073a90d122c757b677c149e11c7564e8e0 (patch)
tree187c747efb7fbf6e438ffad9c3ae6a45720e96dd /src/buffer
parent06c0dd1741af58eb55c27601b070010ad6c50dc8 (diff)
downloadchawan-c5d774073a90d122c757b677c149e11c7564e8e0.tar.gz
buffer: call handleError before handleRead & misc
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/buffer.nim12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim
index d668a01d..dc41ba6c 100644
--- a/src/buffer/buffer.nim
+++ b/src/buffer/buffer.nim
@@ -1137,7 +1137,7 @@ proc handleRead(buffer: Buffer, fd: int) =
     discard #TODO hack
   else: assert false
 
-proc handleError(buffer: Buffer, fd: int) =
+proc handleError(buffer: Buffer, fd: int, err: OSErrorCode) =
   if fd == buffer.rfd:
     # Connection reset by peer, probably. Close the buffer.
     buffer.alive = false
@@ -1145,26 +1145,26 @@ proc handleError(buffer: Buffer, fd: int) =
     buffer.onload()
   elif fd in buffer.loader.connecting:
     # probably shouldn't happen. TODO
-    assert false
+    assert false, $fd & ": " & $err
   elif fd in buffer.loader.ongoing:
     #TODO something with readablestream?
     discard
   elif buffer.fd == -1 and fd == buffer.oldfd:
     discard #TODO hack
   else:
-    assert false
+    assert false, $fd & ": " & $err
 
 proc runBuffer(buffer: Buffer, rfd: int) =
   buffer.rfd = rfd
   while buffer.alive:
     let events = buffer.selector.select(-1)
     for event in events:
+      if Read in event.events:
+        buffer.handleRead(event.fd)
       if Error in event.events:
-        buffer.handleError(event.fd)
+        buffer.handleError(event.fd, event.errorCode)
       if not buffer.alive:
         break
-      if Read in event.events:
-        buffer.handleRead(event.fd)
       if Event.Timer in event.events:
         assert buffer.window != nil
         assert buffer.window.timeouts.runTimeoutFd(event.fd)