net: implement Server.prototype.address() for pipes

This commit is contained in:
Ben Noordhuis 2011-11-01 23:42:45 +01:00
Родитель 481c17504d
Коммит 9c11e8a1ca
2 изменённых файлов: 48 добавлений и 2 удалений

Просмотреть файл

@ -743,7 +743,8 @@ Server.prototype.listen = function() {
} else if (isPipeName(arguments[0])) {
// UNIX socket or Windows pipe.
listen(self, arguments[0], -1, -1);
var pipeName = self._pipeName = arguments[0];
listen(self, pipeName, -1, -1);
} else if (typeof arguments[1] == 'undefined' ||
typeof arguments[1] == 'function') {
@ -764,7 +765,13 @@ Server.prototype.listen = function() {
};
Server.prototype.address = function() {
return this._handle.getsockname();
if (this._handle && this._handle.getsockname) {
return this._handle.getsockname();
} else if (this._pipeName) {
return this._pipeName;
} else {
return null;
}
};
function onconnection(clientHandle) {

Просмотреть файл

@ -0,0 +1,39 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var common = require('../common');
var assert = require('assert');
var net = require('net');
var address = null;
var server = net.createServer(function() {
assert(false); // should not be called
});
server.listen(common.PIPE, function() {
address = server.address();
server.close();
});
process.on('exit', function() {
assert.equal(address, common.PIPE);
});