Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Merge nodejs/master
Browse files Browse the repository at this point in the history
Merge e5a4948 as of 2017-06-13.
This is an automatically created merge. For any problems please
contact @kunalspathak.
  • Loading branch information
chakrabot committed Jun 19, 2017
2 parents 4073d36 + e5a4948 commit 0078c29
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 77 deletions.
62 changes: 29 additions & 33 deletions benchmark/fixtures/simple-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ module.exports = http.createServer(function(req, res) {
dom.add(res);
}

// URL format: /<type>/<length>/<chunks>/<responseBehavior>
// URL format: /<type>/<length>/<chunks>/<responseBehavior>/chunkedEnc
var params = req.url.split('/');
var command = params[1];
var body = '';
var arg = params[2];
var n_chunks = parseInt(params[3], 10);
var resHow = (params.length >= 5 ? params[4] : 'normal');
var chunkedEnc = (params.length >= 6 && params[5] === 'false' ? false : true);
var status = 200;

var n, i;
Expand Down Expand Up @@ -95,48 +96,43 @@ module.exports = http.createServer(function(req, res) {

// example: http://localhost:port/bytes/512/4
// sends a 512 byte body in 4 chunks of 128 bytes
if (n_chunks > 0) {
switch (resHow) {
case 'setHeader':
res.statusCode = status;
res.setHeader('Content-Type', 'text/plain');
var len = body.length;
switch (resHow) {
case 'setHeader':
res.statusCode = status;
res.setHeader('Content-Type', 'text/plain');
if (chunkedEnc)
res.setHeader('Transfer-Encoding', 'chunked');
break;
case 'setHeaderWH':
res.setHeader('Content-Type', 'text/plain');
else
res.setHeader('Content-Length', len.toString());
break;
case 'setHeaderWH':
res.setHeader('Content-Type', 'text/plain');
if (chunkedEnc)
res.writeHead(status, { 'Transfer-Encoding': 'chunked' });
break;
default:
else
res.writeHead(status, { 'Content-Length': len.toString() });
break;
default:
if (chunkedEnc) {
res.writeHead(status, {
'Content-Type': 'text/plain',
'Transfer-Encoding': 'chunked'
});
}
// send body in chunks
var len = body.length;
} else {
res.writeHead(status, {
'Content-Type': 'text/plain',
'Content-Length': len.toString()
});
}
}
// send body in chunks
if (n_chunks > 1) {
var step = Math.floor(len / n_chunks) || 1;

for (i = 0, n = (n_chunks - 1); i < n; ++i) {
for (i = 0, n = (n_chunks - 1); i < n; ++i)
res.write(body.slice(i * step, i * step + step));
}
res.end(body.slice((n_chunks - 1) * step));
} else {
switch (resHow) {
case 'setHeader':
res.statusCode = status;
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Length', body.length.toString());
break;
case 'setHeaderWH':
res.setHeader('Content-Type', 'text/plain');
res.writeHead(status, { 'Content-Length': body.length.toString() });
break;
default:
res.writeHead(status, {
'Content-Type': 'text/plain',
'Content-Length': body.length.toString()
});
}
res.end(body);
}
});
6 changes: 4 additions & 2 deletions benchmark/http/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ var bench = common.createBenchmark(main, {
// unicode confuses ab on os x.
type: ['bytes', 'buffer'],
len: [4, 1024, 102400],
chunks: [0, 1, 4], // chunks=0 means 'no chunked encoding'.
chunks: [1, 4],
c: [50, 500],
chunkedEnc: ['true', 'false'],
res: ['normal', 'setHeader', 'setHeaderWH']
});

Expand All @@ -16,7 +17,8 @@ function main(conf) {
var server = require('../fixtures/simple-http-server.js')
.listen(process.env.PORT || common.PORT)
.on('listening', function() {
var path = `/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}`;
var path =
`/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}/${conf.chunkedEnc}`;

bench.http({
path: path,
Expand Down
4 changes: 2 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ parser = optparse.OptionParser()

valid_os = ('win', 'mac', 'solaris', 'freebsd', 'openbsd', 'linux',
'android', 'aix')
valid_arch = ('arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 'x32',
'x64', 'x86', 's390', 's390x')
valid_arch = ('arm', 'arm64', 'ia32', 'mips', 'mipsel', 'mips64el', 'ppc',
'ppc64', 'x32','x64', 'x86', 's390', 's390x')
valid_arm_float_abi = ('soft', 'softfp', 'hard')
valid_arm_fpu = ('vfp', 'vfpv3', 'vfpv3-d16', 'neon')
valid_mips_arch = ('loongson', 'r1', 'r2', 'r6', 'rx')
Expand Down
6 changes: 6 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,12 @@ an argument of the wrong type has been passed to a Node.js API.
The `'ERR_INVALID_CALLBACK'` error code is used generically to identify that
a callback function is required and has not been provided to a Node.js API.

<a id="ERR_INVALID_CURSOR_POS"></a>
### ERR_INVALID_CURSOR_POS

The `'ERR_INVALID_CURSOR_POS'` is thrown specifically when a cursor on a given
stream is attempted to move to a specified row without a specified column.

<a id="ERR_INVALID_FILE_URL_HOST"></a>
### ERR_INVALID_FILE_URL_HOST

Expand Down
13 changes: 6 additions & 7 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,16 @@ For more details, review the [Object Lifetime Management][].

### N-API Callback types
#### *napi_callback_info*
Opaque datatype that is passed to a callback function. It can be used for two
purposes:
- Get additional information about the context in which the callback was
invoked.
- Set the return value of the callback.
Opaque datatype that is passed to a callback function. It can be used for
getting additional information about the context in which the callback was
invoked.

#### *napi_callback*
Function pointer type for user-provided native functions which are to be
exposed to JavaScript via N-API. Callback functions should satisfy the
following signature:
```C
typedef void (*napi_callback)(napi_env, napi_callback_info);
typedef napi_value (*napi_callback)(napi_env, napi_callback_info);
```
#### *napi_finalize*
Expand Down Expand Up @@ -2516,8 +2514,9 @@ In order to expose a function as part of the
add-on's module exports, set the newly created function on the exports
object. A sample module might look as follows:
```C
void SayHello(napi_env env, napi_callback_info info) {
napi_value SayHello(napi_env env, napi_callback_info info) {
printf("Hello\n");
return nullptr;
}
void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
Expand Down
10 changes: 5 additions & 5 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,18 +660,18 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
// signal the user to keep writing.
if (chunk.length === 0) return true;

if (!fromEnd && msg.connection && !msg.connection.corked) {
msg.connection.cork();
process.nextTick(connectionCorkNT, msg.connection);
}

var len, ret;
if (msg.chunkedEncoding) {
if (typeof chunk === 'string')
len = Buffer.byteLength(chunk, encoding);
else
len = chunk.length;

if (msg.connection && !msg.connection.corked) {
msg.connection.cork();
process.nextTick(connectionCorkNT, msg.connection);
}

msg._send(len.toString(16), 'latin1', null);
msg._send(crlf_buf, null, null);
msg._send(chunk, encoding, null);
Expand Down
20 changes: 12 additions & 8 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,6 @@ function socketOnData(server, socket, parser, state, d) {
assert(!socket._paused);
debug('SERVER socketOnData %d', d.length);

if (state.keepAliveTimeoutSet) {
socket.setTimeout(0);
if (server.timeout) {
socket.setTimeout(server.timeout);
}
state.keepAliveTimeoutSet = false;
}

var ret = parser.execute(d);
onParserExecuteCommon(server, socket, parser, state, ret, d);
}
Expand All @@ -469,6 +461,8 @@ function socketOnError(e) {
}

function onParserExecuteCommon(server, socket, parser, state, ret, d) {
resetSocketTimeout(server, socket, state);

if (ret instanceof Error) {
debug('parse error', ret);
socketOnError.call(socket, ret);
Expand Down Expand Up @@ -550,6 +544,8 @@ function resOnFinish(req, res, socket, state, server) {
// new message. In this callback we setup the response object and pass it
// to the user.
function parserOnIncoming(server, socket, state, req, keepAlive) {
resetSocketTimeout(server, socket, state);

state.incoming.push(req);

// If the writable end isn't consuming, then stop reading
Expand Down Expand Up @@ -611,6 +607,14 @@ function parserOnIncoming(server, socket, state, req, keepAlive) {
return false; // Not a HEAD response. (Not even a response!)
}

function resetSocketTimeout(server, socket, state) {
if (!state.keepAliveTimeoutSet)
return;

socket.setTimeout(server.timeout || 0);
state.keepAliveTimeoutSet = false;
}

function onSocketResume() {
// It may seem that the socket is resumed, but this is an enemy's trick to
// deceive us! `resume` is emitted asynchronously, and may be called from
Expand Down
2 changes: 1 addition & 1 deletion lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
}

// NOTE: It is important to set the key after the cert.
// `ssl_set_pkey` returns `0` when the key does not much the cert, but
// `ssl_set_pkey` returns `0` when the key does not match the cert, but
// `ssl_set_cert` returns `1` and nullifies the key in the SSL structure
// which leads to the crash later on.
if (options.key) {
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range');
E('ERR_INVALID_ARG_TYPE', invalidArgType);
E('ERR_INVALID_CALLBACK', 'callback must be a function');
E('ERR_INVALID_FD', (fd) => `"fd" must be a positive integer: ${fd}`);
E('ERR_INVALID_CURSOR_POS',
'Cannot set cursor row without setting its column');
E('ERR_INVALID_FILE_URL_HOST', 'File URL host %s');
E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s');
E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent');
Expand Down
18 changes: 14 additions & 4 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

'use strict';

const errors = require('internal/errors');
const { debug, inherits } = require('util');
const Buffer = require('buffer').Buffer;
const EventEmitter = require('events');
Expand Down Expand Up @@ -95,7 +96,7 @@ function Interface(input, output, completer, terminal) {
}

if (completer && typeof completer !== 'function') {
throw new TypeError('Argument "completer" must be a function');
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'completer', completer);
}

if (historySize === undefined) {
Expand All @@ -105,7 +106,11 @@ function Interface(input, output, completer, terminal) {
if (typeof historySize !== 'number' ||
isNaN(historySize) ||
historySize < 0) {
throw new TypeError('Argument "historySize" must be a positive number');
throw new errors.RangeError(
'ERR_INVALID_OPT_VALUE',
'historySize',
historySize
);
}

// backwards compat; check the isTTY prop of the output stream
Expand Down Expand Up @@ -281,7 +286,12 @@ Interface.prototype._onLine = function(line) {

Interface.prototype._writeToOutput = function _writeToOutput(stringToWrite) {
if (typeof stringToWrite !== 'string')
throw new TypeError('"stringToWrite" argument must be a string');
throw new errors.TypeError(
'ERR_INVALID_ARG_TYPE',
'stringToWrite',
'string',
stringToWrite
);

if (this.output !== null && this.output !== undefined)
this.output.write(stringToWrite);
Expand Down Expand Up @@ -1053,7 +1063,7 @@ function cursorTo(stream, x, y) {
return;

if (typeof x !== 'number')
throw new Error('Can\'t set cursor row without also setting it\'s column');
throw new errors.Error('ERR_INVALID_CURSOR_POS');

if (typeof y !== 'number') {
stream.write(CSI`${x + 1}G`);
Expand Down
11 changes: 6 additions & 5 deletions test/parallel/test-child-process-stdio-big-write-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'use strict';
require('../common');
const assert = require('assert');
const BUFSIZE = 1024;
let bufsize = 0;

switch (process.argv[2]) {
case undefined:
Expand Down Expand Up @@ -51,14 +51,15 @@ function parent() {
// Write until the buffer fills up.
let buf;
do {
buf = Buffer.alloc(BUFSIZE, '.');
sent += BUFSIZE;
bufsize += 1024;
buf = Buffer.alloc(bufsize, '.');
sent += bufsize;
} while (child.stdin.write(buf));

// then write a bunch more times.
for (let i = 0; i < 100; i++) {
const buf = Buffer.alloc(BUFSIZE, '.');
sent += BUFSIZE;
const buf = Buffer.alloc(bufsize, '.');
sent += bufsize;
child.stdin.write(buf);
}

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-eof-on-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const http = require('http');
// It is separate from test-http-malformed-request.js because it is only
// reproduceable on the first packet on the first connection to a server.

const server = http.createServer(common.noop);
const server = http.createServer(common.mustNotCall());
server.listen(0);

server.on('listening', function() {
Expand Down
Loading

0 comments on commit 0078c29

Please sign in to comment.