Skip to content

Commit 94cd83e

Browse files
pgriessry
authored andcommitted
Doc fixes for FD related features, upgrade.
- Add docs for 'fd' events, Server.listenFD(), Stream.write(...[, fd]) and http.Client 'upgrade' event.
1 parent 82ce348 commit 94cd83e

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

doc/api.markdown

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@ Emitted when the underlying file descriptor has be closed. Not all streams
312312
will emit this. (For example, an incoming HTTP request will not emit
313313
`'close'`.)
314314

315+
### Event: 'fd'
316+
317+
`function (fd) { }`
318+
319+
Emitted when a file descriptor is received on the stream. Only UNIX streams
320+
support this functionality; all others will simply never emit this event.
321+
315322
### stream.setEncoding(encoding)
316323
Makes the data event emit a string instead of a `Buffer`. `encoding` can be
317324
`'utf8'`, `'ascii'`, or `'binary'`.
@@ -353,14 +360,19 @@ Emitted on error with the exception `exception`.
353360

354361
Emitted when the underlying file descriptor has been closed.
355362

356-
### stream.write(string, encoding)
363+
### stream.write(string, encoding, [fd])
357364

358365
Writes `string` with the given `encoding` to the stream. Returns `true` if
359366
the string has been flushed to the kernel buffer. Returns `false` to
360367
indicate that the kernel buffer is full, and the data will be sent out in
361368
the future. The `'drain'` event will indicate when the kernel buffer is
362369
empty again. The `encoding` defaults to `'utf8'`.
363370

371+
If the optional `fd` parameter is specified, it is interpreted as an integral
372+
file descriptor to be sent over the stream. This is only supported for UNIX
373+
streams, and is silently ignored otherwise. When writing a file descriptor in
374+
this manner, closing the descriptor before the stream drains risks sending an
375+
invalid (closed) FD.
364376

365377
### stream.write(buffer)
366378

@@ -1844,6 +1856,16 @@ Example of connecting to `google.com`:
18441856
});
18451857

18461858

1859+
### Event: 'upgrade'
1860+
1861+
`function (request, socket, head)`
1862+
1863+
Emitted each time a server responds to a request with an upgrade. If this event
1864+
isn't being listened for, clients receiving an upgrade header will have their
1865+
connections closed.
1866+
1867+
See the description of the `upgrade` event for `http.Server` for further details.
1868+
18471869
### http.createClient(port, host, secure, credentials)
18481870

18491871
Constructs a new HTTP client. `port` and
@@ -2081,6 +2103,12 @@ This function is asynchronous. The last parameter `callback` will be called
20812103
when the server has been bound.
20822104

20832105

2106+
### server.listenFD(fd)
2107+
2108+
Start a server listening for connections on the given file descriptor.
2109+
2110+
This file descriptor must have already had the `bind(2)` and `listen(2)` system
2111+
calls invoked on it.
20842112

20852113
### server.close()
20862114

lib/net.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ function setImplmentationMethods (self) {
318318
// by the kernel for some reason. Otherwise, we'd just
319319
// fast-path return here.
320320

321-
return write(self.fd, buf, off, len, fd, flags);
321+
// Drop 'fd' and 'flags' as these are not supported by the write(2)
322+
// system call
323+
return write(self.fd, buf, off, len);
322324
};
323325

324326
self._readImpl = function(buf, off, len, calledByIOWatcher) {
@@ -652,8 +654,6 @@ Object.defineProperty(Stream.prototype, 'readyState', {
652654
// Returns true if all the data was flushed to socket. Returns false if
653655
// something was queued. If data was queued, then the "drain" event will
654656
// signal when it has been finally flushed to socket.
655-
//
656-
// XXX: Caller cannot close the given fd until the stream has drained.
657657
Stream.prototype.write = function (data, encoding, fd) {
658658
if (this._writeQueue && this._writeQueue.length) {
659659
// Slow. There is already a write queue, so let's append to it.

0 commit comments

Comments
 (0)