Skip to content

Commit 0fec213

Browse files
committed
Update docs for server fd sharing
1 parent 025f5c8 commit 0fec213

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

doc/api/child_processes.markdown

+20-4
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ leaner than `child_process.exec`. It has the same options.
190190
This is a special case of the `spawn()` functionality for spawning Node
191191
processes. In addition to having all the methods in a normal ChildProcess
192192
instance, the returned object has a communication channel built-in. The
193-
channel is written to with `child.send(message, [sendStream])` and messages
193+
channel is written to with `child.send(message, [sendHandle])` and messages
194194
are recieved by a `'message'` event on the child.
195195

196196
For example:
@@ -224,9 +224,25 @@ These child Nodes are still whole new instances of V8. Assume at least 30ms
224224
startup and 10mb memory for each new Node. That is, you cannot create many
225225
thousands of them.
226226

227-
The `sendStream` option to `child.send()` is for sending a `net.Socket`
228-
or `net.Server` object to another process. Child will receive the handle as
229-
as second argument to the `message` event.
227+
The `sendHandle` option to `child.send()` is for sending a handle object to
228+
another process. Child will receive the handle as as second argument to the
229+
`message` event. Here is an example of sending a handle:
230+
231+
var server = require('net').createServer();
232+
var child = require('child_process').fork(__dirname + '/child.js');
233+
// Open up the server object and send the handle.
234+
child.send({ server: true }, server._handle);
235+
236+
Here is an example of receiving the server handle and sharing it between
237+
processes:
238+
239+
process.on('message', function(m, serverHandle) {
240+
if (serverHandle) {
241+
var server = require('child_process').createServer();
242+
server.listen(serverHandle);
243+
}
244+
});
245+
230246

231247

232248
### child.kill(signal='SIGTERM')

doc/api/net.markdown

+3-13
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ This function is asynchronous. The last parameter `listeningListener` will be
135135
called when the server has been bound.
136136
See also ['listening'](#event_listening_) event.
137137

138-
#### server.listenFD(fd)
139-
140-
Start a server listening for connections on the given file descriptor.
141-
142-
This file descriptor must have already had the `bind(2)` and `listen(2)` system
143-
calls invoked on it. Additionally, it must be set non-blocking; try
144-
`fcntl(fd, F_SETFL, O_NONBLOCK)`.
145-
146138
#### server.pause(msecs)
147139

148140
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.
300292
The optional `callback` parameter will be executed when the data is finally
301293
written out - this may not be immediately.
302294

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

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

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

doc/api/streams.markdown

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

40-
### Event: 'fd'
41-
42-
`function (fd) { }`
43-
44-
Emitted when a file descriptor is received on the stream. Only UNIX streams
45-
support this functionality; all others will simply never emit this event.
46-
4740
### stream.readable
4841

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

0 commit comments

Comments
 (0)