-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Send binary data via ChildProcess.send #5727
Comments
Same thing with dates... I'm not sure it's a bug because send() indeed uses JSON internally, and JSON has no easy way to represent buffers. |
As pointed out by @rlidwka, the control channel speaks JSON. You can only send over things that have a valid JSON representation, something Buffer and Date objects don't really have.
You can open an additional pipe when spawning the child process: var args = [ /* ... */ ];
var options = { stdio: ['pipe','pipe','pipe','pipe'] }; // first three are stdin/out/err
var proc = child_process.spawn(cmd, args, options);
var pipe = proc.stdio[3];
pipe.write(Buffer('hello')); The child can open the pipe like this: var pipe = new net.Socket({ fd: 3 });
pipe.on('data', function(buf) {
// do whatever
}); |
Thanks bnoordhuis, please consider my pull request that exports some of the configurability of
I wasn't sure how to handle the |
test/parallel/test-regress-GH-5727 assumed that one of the servers would be listening on IPv6. This breaks when the machine running the test doesn't have IPv6. This commit builds the connection key that is compared dynamically. Refs: nodejs/node#5732 PR-URL: nodejs/node#6319 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
test/parallel/test-regress-GH-5727 assumed that one of the servers would be listening on IPv6. This breaks when the machine running the test doesn't have IPv6. This commit builds the connection key that is compared dynamically. Refs: nodejs/node#5732 PR-URL: nodejs/node#6319 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
I don't suppose there's been any improvement to this. I would have loved to see the PR for fork options make it, because I cannot seem to figure out a good way of opening this additional IPC channel without having to basically re-implement everything the cluster module is doing for me. Is there a way to set up the IPC channel after the worker has been forked? |
So is there a way to pass binary data (e.g typed arrays) to forked (not spawned) child process through The use case i have, is an image processing lib (for node, browser and web workers) and i have everything working perfect in all platforms except parallel processing in node (through forked child processes), since typed arrays (i.e image data) are serialised as objects, not even arrays. |
This commit allows child_process.fork() to pass stdio options to spawn(). This allows fork() to more easily take advantage of additional stdio channels. Refs: nodejs/node-v0.x-archive#5727 PR-URL: #7811 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit allows setupMaster() to configure the stdio channels for worker processes. Refs: nodejs/node-v0.x-archive#5727 Refs: nodejs#7811 PR-URL: nodejs#7838 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit allows child_process.fork() to pass stdio options to spawn(). This allows fork() to more easily take advantage of additional stdio channels. Refs: nodejs/node-v0.x-archive#5727 PR-URL: #7811 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit allows setupMaster() to configure the stdio channels for worker processes. Refs: nodejs/node-v0.x-archive#5727 Refs: #7811 PR-URL: #7838 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Removed common.PORT from test-regress-nodejsGH-5051 and test-regress-nodejsGH-5727 in order to eliminate the possibility of port collision. Refs: nodejs/node#12376 PR-URL: nodejs/node#12639 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Is there a way to send binary data efficiently to a child process using (something as easy to use as)
ChildProcess.send
?send(buf)
does not work as expected:The above will log
msg
turns out to be a JSONified version of the original buffer.The text was updated successfully, but these errors were encountered: