0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-net-persistent-ref-unref.js
Evan Lucas 85d9983009 net: persist net.Socket options before connect
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>
2015-05-19 13:21:44 -05:00

40 lines
782 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(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();
});
});