mirror of https://github.com/lukechilds/node.git
Browse Source
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>v2.3.1-release
Evan Lucas
10 years ago
4 changed files with 130 additions and 6 deletions
@ -0,0 +1,33 @@ |
|||
'use strict'; |
|||
var common = require('../common'); |
|||
var assert = require('assert'); |
|||
var net = require('net'); |
|||
|
|||
var serverConnection; |
|||
var echoServer = net.createServer(function(connection) { |
|||
serverConnection = connection; |
|||
connection.setTimeout(0); |
|||
assert.equal(typeof connection.setKeepAlive, 'function'); |
|||
connection.on('end', function() { |
|||
connection.end(); |
|||
}); |
|||
}); |
|||
echoServer.listen(common.PORT); |
|||
|
|||
echoServer.on('listening', function() { |
|||
var clientConnection = new net.Socket(); |
|||
// send a keepalive packet after 1000 ms
|
|||
// and make sure it persists
|
|||
clientConnection.setKeepAlive(true, 400); |
|||
clientConnection.connect(common.PORT); |
|||
clientConnection.setTimeout(0); |
|||
|
|||
setTimeout(function() { |
|||
// make sure both connections are still open
|
|||
assert.equal(serverConnection.readyState, 'open'); |
|||
assert.equal(clientConnection.readyState, 'open'); |
|||
serverConnection.end(); |
|||
clientConnection.end(); |
|||
echoServer.close(); |
|||
}, 600); |
|||
}); |
@ -0,0 +1,33 @@ |
|||
'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(); |
|||
}); |
|||
}); |
@ -0,0 +1,39 @@ |
|||
'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(conn) { |
|||
conn.end(); |
|||
}); |
|||
|
|||
var ref = TCPWrap.prototype.ref; |
|||
var unref = TCPWrap.prototype.unref; |
|||
|
|||
var refCount = 0; |
|||
|
|||
TCPWrap.prototype.ref = function() { |
|||
ref.call(this); |
|||
refCount++; |
|||
assert.equal(refCount, 0); |
|||
}; |
|||
|
|||
TCPWrap.prototype.unref = function() { |
|||
unref.call(this); |
|||
refCount--; |
|||
assert.equal(refCount, -1); |
|||
}; |
|||
|
|||
echoServer.listen(common.PORT); |
|||
|
|||
echoServer.on('listening', function() { |
|||
var sock = new net.Socket(); |
|||
sock.unref(); |
|||
sock.ref(); |
|||
sock.connect(common.PORT); |
|||
sock.on('end', function() { |
|||
assert.equal(refCount, 0); |
|||
echoServer.close(); |
|||
}); |
|||
}); |
Loading…
Reference in new issue