4

I'm porting an existing program to nodejs. In this program, I open a file descriptor and then hand it off to a thread which calls poll on it in order to determine when it's readable.

Instead of writing a custom C++ module, I'd really like to do this in pure javascript making use of Node's handy dandy Duplex stream.

For example I'd like to do something like this:

var device = new PollDuplexStream(fileDescriptor);

device.on('data', function(data) {
    // data handling logic here
});

...

var chunk = new Buffer(...);
device.write(chunk);

It seems like this should exist, but I'm not seeing where it does. Perhaps I'm just blind? What's the real world equivalent of PollDuplexStream from the example above?

Please note that I'm explicitly looking for a solution which starts with a file descriptor rather than a path, otherwise I'd just create my own from fs.createReadStream and fs.createWriteStream.

Also I don't care that it calls poll internally - in fact, I'd prefer that it use libuv's uv_poll_* internally.

Ben Burns
  • 14,978
  • 4
  • 35
  • 56

1 Answers1

0

You'll need to create a binary addon which uses a uv_poll_t handle, which is able to poll for readability / writability for arbitrary file descriptors.

saghul
  • 1,990
  • 1
  • 13
  • 15