mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 14:34:40 +00:00

Remembers net.Socket options called before connect and retroactively applies them after the handle has been created. This change makes the following function calls more user-friendly: - setKeepAlive() - setNoDelay() - ref() - unref() Related: https://github.com/joyent/node/issues/7077 and https://github.com/joyent/node/issues/8572 Fixes: https://github.com/joyent/node/issues/7077 Fixes: https://github.com/joyent/node/issues/8572 PR-URL: https://github.com/nodejs/io.js/pull/1518 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Roman Reiss <me@silverwind.io>
34 lines
776 B
JavaScript
34 lines
776 B
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
var net = require('net');
|
|
var TCPWrap = process.binding('tcp_wrap').TCP;
|
|
|
|
var echoServer = net.createServer(function(connection) {
|
|
connection.end();
|
|
});
|
|
echoServer.listen(common.PORT);
|
|
|
|
var callCount = 0;
|
|
|
|
var Socket = net.Socket;
|
|
var setNoDelay = TCPWrap.prototype.setNoDelay;
|
|
|
|
TCPWrap.prototype.setNoDelay = function(enable) {
|
|
setNoDelay.call(this, enable);
|
|
callCount++;
|
|
};
|
|
|
|
echoServer.on('listening', function() {
|
|
var sock1 = new Socket();
|
|
// setNoDelay before the handle is created
|
|
// there is probably a better way to test this
|
|
|
|
sock1.setNoDelay();
|
|
sock1.connect(common.PORT);
|
|
sock1.on('end', function() {
|
|
assert.equal(callCount, 1);
|
|
echoServer.close();
|
|
});
|
|
});
|