2017-03-10 09:55:36 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const net = require('net');
|
2018-03-08 00:09:24 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const fs = require('fs');
|
2017-03-10 09:55:36 +08:00
|
|
|
|
2017-12-24 22:38:11 -08:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
2017-03-10 09:55:36 +08:00
|
|
|
|
|
|
|
function closeServer() {
|
|
|
|
return common.mustCall(function() {
|
|
|
|
this.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let counter = 0;
|
|
|
|
|
|
|
|
// Avoid conflict with listen-handle
|
|
|
|
function randomPipePath() {
|
2017-04-28 04:06:42 +03:00
|
|
|
return `${common.PIPE}-listen-path-${counter++}`;
|
2017-03-10 09:55:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test listen(path)
|
|
|
|
{
|
|
|
|
const handlePath = randomPipePath();
|
|
|
|
net.createServer()
|
|
|
|
.listen(handlePath)
|
|
|
|
.on('listening', closeServer());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test listen({path})
|
|
|
|
{
|
|
|
|
const handlePath = randomPipePath();
|
|
|
|
net.createServer()
|
2017-07-10 20:55:21 -04:00
|
|
|
.listen({ path: handlePath })
|
2017-03-10 09:55:36 +08:00
|
|
|
.on('listening', closeServer());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test listen(path, cb)
|
|
|
|
{
|
|
|
|
const handlePath = randomPipePath();
|
|
|
|
net.createServer()
|
|
|
|
.listen(handlePath, closeServer());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test listen(path, cb)
|
|
|
|
{
|
|
|
|
const handlePath = randomPipePath();
|
|
|
|
net.createServer()
|
2017-07-10 20:55:21 -04:00
|
|
|
.listen({ path: handlePath }, closeServer());
|
2017-03-10 09:55:36 +08:00
|
|
|
}
|
2018-03-08 00:09:24 +01:00
|
|
|
|
|
|
|
// Test pipe chmod
|
|
|
|
{
|
|
|
|
const handlePath = randomPipePath();
|
|
|
|
|
|
|
|
const srv = net.createServer()
|
|
|
|
.listen({
|
|
|
|
path: handlePath,
|
|
|
|
readableAll: true,
|
|
|
|
writableAll: true
|
|
|
|
}, common.mustCall(() => {
|
|
|
|
if (process.platform !== 'win32') {
|
|
|
|
const mode = fs.statSync(handlePath).mode;
|
2018-07-29 20:33:58 -04:00
|
|
|
assert.notStrictEqual(mode & fs.constants.S_IROTH, 0);
|
|
|
|
assert.notStrictEqual(mode & fs.constants.S_IWOTH, 0);
|
2018-03-08 00:09:24 +01:00
|
|
|
}
|
|
|
|
srv.close();
|
|
|
|
}));
|
|
|
|
}
|