aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-27 02:32:22 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-27 02:32:22 +0200
commit285b6f32c28d1cda403ba33bfb2d22c34fab2a1e (patch)
tree0ec51fbd1afbf142503f960e7634404f2e467617
parent2d414c2b77acb8c276812d78ff814ccadc33691f (diff)
downloadchawan-285b6f32c28d1cda403ba33bfb2d22c34fab2a1e.tar.gz
interface clone: remove unused arg, document
-rw-r--r--src/local/container.nim2
-rw-r--r--src/server/buffer.nim13
2 files changed, 10 insertions, 5 deletions
diff --git a/src/local/container.nim b/src/local/container.nim
index 465d7b87..fb48e89e 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -1001,7 +1001,7 @@ proc setStream*(container: Container, stream: Stream) =
stream.flush()
container.load()
else:
- container.iface = container.iface.clone(stream)
+ container.iface = cloneInterface(stream)
# Maybe we have to resume loading. Let's try.
discard container.iface.load().then(proc(res: LoadResult) =
container.onload(res))
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index d6c00ef9..3be0fdcf 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -141,14 +141,19 @@ proc newBufferInterface*(stream: Stream): BufferInterface =
stream: stream
)
-proc clone*(iface: BufferInterface, stream: Stream): BufferInterface =
- let iface2 = newBufferInterface(stream)
+# After cloning a buffer, we need a new interface to the new buffer process.
+# Here we create a new interface for that clone.
+proc cloneInterface*(stream: Stream): BufferInterface =
+ let iface = newBufferInterface(stream)
+ # We have just fork'ed the buffer process inside an interface function,
+ # from which the new buffer is going to return as well. So we must also
+ # consume the return value of the clone function, which is the pid 0.
var len: int
var pid: Pid
stream.sread(len)
- stream.sread(iface2.packetid)
+ stream.sread(iface.packetid)
stream.sread(pid)
- return iface2
+ return iface
proc resolve*(iface: BufferInterface, packetid, len: int) =
iface.opaque.len = len