Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Update docs for server fd sharing

  • Loading branch information...
ry committed Oct 10, 2011
1 parent 025f5c8 commit 0fec21365612621cedaabeec6300d97e49c601c0
Showing with 23 additions and 24 deletions.
  1. +20 −4 doc/api/child_processes.markdown
  2. +3 −13 doc/api/net.markdown
  3. +0 −7 doc/api/streams.markdown
@@ -190,7 +190,7 @@ leaner than `child_process.exec`. It has the same options.
This is a special case of the `spawn()` functionality for spawning Node
processes. In addition to having all the methods in a normal ChildProcess
instance, the returned object has a communication channel built-in. The
channel is written to with `child.send(message, [sendStream])` and messages
channel is written to with `child.send(message, [sendHandle])` and messages
are recieved by a `'message'` event on the child.
For example:
@@ -224,9 +224,25 @@ These child Nodes are still whole new instances of V8. Assume at least 30ms
startup and 10mb memory for each new Node. That is, you cannot create many
thousands of them.
The `sendStream` option to `child.send()` is for sending a `net.Socket`
or `net.Server` object to another process. Child will receive the handle as
as second argument to the `message` event.
The `sendHandle` option to `child.send()` is for sending a handle object to
another process. Child will receive the handle as as second argument to the
`message` event. Here is an example of sending a handle:
var server = require('net').createServer();
var child = require('child_process').fork(__dirname + '/child.js');
// Open up the server object and send the handle.
child.send({ server: true }, server._handle);
Here is an example of receiving the server handle and sharing it between
processes:
process.on('message', function(m, serverHandle) {
if (serverHandle) {
var server = require('child_process').createServer();

This comment has been minimized.

Copy link
@stolsma

stolsma Oct 11, 2011

Looks like the require is not correct ??? I think it must be require('net') or am I wrong ??

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Oct 11, 2011

Member

Thanks, good catch. Fixed in 49c3a91.

server.listen(serverHandle);
}
});
### child.kill(signal='SIGTERM')
@@ -135,14 +135,6 @@ This function is asynchronous. The last parameter `listeningListener` will be
called when the server has been bound.
See also ['listening'](#event_listening_) event.

#### server.listenFD(fd)

Start a server listening for connections on the given file descriptor.

This file descriptor must have already had the `bind(2)` and `listen(2)` system
calls invoked on it. Additionally, it must be set non-blocking; try
`fcntl(fd, F_SETFL, O_NONBLOCK)`.

#### server.pause(msecs)

Stop accepting connections for the given number of milliseconds (default is
@@ -300,12 +292,10 @@ buffer. Returns `false` if all or part of the data was queued in user memory.
The optional `callback` parameter will be executed when the data is finally
written out - this may not be immediately.

#### socket.write(data, [encoding], [fileDescriptor], [callback])

For UNIX sockets, it is possible to send a file descriptor through the
socket. Simply add the `fileDescriptor` argument and listen for the `'fd'`
event on the other end.
#### socket.write(data, [encoding], [callback])

Write data with the optional encoding. The callback will be made when the
data is flushed to the kernel.

#### socket.end([data], [encoding])

@@ -37,13 +37,6 @@ Emitted when the underlying file descriptor has been closed. Not all streams
will emit this. (For example, an incoming HTTP request will not emit
`'close'`.)

### Event: 'fd'

`function (fd) { }`

Emitted when a file descriptor is received on the stream. Only UNIX streams
support this functionality; all others will simply never emit this event.

### stream.readable

A boolean that is `true` by default, but turns `false` after an `'error'`

0 comments on commit 0fec213

Please sign in to comment.
You can’t perform that action at this time.