about summary refs log tree commit diff stats
path: root/src/ips/serversocket.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-29 18:09:34 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-29 18:30:57 +0200
commitcd6b8bf5cf93ada0ee60202c249ae80693e5ca89 (patch)
tree2c1865bda4a795c10cad36baba06b14845557d79 /src/ips/serversocket.nim
parent09be1d576ce815d80df1b625366de5965971430c (diff)
downloadchawan-cd6b8bf5cf93ada0ee60202c249ae80693e5ca89.tar.gz
Do not block indefinitely if buffer crashes before accept
Kind of a hack, but better than nothing.
Diffstat (limited to 'src/ips/serversocket.nim')
-rw-r--r--src/ips/serversocket.nim5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/ips/serversocket.nim b/src/ips/serversocket.nim
index b476320e..61b633a9 100644
--- a/src/ips/serversocket.nim
+++ b/src/ips/serversocket.nim
@@ -1,3 +1,4 @@
+import nativesockets
 import net
 import os
 when defined(posix):
@@ -12,9 +13,11 @@ const SocketPathPrefix = "cha_sock_"
 proc getSocketPath*(pid: Pid): string =
   SocketDirectory / SocketPathPrefix & $pid
 
-proc initServerSocket*(buffered = true): ServerSocket =
+proc initServerSocket*(buffered = true, blocking = true): ServerSocket =
   createDir(SocketDirectory)
   result.sock = newSocket(Domain.AF_UNIX, SockType.SOCK_STREAM, Protocol.IPPROTO_IP, buffered)
+  if not blocking:
+    result.sock.getFd().setBlocking(false)
   result.path = getSocketPath(getpid())
   discard unlink(cstring(result.path))
   bindUnix(result.sock, result.path)