about summary refs log tree commit diff stats
path: root/src/ips
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-11-27 22:01:03 +0100
committerbptato <nincsnevem662@gmail.com>2022-11-27 22:16:16 +0100
commit4df668fd2225278d4745a67613efd9859bc8c1a0 (patch)
tree4e689276743ee1deddd8175e1eb09159c6fb0115 /src/ips
parentfddc8d8da34b2f05b99d56b3c753a7b00d54ae7c (diff)
downloadchawan-4df668fd2225278d4745a67613efd9859bc8c1a0.tar.gz
Rework broken non-blocking io
Piped input works correctly again!
(Also fix hash's setter not working with url's without a fragment)
Diffstat (limited to 'src/ips')
-rw-r--r--src/ips/socketstream.nim16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/ips/socketstream.nim b/src/ips/socketstream.nim
index 6df9f09b..df4bbf09 100644
--- a/src/ips/socketstream.nim
+++ b/src/ips/socketstream.nim
@@ -15,13 +15,7 @@ type SocketStream* = ref object of Stream
 
 proc sockReadData(s: Stream, buffer: pointer, len: int): int =
   let s = SocketStream(s)
-  try:
-    if s.recvw:
-      result = s.source.recv(buffer, len, 100)
-    else:
-      result = s.source.recv(buffer, len)
-  except TimeoutError:
-    return
+  result = s.source.recv(buffer, len)
   if result < 0:
     raise newException(IOError, "Failed to read data (code " & $osLastError() & ")")
   elif result < len:
@@ -88,15 +82,17 @@ func newSocketStream*(): SocketStream =
   result.atEndImpl = sockAtEnd
   result.closeImpl = sockClose
 
-proc connectSocketStream*(path: string, buffered = true): SocketStream =
+proc connectSocketStream*(path: string, buffered = true, blocking = true): SocketStream =
   result = newSocketStream()
   let sock = newSocket(Domain.AF_UNIX, SockType.SOCK_STREAM, Protocol.IPPROTO_IP, buffered)
+  #if not blocking:
+  #  sock.getFd().setBlocking(false)
   connectUnix(sock, path)
   result.source = sock
 
-proc connectSocketStream*(pid: Pid, buffered = true): SocketStream =
+proc connectSocketStream*(pid: Pid, buffered = true, blocking = true): SocketStream =
   try:
-    connectSocketStream(getSocketPath(pid), buffered)
+    connectSocketStream(getSocketPath(pid), buffered, blocking)
   except OSError:
     return nil