about summary refs log tree commit diff stats
path: root/src/ips/forkserver.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-08-13 17:42:34 +0200
committerbptato <nincsnevem662@gmail.com>2023-08-13 17:54:05 +0200
commitd526deb99e44f2a8d1a9c3eea60676703dd64302 (patch)
treef63689ff7654d14ad9bca182a837b3155b2471a0 /src/ips/forkserver.nim
parentf92e30232252deb194596e7c298cc7fcf56517cb (diff)
downloadchawan-d526deb99e44f2a8d1a9c3eea60676703dd64302.tar.gz
Add mailcap, mime.types & misc refactorings
* add mailcap: works with copiousoutput, needsterminal, etc.
* add mime.types (only works with mailcap)
* refactor pipeBuffer
* remove "dispatcher"
* fix bug in directory display where baseurl would not be used
Diffstat (limited to 'src/ips/forkserver.nim')
-rw-r--r--src/ips/forkserver.nim18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/ips/forkserver.nim b/src/ips/forkserver.nim
index 62d41198..ec0c60d1 100644
--- a/src/ips/forkserver.nim
+++ b/src/ips/forkserver.nim
@@ -1,5 +1,6 @@
 import options
 import streams
+import tables
 
 when defined(posix):
   import posix
@@ -36,7 +37,6 @@ type
 proc newFileLoader*(forkserver: ForkServer, defaultHeaders: Headers = nil,
     filter = newURLFilter(default = true), cookiejar: CookieJar = nil,
     proxy: URL = nil, acceptProxy = false): FileLoader =
-  new(result)
   forkserver.ostream.swrite(FORK_LOADER)
   var defaultHeaders = defaultHeaders
   if defaultHeaders == nil:
@@ -51,7 +51,9 @@ proc newFileLoader*(forkserver: ForkServer, defaultHeaders: Headers = nil,
   )
   forkserver.ostream.swrite(config)
   forkserver.ostream.flush()
-  forkserver.istream.sread(result.process)
+  var process: Pid
+  forkserver.istream.sread(process)
+  return FileLoader(process: process)
 
 proc loadForkServerConfig*(forkserver: ForkServer, config: Config) =
   forkserver.ostream.swrite(LOAD_CONFIG)
@@ -117,7 +119,8 @@ proc forkBuffer(ctx: var ForkServerContext): Pid =
       filter: config.filter,
       cookiejar: config.cookiejar,
       referrerpolicy: config.referrerpolicy,
-      proxy: config.proxy
+      #TODO these should be in a separate config I think
+      proxy: config.proxy,
     )
   )
   let pid = fork()
@@ -190,7 +193,6 @@ proc runForkServer() =
   quit(0)
 
 proc newForkServer*(): ForkServer =
-  new(result)
   var pipefd_in: array[2, cint] # stdin in forkserver
   var pipefd_out: array[2, cint] # stdout in forkserver
   var pipefd_err: array[2, cint] # stderr in forkserver
@@ -230,7 +232,9 @@ proc newForkServer*(): ForkServer =
       raise newException(Defect, "Failed to open output handle")
     if not open(readf, pipefd_out[0], fmRead):
       raise newException(Defect, "Failed to open input handle")
-    result.ostream = newFileStream(writef)
-    result.istream = newFileStream(readf)
-    result.estream = newPosixStream(pipefd_err[0])
     discard fcntl(pipefd_err[0], F_SETFL, fcntl(pipefd_err[0], F_GETFL, 0) or O_NONBLOCK)
+    return ForkServer(
+      ostream: newFileStream(writef),
+      istream: newFileStream(readf),
+      estream: newPosixStream(pipefd_err[0])
+    )