2011-07-25 09:01:44 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var net = require('net');
|
|
|
|
|
2012-05-29 13:05:49 +02:00
|
|
|
var events = [];
|
|
|
|
var sockets = [];
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(server.connections, 0);
|
2013-03-06 16:15:17 +01:00
|
|
|
assert.equal(events.length, 3);
|
|
|
|
// Expect to see one server event and two client events. The order of the
|
|
|
|
// events is undefined because they arrive on the same event loop tick.
|
|
|
|
assert.equal(events.join(' ').match(/server/g).length, 1);
|
|
|
|
assert.equal(events.join(' ').match(/client/g).length, 2);
|
2012-05-29 13:05:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
var server = net.createServer(function(c) {
|
|
|
|
c.on('close', function() {
|
|
|
|
events.push('client');
|
2011-07-25 09:01:44 +02:00
|
|
|
});
|
2012-05-29 13:05:49 +02:00
|
|
|
|
|
|
|
sockets.push(c);
|
|
|
|
|
|
|
|
if (sockets.length === 2) {
|
|
|
|
server.close();
|
|
|
|
sockets.forEach(function(c) { c.destroy() });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
server.on('close', function() {
|
|
|
|
events.push('server');
|
2011-07-25 09:01:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
server.listen(common.PORT, function() {
|
|
|
|
net.createConnection(common.PORT);
|
2012-05-29 13:05:49 +02:00
|
|
|
net.createConnection(common.PORT);
|
|
|
|
});
|