diff options
author | bptato <nincsnevem662@gmail.com> | 2023-09-14 01:41:47 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-09-14 02:01:21 +0200 |
commit | c1b8338045716b25d664c0b8dd91eac0cb76480e (patch) | |
tree | a9c0a6763f180c2b6dd380aa880253ffc7685d85 /src/io/serversocket.nim | |
parent | db0798acccbedcef4b16737f6be0cf7388cc0528 (diff) | |
download | chawan-c1b8338045716b25d664c0b8dd91eac0cb76480e.tar.gz |
move around more modules
* ips -> io/ * loader related stuff -> loader/ * tempfile -> extern/ * buffer, forkserver -> server/ * lineedit, window -> display/ * cell -> types/ * opt -> types/
Diffstat (limited to 'src/io/serversocket.nim')
-rw-r--r-- | src/io/serversocket.nim | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/io/serversocket.nim b/src/io/serversocket.nim new file mode 100644 index 00000000..61b633a9 --- /dev/null +++ b/src/io/serversocket.nim @@ -0,0 +1,28 @@ +import nativesockets +import net +import os +when defined(posix): + import posix + +type ServerSocket* = object + sock*: Socket + path*: string + +var SocketDirectory* = "/tmp/cha" +const SocketPathPrefix = "cha_sock_" +proc getSocketPath*(pid: Pid): string = + SocketDirectory / SocketPathPrefix & $pid + +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) + listen(result.sock) + +proc close*(ssock: ServerSocket) = + close(ssock.sock) + discard unlink(cstring(ssock.path)) |