net: add createPipe() and createSocketPair() - #65094
Conversation
|
I dont think we should create a new module |
|
+1, there's no justification for a new top-level module. |
83d8402 to
db5d657
Compare
|
Yep. I'll move it to net. |
|
I also pushed a small stacked follow-up branch that explores the adjacent kingces95/node@create-pipe...create-socket-pair My immediate use case is The idea is that The follow-up has child-process support for fd |
|
I folded the socket-pair follow-up into the main change. The updated version keeps both APIs in
This should make the PR easier to review as one coherent “parent-owned OS endpoints” feature. The removed sketch is preserved here as a userland workbook/example of the style of shell-like stream composition this API is meant to enable: https://gist.github.com/kingces95/1e024a1e987ef3956c7ae3513e468c64 |
3621fab to
3c6c2d0
Compare
Signed-off-by: Chris King <kingces95@gmail.com>
|
I landed on a single coherent
So the PR is no longer “just create pipe.” It is a parent-owned OS endpoint proposal: pipes for directional stdio leasing, socket pairs for duplex cross-process communication. |
Adds a
node:pipemodule withcreatePipe(), returning a readableand writable endpoint owned by the parent process.
The endpoints may be passed to
child_process.spawn()stdio. This letsthe parent lend a pipe endpoint to a child without turning the parent
stream itself into child-owned stdio. The parent can then reclaim unread
bytes or lend the same endpoint to a later child.
This is useful for bash-like partial consumption of long-lived streams.
For example, a parent can keep ownership of a Server Sent Event stream
while delegating bounded reads to external tools, then continue parsing
from the exact byte where the child stopped.
The central integration test (test-child-process-leased-pipe.js) writes
abc,lets child A read
a, lets child B readb, and then verifies that the parentcan still read
c.Endpoints created by
pipe.createPipe()are rejected byspawnSync(), andan endpoint may only be leased to one child process at a time.
Tests cover
node:pipecreation, documentation examples, child stdioleasing, sequential lease-and-reclaim behavior, lease error cleanup,
spawnSync()rejection, and platform-consistent writablefinishbehavior.