about summary refs log tree commit diff stats
path: root/src/server/buffer.nim
Commit message (Expand)AuthorAgeFilesLines
* dom: add document.readyStatebptato2023-11-271-2/+4
* buffer: add DOMContentLoaded, misc event improvementsbptato2023-11-271-46/+72
* buffer: call onload function on dispatchLoadEventbptato2023-11-211-3/+13
* buffer: optimize findPrevLinkbptato2023-11-201-0/+8
* buffer: remove viewport referencebptato2023-10-281-7/+1
* renderdocument: slightly refactor, optimize addLinesbptato2023-10-261-4/+13
* buffer: close ssock on exitbptato2023-10-261-0/+1
* buffer: call load event on loadbptato2023-10-251-1/+13
* Remove trailing spacesbptato2023-10-231-1/+1
* warn on eprint in release modebptato2023-10-211-1/+1
* WindowAttributes: refactorbptato2023-10-191-1/+1
* container: add cursorNthLink, cursorRevNthLinkbptato2023-10-141-4/+38
* buffer: fix cursor unnecessarily jumping to y=0bptato2023-09-301-5/+7
* Improve implicit form submissionbptato2023-09-301-2/+11
* Add urimethodmap supportbptato2023-09-301-2/+5
* buffer: improve submitFormbptato2023-09-301-6/+42
* loader: add local-cgibptato2023-09-301-1/+1
* Response.text: encode/decode properlybptato2023-09-271-5/+8
* buffer: simplify contentType handlingbptato2023-09-271-24/+20
* interface clone: remove unused arg, documentbptato2023-09-271-4/+9
* Add precnum support to more functionsbptato2023-09-261-6/+18
* buffer: make readFromFd work with pipesbptato2023-09-231-4/+17
* buffer: make clone fork()bptato2023-09-231-19/+144
* buffer: support <a name=... for anchor navigationbptato2023-09-201-3/+3
* loader: add gopher supportbptato2023-09-201-2/+3
* update chamebptato2023-09-191-1/+2
* Fix compilation with --assertions:offbptato2023-09-151-1/+2
* buffer: directly pass EncoderStream to parseStylesheetbptato2023-09-141-3/+2
* Update submodulesbptato2023-09-141-1/+3
* move around more modulesbptato2023-09-141-0/+1481
ground-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
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))