mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
839 B
37 lines
839 B
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
|
|
const server = http.createServer((req, res) => res.end());
|
|
|
|
common.refreshTmpDir();
|
|
|
|
server.listen(common.PIPE, common.mustCall(() =>
|
|
asyncLoop(makeKeepAliveRequest, 10, common.mustCall(() =>
|
|
server.getConnections(common.mustCall((err, conns) => {
|
|
assert.ifError(err);
|
|
assert.strictEqual(conns, 1);
|
|
server.close();
|
|
}))
|
|
))
|
|
));
|
|
|
|
function asyncLoop(fn, times, cb) {
|
|
fn(function handler() {
|
|
if (--times) {
|
|
fn(handler);
|
|
} else {
|
|
cb();
|
|
}
|
|
});
|
|
}
|
|
function makeKeepAliveRequest(cb) {
|
|
http.get({
|
|
socketPath: common.PIPE,
|
|
headers: { connection: 'keep-alive' }
|
|
}, (res) => res.on('data', common.mustNotCall())
|
|
.on('error', assert.fail)
|
|
.on('end', cb)
|
|
);
|
|
}
|
|
|