about summary refs log blame commit diff stats
path: root/src/ips/serversocket.nim
blob: b476320e3b7e91b0678e41131e203ce8770fd3fc (plain) (tree)
1
2
3
4
5
6
7
8
9

          


                    



                           



                                           
 
                                                       
                            pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right
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): ServerSocket =
  createDir(SocketDirectory)
  result.sock = newSocket(Domain.AF_UNIX, SockType.SOCK_STREAM, Protocol.IPPROTO_IP, buffered)
  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))
>) (rowidx:integer <- add rowidx:integer 1:literal) (x:boolean <- not-equal rowidx:integer nrows:integer) (loop-if x:boolean) } (reply result:screen-address) ])