about summary refs log tree commit diff stats
path: root/src/server
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-01-29 13:25:23 +0100
committerbptato <nincsnevem662@gmail.com>2024-01-29 13:26:15 +0100
commit9318ad33229d3c2f96dd766b38b8748f77487c5a (patch)
tree34dc6cbfd0a52d521d9d125fea626895ec3548c8 /src/server
parent619d5296dbfc77c37c13b86e4e96c356f1c3f61a (diff)
downloadchawan-9318ad33229d3c2f96dd766b38b8748f77487c5a.tar.gz
forkserver: clean up
Move forkBuffer into forkserver (why was it in container anyway), remove
unused mainproc variable, etc.
Diffstat (limited to 'src/server')
-rw-r--r--src/server/forkserver.nim24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/server/forkserver.nim b/src/server/forkserver.nim
index ea811955..9ad9c8a9 100644
--- a/src/server/forkserver.nim
+++ b/src/server/forkserver.nim
@@ -24,8 +24,8 @@ type
 
   ForkServer* = ref object
     process*: Pid
-    istream*: Stream
-    ostream*: Stream
+    istream: Stream
+    ostream: Stream
     estream*: PosixStream
 
   ForkServerContext = object
@@ -62,6 +62,17 @@ proc removeChild*(forkserver: ForkServer, pid: Pid) =
   forkserver.ostream.swrite(pid)
   forkserver.ostream.flush()
 
+proc forkBuffer*(forkserver: ForkServer, source: BufferSource,
+    config: BufferConfig, attrs: WindowAttributes): Pid =
+  forkserver.ostream.swrite(FORK_BUFFER)
+  forkserver.ostream.swrite(source)
+  forkserver.ostream.swrite(config)
+  forkserver.ostream.swrite(attrs)
+  forkserver.ostream.flush()
+  var process: Pid
+  forkserver.istream.sread(process)
+  return process
+
 proc trapSIGINT() =
   # trap SIGINT, so e.g. an external editor receiving an interrupt in the
   # same process group can't just kill the process
@@ -107,11 +118,9 @@ proc forkBuffer(ctx: var ForkServerContext): Pid =
   var source: BufferSource
   var config: BufferConfig
   var attrs: WindowAttributes
-  var mainproc: Pid
   ctx.istream.sread(source)
   ctx.istream.sread(config)
   ctx.istream.sread(attrs)
-  ctx.istream.sread(mainproc)
   let loaderPid = ctx.forkLoader(config.loaderConfig)
   var pipefd: array[2, cint]
   if pipe(pipefd) == -1:
@@ -158,9 +167,10 @@ proc forkBuffer(ctx: var ForkServerContext): Pid =
   return pid
 
 proc runForkServer() =
-  var ctx: ForkServerContext
-  ctx.istream = newPosixStream(stdin.getFileHandle())
-  ctx.ostream = newPosixStream(stdout.getFileHandle())
+  var ctx = ForkServerContext(
+    istream: newPosixStream(stdin.getFileHandle()),
+    ostream: newPosixStream(stdout.getFileHandle())
+  )
   while true:
     try:
       var cmd: ForkCommand