Update docs for server fd sharing

This commit is contained in:
Ryan Dahl
2011-10-10 11:31:40 -07:00
parent 025f5c89c7
commit 0fec213656
3 changed files with 23 additions and 24 deletions

View File

@@ -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();
server.listen(serverHandle);
}
});
### child.kill(signal='SIGTERM')

View File

@@ -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])

View File

@@ -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'`