Skip to content
Browse files

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

  • Loading branch information...
1 parent fc61134 commit a0185dd7768a9bc4f3be1a2d54d5efd2991a724b @bnoordhuis committed Nov 1, 2011
Showing with 48 additions and 2 deletions.
  1. +9 −2 lib/net.js
  2. +39 −0 test/simple/test-pipe-address.js
View
11 lib/net.js
@@ -722,7 +722,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') {
@@ -743,7 +744,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) {
View
39 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 a0185dd

Please sign in to comment.
Something went wrong with that request. Please try again.