Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
net: implement Server.prototype.address() for pipes
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Nov 3, 2011
1 parent 481c175 commit 9c11e8a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/net.js
Expand Up @@ -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') {
Expand All @@ -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) {
Expand Down
39 changes: 39 additions & 0 deletions test/simple/test-pipe-address.js
@@ -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);
});

0 comments on commit 9c11e8a

Please sign in to comment.