about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-07-29 21:31:19 +0200
committerbptato <nincsnevem662@gmail.com>2024-07-29 23:24:34 +0200
commit90fa62f49f7f3b80bb89033a740be7a7e9e5cbb3 (patch)
tree3066458b5de642193a4c836f613695f5fb24c864
parente01fa3b643966bd64d0f244f1e604f81107604fe (diff)
downloadchawan-90fa62f49f7f3b80bb89033a740be7a7e9e5cbb3.tar.gz
Fixes for Nim 2.2
* xmlhttprequest: fix missing import
* painter: generic tuple workaround
* dynstream: merge module with implementations (so it will work with
  vtables)

Not enabling vtables yet since it doesn't work with refc.
-rw-r--r--src/html/env.nim2
-rw-r--r--src/html/formdata.nim1
-rw-r--r--src/html/xmlhttprequest.nim1
-rw-r--r--src/img/painter.nim16
-rw-r--r--src/io/bufreader.nim1
-rw-r--r--src/io/bufstream.nim53
-rw-r--r--src/io/bufwriter.nim1
-rw-r--r--src/io/dynstream.nim269
-rw-r--r--src/io/filestream.nim34
-rw-r--r--src/io/posixstream.nim77
-rw-r--r--src/io/socketstream.nim111
-rw-r--r--src/loader/cgi.nim1
-rw-r--r--src/loader/loader.nim2
-rw-r--r--src/loader/loaderhandle.nim1
-rw-r--r--src/loader/response.nim3
-rw-r--r--src/local/client.nim4
-rw-r--r--src/local/container.nim2
-rw-r--r--src/local/pager.nim2
-rw-r--r--src/local/term.nim2
-rw-r--r--src/server/buffer.nim4
-rw-r--r--src/server/forkserver.nim2
-rw-r--r--src/types/formdata.nim1
22 files changed, 283 insertions, 307 deletions
diff --git a/src/html/env.nim b/src/html/env.nim
index 187968e3..7117a9b0 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -7,7 +7,7 @@ import html/event
 import html/formdata
 import html/script
 import html/xmlhttprequest
-import io/filestream
+import io/dynstream
 import io/promise
 import js/base64
 import js/console
diff --git a/src/html/formdata.nim b/src/html/formdata.nim
index df839d3f..687c5600 100644
--- a/src/html/formdata.nim
+++ b/src/html/formdata.nim
@@ -3,7 +3,6 @@ import html/catom
 import html/dom
 import html/enums
 import io/dynstream
-import io/posixstream
 import js/base64
 import js/domexception
 import monoucha/javascript
diff --git a/src/html/xmlhttprequest.nim b/src/html/xmlhttprequest.nim
index 8ac94792..c402f6b4 100644
--- a/src/html/xmlhttprequest.nim
+++ b/src/html/xmlhttprequest.nim
@@ -5,6 +5,7 @@ import std/tables
 import html/catom
 import html/dom
 import html/event
+import html/script
 import io/promise
 import js/domexception
 import loader/headers
diff --git a/src/img/painter.nim b/src/img/painter.nim
index 4e8d1f72..7b844447 100644
--- a/src/img/painter.nim
+++ b/src/img/painter.nim
@@ -138,15 +138,19 @@ proc clearRect*(bmp: Bitmap; x0, x1, y0, y1: uint64) =
 proc clear*(bmp: Bitmap) =
   bmp.clearRect(0, bmp.width, 0, bmp.height)
 
+type GlyphCacheItem = object
+  u: uint32
+  bmp: Bitmap
+
 var unifontBitmap*: Bitmap = nil
-var glyphCache: seq[tuple[u: uint32, bmp: Bitmap]]
+var glyphCache: seq[GlyphCacheItem] = @[]
 var glyphCacheI = 0
 proc getCharBmp(u: uint32): Bitmap =
   # We only have the BMP.
   let u = if u <= 0xFFFF: u else: 0xFFFD
-  for (cu, bmp) in glyphCache:
-    if cu == u:
-      return bmp
+  for it in glyphCache:
+    if it.u == u:
+      return it.bmp
   # Unifont glyphs start at x: 32, y: 64, and are of 8x16/16x16 size
   let gx = uint64(32 + 16 * (u mod 0x100))
   let gy = uint64(64 + 16 * (u div 0x100))
@@ -166,9 +170,9 @@ proc getCharBmp(u: uint32): Bitmap =
       if c != white:
         bmp.setpx(x, y, c)
   if glyphCache.len < 256:
-    glyphCache.add((u, bmp))
+    glyphCache.add(GlyphCacheItem(u: u, bmp: bmp))
   else:
-    glyphCache[glyphCacheI] = (u, bmp)
+    glyphCache[glyphCacheI] = GlyphCacheItem(u: u, bmp: bmp)
     inc glyphCacheI
     if glyphCacheI >= glyphCache.len:
       glyphCacheI = 0
diff --git a/src/io/bufreader.nim b/src/io/bufreader.nim
index 5f522666..bc448edf 100644
--- a/src/io/bufreader.nim
+++ b/src/io/bufreader.nim
@@ -4,7 +4,6 @@ import std/tables
 
 import img/bitmap
 import io/dynstream
-import io/socketstream
 import loader/request
 import types/blob
 import types/color
diff --git a/src/io/bufstream.nim b/src/io/bufstream.nim
index 3dba86f1..e69de29b 100644
--- a/src/io/bufstream.nim
+++ b/src/io/bufstream.nim
@@ -1,53 +0,0 @@
-import io/dynstream
-import io/posixstream
-
-type
-  BufStream* = ref object of DynStream
-    source*: PosixStream
-    registerFun: proc(fd: int)
-    registered: bool
-    writeBuffer: string
-
-method recvData*(s: BufStream; buffer: pointer; len: int): int =
-  s.source.recvData(buffer, len)
-
-method sendData*(s: BufStream; buffer: pointer; len: int): int =
-  s.source.setBlocking(false)
-  block nobuf:
-    var n: int
-    if not s.registered:
-      try:
-        n = s.source.sendData(buffer, len)
-        if n == len:
-          break nobuf
-      except ErrorAgain:
-        discard
-      s.registerFun(s.source.fd)
-      s.registered = true
-    let olen = s.writeBuffer.len
-    s.writeBuffer.setLen(s.writeBuffer.len + len - n)
-    let buffer = cast[ptr UncheckedArray[uint8]](buffer)
-    copyMem(addr s.writeBuffer[olen], addr buffer[n], len - n)
-  s.source.setBlocking(true)
-  return len
-
-method sclose*(s: BufStream) =
-  s.source.sclose()
-
-proc flushWrite*(s: BufStream): bool =
-  s.source.setBlocking(false)
-  let n = s.source.sendData(s.writeBuffer)
-  s.source.setBlocking(true)
-  if n == s.writeBuffer.len:
-    s.writeBuffer = ""
-    s.registered = false
-    return true
-  s.writeBuffer = s.writeBuffer.substr(n)
-  return false
-
-proc reallyFlush*(s: BufStream) =
-  if s.writeBuffer.len > 0:
-    s.source.sendDataLoop(s.writeBuffer)
-
-proc newBufStream*(ps: PosixStream; registerFun: proc(fd: int)): BufStream =
-  return BufStream(source: ps, blocking: ps.blocking, registerFun: registerFun)
diff --git a/src/io/bufwriter.nim b/src/io/bufwriter.nim
index 8166eab8..437fa24f 100644
--- a/src/io/bufwriter.nim
+++ b/src/io/bufwriter.nim
@@ -7,7 +7,6 @@ import std/tables
 
 import img/bitmap
 import io/dynstream
-import io/socketstream
 import loader/request
 import types/blob
 import types/color
diff --git a/src/io/dynstream.nim b/src/io/dynstream.nim
index 65077734..9e23a8ae 100644
--- a/src/io/dynstream.nim
+++ b/src/io/dynstream.nim
@@ -1,3 +1,10 @@
+import std/nativesockets
+import std/net
+import std/os
+import std/posix
+
+import io/serversocket
+
 type
   DynStream* = ref object of RootObj
     isend*: bool
@@ -84,3 +91,265 @@ proc recvAll*(s: DynStream): string =
       buffer.setLen(buffer.len + 4096)
   buffer.setLen(idx)
   return buffer
+
+type
+  PosixStream* = ref object of DynStream
+    fd*: cint
+
+  ErrorAgain* = object of IOError
+  ErrorBadFD* = object of IOError
+  ErrorFault* = object of IOError
+  ErrorInterrupted* = object of IOError
+  ErrorInvalid* = object of IOError
+  ErrorConnectionReset* = object of IOError
+  ErrorBrokenPipe* = object of IOError
+
+proc raisePosixIOError() =
+  # In the nim stdlib, these are only constants on linux amd64, so we
+  # can't use a switch.
+  if errno == EAGAIN or errno == EWOULDBLOCK:
+    raise newException(ErrorAgain, "eagain")
+  elif errno == EBADF:
+    raise newException(ErrorBadFD, "bad fd")
+  elif errno == EFAULT:
+    raise newException(ErrorFault, "fault")
+  elif errno == EINVAL:
+    raise newException(ErrorInvalid, "invalid")
+  elif errno == ECONNRESET:
+    raise newException(ErrorConnectionReset, "connection reset by peer")
+  elif errno == EPIPE:
+    raise newException(ErrorBrokenPipe, "broken pipe")
+  else:
+    raise newException(IOError, $strerror(errno))
+
+method recvData*(s: PosixStream; buffer: pointer; len: int): int =
+  let n = read(s.fd, buffer, len)
+  if n < 0:
+    raisePosixIOError()
+  if n == 0:
+    if unlikely(s.isend):
+      raise newException(EOFError, "eof")
+    s.isend = true
+  return n
+
+proc sreadChar*(s: PosixStream): char =
+  let n = read(s.fd, addr result, 1)
+  assert n == 1
+
+method sendData*(s: PosixStream; buffer: pointer; len: int): int =
+  let n = write(s.fd, buffer, len)
+  if n < 0:
+    raisePosixIOError()
+  return n
+
+method setBlocking*(s: PosixStream; blocking: bool) {.base.} =
+  s.blocking = blocking
+  let ofl = fcntl(s.fd, F_GETFL, 0)
+  if blocking:
+    discard fcntl(s.fd, F_SETFL, ofl and not O_NONBLOCK)
+  else:
+    discard fcntl(s.fd, F_SETFL, ofl or O_NONBLOCK)
+
+method seek*(s: PosixStream; off: int) =
+  if lseek(s.fd, Off(off), SEEK_SET) == -1:
+    raisePosixIOError()
+
+method sclose*(s: PosixStream) =
+  discard close(s.fd)
+
+proc newPosixStream*(fd: FileHandle): PosixStream =
+  return PosixStream(fd: fd, blocking: true)
+
+proc newPosixStream*(path: string; flags, mode: cint): PosixStream =
+  let fd = open(cstring(path), flags, mode)
+  if fd == -1:
+    return nil
+  return newPosixStream(fd)
+
+type SocketStream* = ref object of PosixStream
+  source*: Socket
+
+method recvData*(s: SocketStream; buffer: pointer; len: int): int =
+  let n = s.source.recv(buffer, len)
+  if n < 0:
+    raisePosixIOError()
+  if n == 0:
+    if unlikely(s.isend):
+      raise newException(EOFError, "eof")
+    s.isend = true
+  return n
+
+method sendData*(s: SocketStream; buffer: pointer; len: int): int =
+  let n = s.source.send(buffer, len)
+  if n < 0:
+    raisePosixIOError()
+  return n
+
+{.compile: "sendfd.c".}
+proc sendfd(sock, fd: cint): int {.importc.}
+
+proc sendFileHandle*(s: SocketStream; fd: FileHandle) =
+  assert not s.source.hasDataBuffered
+  let n = sendfd(s.fd, cint(fd))
+  if n < 0:
+    raisePosixIOError()
+  assert n == 1 # we send a single nul byte as buf
+
+{.compile: "recvfd.c".}
+proc recvfd(sock: cint; fdout: ptr cint): int {.importc.}
+
+proc recvFileHandle*(s: SocketStream): FileHandle =
+  assert not s.source.hasDataBuffered
+  var fd: cint
+  let n = recvfd(s.fd, addr fd)
+  if n < 0:
+    raisePosixIOError()
+  return FileHandle(fd)
+
+method setBlocking*(s: SocketStream; blocking: bool) =
+  s.blocking = blocking
+  s.source.getFd().setBlocking(blocking)
+
+method seek*(s: SocketStream; off: int) =
+  doAssert false
+
+method sclose*(s: SocketStream) =
+  s.source.close()
+
+# see serversocket.nim for an explanation
+{.compile: "connect_unix.c".}
+proc connect_unix_from_c(fd: cint; path: cstring; pathlen: cint): cint
+  {.importc.}
+when defined(freebsd):
+  # for FreeBSD/capsicum
+  proc connectat_unix_from_c(baseFd, sockFd: cint; rel_path: cstring;
+    rel_pathlen: cint): cint {.importc.}
+
+proc connectAtSocketStream0(socketDir: string; baseFd, pid: int;
+    blocking = true): SocketStream =
+  let sock = newSocket(Domain.AF_UNIX, SockType.SOCK_STREAM,
+    Protocol.IPPROTO_IP, buffered = false)
+  if not blocking:
+    sock.getFd().setBlocking(false)
+  let path = getSocketPath(socketDir, pid)
+  if baseFd == -1:
+    if connect_unix_from_c(cint(sock.getFd()), cstring(path),
+        cint(path.len)) != 0:
+      raiseOSError(osLastError())
+  else:
+    when defined(freebsd):
+      doAssert baseFd != -1
+      let name = getSocketName(pid)
+      if connectat_unix_from_c(cint(baseFd), cint(sock.getFd()), cstring(name),
+          cint(name.len)) != 0:
+        raiseOSError(osLastError())
+    else:
+      # shouldn't have sockDirFd on other architectures
+      doAssert false
+  return SocketStream(
+    source: sock,
+    fd: cint(sock.getFd()),
+    blocking: blocking
+  )
+
+proc connectSocketStream*(socketDir: string; baseFd, pid: int;
+    blocking = true): SocketStream =
+  try:
+    return connectAtSocketStream0(socketDir, baseFd, pid, blocking)
+  except OSError:
+    return nil
+
+proc acceptSocketStream*(ssock: ServerSocket; blocking = true): SocketStream =
+  var sock: Socket
+  ssock.sock.accept(sock, inheritable = true)
+  if not blocking:
+    sock.getFd().setBlocking(false)
+  return SocketStream(
+    blocking: blocking,
+    source: sock,
+    fd: cint(sock.getFd())
+  )
+
+type
+  BufStream* = ref object of DynStream
+    source*: PosixStream
+    registerFun: proc(fd: int)
+    registered: bool
+    writeBuffer: string
+
+method recvData*(s: BufStream; buffer: pointer; len: int): int =
+  s.source.recvData(buffer, len)
+
+method sendData*(s: BufStream; buffer: pointer; len: int): int =
+  s.source.setBlocking(false)
+  block nobuf:
+    var n: int
+    if not s.registered:
+      try:
+        n = s.source.sendData(buffer, len)
+        if n == len:
+          break nobuf
+      except ErrorAgain:
+        discard
+      s.registerFun(s.source.fd)
+      s.registered = true
+    let olen = s.writeBuffer.len
+    s.writeBuffer.setLen(s.writeBuffer.len + len - n)
+    let buffer = cast[ptr UncheckedArray[uint8]](buffer)
+    copyMem(addr s.writeBuffer[olen], addr buffer[n], len - n)
+  s.source.setBlocking(true)
+  return len
+
+method sclose*(s: BufStream) =
+  s.source.sclose()
+
+proc flushWrite*(s: BufStream): bool =
+  s.source.setBlocking(false)
+  let n = s.source.sendData(s.writeBuffer)
+  s.source.setBlocking(true)
+  if n == s.writeBuffer.len:
+    s.writeBuffer = ""
+    s.registered = false
+    return true
+  s.writeBuffer = s.writeBuffer.substr(n)
+  return false
+
+proc reallyFlush*(s: BufStream) =
+  if s.writeBuffer.len > 0:
+    s.source.sendDataLoop(s.writeBuffer)
+
+proc newBufStream*(ps: PosixStream; registerFun: proc(fd: int)): BufStream =
+  return BufStream(source: ps, blocking: ps.blocking, registerFun: registerFun)
+
+type
+  DynFileStream* = ref object of DynStream
+    file*: File
+
+method recvData*(s: DynFileStream; buffer: pointer; len: int): int =
+  let n = s.file.readBuffer(buffer, len)
+  if n == 0:
+    if unlikely(s.isend):
+      raise newException(EOFError, "eof")
+    s.isend = true
+  return n
+
+method sendData*(s: DynFileStream; buffer: pointer; len: int): int =
+  return s.file.writeBuffer(buffer, len)
+
+method seek*(s: DynFileStream; off: int) =
+  s.file.setFilePos(int64(off))
+
+method sclose*(s: DynFileStream) =
+  s.file.close()
+
+method sflush*(s: DynFileStream) =
+  s.file.flushFile()
+
+proc newDynFileStream*(file: File): DynFileStream =
+  return DynFileStream(file: file, blocking: true)
+
+proc newDynFileStream*(path: string): DynFileStream =
+  var file: File
+  if file.open(path):
+    return newDynFileStream(path)
+  return nil
diff --git a/src/io/filestream.nim b/src/io/filestream.nim
deleted file mode 100644
index b1b3a296..00000000
--- a/src/io/filestream.nim
+++ /dev/null
@@ -1,34 +0,0 @@
-import io/dynstream
-
-type
-  DynFileStream* = ref object of DynStream
-    file*: File
-
-method recvData*(s: DynFileStream; buffer: pointer; len: int): int =
-  let n = s.file.readBuffer(buffer, len)
-  if n == 0:
-    if unlikely(s.isend):
-      raise newException(EOFError, "eof")
-    s.isend = true
-  return n
-
-method sendData*(s: DynFileStream; buffer: pointer; len: int): int =
-  return s.file.writeBuffer(buffer, len)
-
-method seek*(s: DynFileStream; off: int) =
-  s.file.setFilePos(int64(off))
-
-method sclose*(s: DynFileStream) =
-  s.file.close()
-
-method sflush*(s: DynFileStream) =
-  s.file.flushFile()
-
-proc newDynFileStream*(file: File): DynFileStream =
-  return DynFileStream(file: file, blocking: true)
-
-proc newDynFileStream*(path: string): DynFileStream =
-  var file: File
-  if file.open(path):
-    return newDynFileStream(path)
-  return nil
diff --git a/src/io/posixstream.nim b/src/io/posixstream.nim
deleted file mode 100644
index dd2101fa..00000000
--- a/src/io/posixstream.nim
+++ /dev/null
@@ -1,77 +0,0 @@
-import std/posix
-
-import io/dynstream
-
-type
-  PosixStream* = ref object of DynStream
-    fd*: cint
-
-  ErrorAgain* = object of IOError
-  ErrorBadFD* = object of IOError
-  ErrorFault* = object of IOError
-  ErrorInterrupted* = object of IOError
-  ErrorInvalid* = object of IOError
-  ErrorConnectionReset* = object of IOError
-  ErrorBrokenPipe* = object of IOError
-
-proc raisePosixIOError*() =
-  # In the nim stdlib, these are only constants on linux amd64, so we
-  # can't use a switch.
-  if errno == EAGAIN or errno == EWOULDBLOCK:
-    raise newException(ErrorAgain, "eagain")
-  elif errno == EBADF:
-    raise newException(ErrorBadFD, "bad fd")
-  elif errno == EFAULT:
-    raise newException(ErrorFault, "fault")
-  elif errno == EINVAL:
-    raise newException(ErrorInvalid, "invalid")
-  elif errno == ECONNRESET:
-    raise newException(ErrorConnectionReset, "connection reset by peer")
-  elif errno == EPIPE:
-    raise newException(ErrorBrokenPipe, "broken pipe")
-  else:
-    raise newException(IOError, $strerror(errno))
-
-method recvData*(s: PosixStream; buffer: pointer; len: int): int =
-  let n = read(s.fd, buffer, len)
-  if n < 0:
-    raisePosixIOError()
-  if n == 0:
-    if unlikely(s.isend):
-      raise newException(EOFError, "eof")
-    s.isend = true
-  return n
-
-proc sreadChar*(s: PosixStream): char =
-  let n = read(s.fd, addr result, 1)
-  assert n == 1
-
-method sendData*(s: PosixStream; buffer: pointer; len: int): int =
-  let n = write(s.fd, buffer, len)
-  if n < 0:
-    raisePosixIOError()
-  return n
-
-method setBlocking*(s: PosixStream; blocking: bool) {.base.} =
-  s.blocking = blocking
-  let ofl = fcntl(s.fd, F_GETFL, 0)
-  if blocking:
-    discard fcntl(s.fd, F_SETFL, ofl and not O_NONBLOCK)
-  else:
-    discard fcntl(s.fd, F_SETFL, ofl or O_NONBLOCK)
-
-method seek*(s: PosixStream; off: int) =
-  if lseek(s.fd, Off(off), SEEK_SET) == -1:
-    raisePosixIOError()
-
-method sclose*(s: PosixStream) =
-  discard close(s.fd)
-
-proc newPosixStream*(fd: FileHandle): PosixStream =
-  return PosixStream(fd: fd, blocking: true)
-
-proc newPosixStream*(path: string; flags, mode: cint): PosixStream =
-  let fd = open(cstring(path), flags, mode)
-  if fd == -1:
-    return nil
-  return newPosixStream(fd)
diff --git a/src/io/socketstream.nim b/src/io/socketstream.nim
deleted file mode 100644
index 5744ad32..00000000
--- a/src/io/socketstream.nim
+++ /dev/null
@@ -1,111 +0,0 @@
-import std/nativesockets
-import std/net
-import std/os
-
-import io/dynstream
-import io/posixstream
-import io/serversocket
-
-type SocketStream* = ref object of PosixStream
-  source*: Socket
-
-method recvData*(s: SocketStream; buffer: pointer; len: int): int =
-  let n = s.source.recv(buffer, len)
-  if n < 0:
-    raisePosixIOError()
-  if n == 0:
-    if unlikely(s.isend):
-      raise newException(EOFError, "eof")
-    s.isend = true
-  return n
-
-method sendData*(s: SocketStream; buffer: pointer; len: int): int =
-  let n = s.source.send(buffer, len)
-  if n < 0:
-    raisePosixIOError()
-  return n
-
-{.compile: "sendfd.c".}
-proc sendfd(sock, fd: cint): int {.importc.}
-
-proc sendFileHandle*(s: SocketStream; fd: FileHandle) =
-  assert not s.source.hasDataBuffered
-  let n = sendfd(s.fd, cint(fd))
-  if n < 0:
-    raisePosixIOError()
-  assert n == 1 # we send a single nul byte as buf
-
-{.compile: "recvfd.c".}
-proc recvfd(sock: cint; fdout: ptr cint): int {.importc.}
-
-proc recvFileHandle*(s: SocketStream): FileHandle =
-  assert not s.source.hasDataBuffered
-  var fd: cint
-  let n = recvfd(s.fd, addr fd)
-  if n < 0:
-    raisePosixIOError()
-  return FileHandle(fd)
-
-method setBlocking*(s: SocketStream; blocking: bool) =
-  s.blocking = blocking
-  s.source.getFd().setBlocking(blocking)
-
-method seek*(s: SocketStream; off: int) =
-  doAssert false
-
-method sclose*(s: SocketStream) =
-  s.source.close()
-
-# see serversocket.nim for an explanation
-{.compile: "connect_unix.c".}
-proc connect_unix_from_c(fd: cint; path: cstring; pathlen: cint): cint
-  {.importc.}
-when defined(freebsd):
-  # for FreeBSD/capsicum
-  proc connectat_unix_from_c(baseFd, sockFd: cint; rel_path: cstring;
-    rel_pathlen: cint): cint {.importc.}
-
-proc connectAtSocketStream0(socketDir: string; baseFd, pid: int;
-    blocking = true): SocketStream =
-  let sock = newSocket(Domain.AF_UNIX, SockType.SOCK_STREAM,
-    Protocol.IPPROTO_IP, buffered = false)
-  if not blocking:
-    sock.getFd().setBlocking(false)
-  let path = getSocketPath(socketDir, pid)
-  if baseFd == -1:
-    if connect_unix_from_c(cint(sock.getFd()), cstring(path),
-        cint(path.len)) != 0:
-      raiseOSError(osLastError())
-  else:
-    when defined(freebsd):
-      doAssert baseFd != -1
-      let name = getSocketName(pid)
-      if connectat_unix_from_c(cint(baseFd), cint(sock.getFd()), cstring(name),
-          cint(name.len)) != 0:
-        raiseOSError(osLastError())
-    else:
-      # shouldn't have sockDirFd on other architectures
-      doAssert false
-  return SocketStream(
-    source: sock,
-    fd: cint(sock.getFd()),
-    blocking: blocking
-  )
-
-proc connectSocketStream*(socketDir: string; baseFd, pid: int;
-    blocking = true): SocketStream =
-  try:
-    return connectAtSocketStream0(socketDir, baseFd, pid, blocking)
-  except OSError:
-    return nil
-
-proc acceptSocketStream*(ssock: ServerSocket; blocking = true): SocketStream =
-  var sock: Socket
-  ssock.sock.accept(sock, inheritable = true)
-  if not blocking:
-    sock.getFd().setBlocking(false)
-  return SocketStream(
-    blocking: blocking,
-    source: sock,
-    fd: cint(sock.getFd())
-  )
diff --git a/src/loader/cgi.nim b/src/loader/cgi.nim
index ee3d3160..e5fa33c4 100644
--- a/src/loader/cgi.nim
+++ b/src/loader/cgi.nim
@@ -4,7 +4,6 @@ import std/posix
 import std/strutils
 
 import io/dynstream
-import io/posixstream
 import io/stdio
 import loader/connecterror
 import loader/headers
diff --git a/src/loader/loader.nim b/src/loader/loader.nim
index 4121d351..fec07d99 100644
--- a/src/loader/loader.nim
+++ b/src/loader/loader.nim
@@ -33,10 +33,8 @@ import std/tables
 import io/bufreader
 import io/bufwriter
 import io/dynstream
-import io/posixstream
 import io/promise
 import io/serversocket
-import io/socketstream
 import io/tempfile
 import io/urlfilter
 import loader/cgi
diff --git a/src/loader/loaderhandle.nim b/src/loader/loaderhandle.nim
index b1b04dee..aa3a32d4 100644
--- a/src/loader/loaderhandle.nim
+++ b/src/loader/loaderhandle.nim
@@ -4,7 +4,6 @@ import std/tables
 
 import io/bufwriter
 import io/dynstream
-import io/posixstream
 import loader/headers
 
 when defined(debug):
diff --git a/src/loader/response.nim b/src/loader/response.nim
index bbf41741..e97e931b 100644
--- a/src/loader/response.nim
+++ b/src/loader/response.nim
@@ -4,9 +4,8 @@ import std/tables
 import chagashi/charset
 import chagashi/decoder
 import img/bitmap
-import io/posixstream
+import io/dynstream
 import io/promise
-import io/socketstream
 import loader/headers
 import loader/request
 import monoucha/javascript
diff --git a/src/local/client.nim b/src/local/client.nim
index eae079d9..b547f810 100644
--- a/src/local/client.nim
+++ b/src/local/client.nim
@@ -17,14 +17,10 @@ import html/dom
 import html/env
 import html/formdata
 import html/xmlhttprequest
-import io/bufstream
 import io/bufwriter
 import io/dynstream
-import io/filestream
-import io/posixstream
 import io/promise
 import io/serversocket
-import io/socketstream
 import js/console
 import js/domexception
 import js/encoding
diff --git a/src/local/container.nim b/src/local/container.nim
index 62bda3f2..8a057885 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -9,11 +9,9 @@ import chagashi/charset
 import config/config
 import config/mimetypes
 import img/bitmap
-import io/bufstream
 import io/dynstream
 import io/promise
 import io/serversocket
-import io/socketstream
 import layout/renderdocument
 import loader/headers
 import loader/loader
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 50a07ce8..44237da8 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -16,9 +16,7 @@ import config/mailcap
 import img/bitmap
 import io/bufreader
 import io/dynstream
-import io/posixstream
 import io/promise
-import io/socketstream
 import io/stdio
 import io/tempfile
 import io/urlfilter
diff --git a/src/local/term.nim b/src/local/term.nim
index 758f0fe3..71ff9e25 100644
--- a/src/local/term.nim
+++ b/src/local/term.nim
@@ -12,7 +12,7 @@ import chagashi/decoder
 import chagashi/encoder
 import config/config
 import img/bitmap
-import io/posixstream
+import io/dynstream
 import js/base64
 import types/blob
 import types/cell
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 6da64c83..a1e273cc 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -28,14 +28,10 @@ import html/env
 import html/event
 import html/formdata as formdata_impl
 import io/bufreader
-import io/bufstream
 import io/bufwriter
 import io/dynstream
-import io/filestream
-import io/posixstream
 import io/promise
 import io/serversocket
-import io/socketstream
 import js/console
 import js/timeout
 import layout/renderdocument
diff --git a/src/server/forkserver.nim b/src/server/forkserver.nim
index 4037c81d..b34c97b6 100644
--- a/src/server/forkserver.nim
+++ b/src/server/forkserver.nim
@@ -10,9 +10,7 @@ import html/formdata
 import io/bufreader
 import io/bufwriter
 import io/dynstream
-import io/posixstream
 import io/serversocket
-import io/socketstream
 import io/stdio
 import loader/loader
 import server/buffer
diff --git a/src/types/formdata.nim b/src/types/formdata.nim
index 27af9a5b..9ce881f0 100644
--- a/src/types/formdata.nim
+++ b/src/types/formdata.nim
@@ -1,7 +1,6 @@
 import std/strutils
 
 import io/dynstream
-import io/posixstream
 import monoucha/javascript
 import types/blob
 import utils/twtstr