Don't call `server.address()` until the `'listening'` event has been emitted.
+This method used to return the file path as a string for UNIX sockets and
+Windows pipes. As of io.js v1.5.0, it returns the expected object.
+
### server.unref()
Calling `unref` on a server will allow the program to exit if this is the only
The string representation of the remote IP address. For example,
`'74.125.127.100'` or `'2001:4860:a005::68'`.
+For UNIX sockets and Windows pipes, the file path the socket is connected
+to. The remote address for server sockets is always `''`, the empty string.
+
### socket.remoteFamily
-The string representation of the remote IP family. `'IPv4'` or `'IPv6'`.
+The string representation of the remote IP family. `'IPv4'` or `'IPv6'`
+for TCP sockets, `'pipe'` for UNIX sockets and Windows pipes.
### socket.remotePort
-The numeric representation of the remote port. For example,
-`80` or `21`.
+The numeric representation of the remote port. For example, `80` or `21`.
+`undefined` for UNIX sockets and Windows pipes.
### socket.localAddress
connecting on. For example, if you are listening on `'0.0.0.0'` and the
client connects on `'192.168.1.1'`, the value would be `'192.168.1.1'`.
+For UNIX sockets and Windows pipes, the file path the socket is listening
+on. The local address for client sockets is always `''`, the empty string.
+
### socket.localPort
-The numeric representation of the local port. For example,
-`80` or `21`.
+The numeric representation of the local port. For example, `80` or `21`.
+`undefined` for UNIX sockets and Windows pipes.
### socket.bytesRead
else
listen(self, null, h.port | 0, 4, backlog, undefined, h.exclusive);
} else if (h.path && isPipeName(h.path)) {
- var pipeName = self._pipeName = h.path;
- listen(self, pipeName, -1, -1, backlog, undefined, h.exclusive);
+ listen(self, h.path, -1, -1, backlog, undefined, h.exclusive);
} else {
throw new Error('Invalid listen argument: ' + h);
}
}
} else if (isPipeName(arguments[0])) {
// UNIX socket or Windows pipe.
- var pipeName = self._pipeName = arguments[0];
- listen(self, pipeName, -1, -1, backlog);
+ listen(self, arguments[0], -1, -1, backlog);
} else if (arguments[1] === undefined ||
typeof arguments[1] === 'function' ||
this._handle.getsockname(out);
// TODO(bnoordhuis) Check err and throw?
return out;
- } else if (this._pipeName) {
- return this._pipeName;
} else {
return null;
}
env->SetProtoMethod(t, "listen", Listen);
env->SetProtoMethod(t, "connect", Connect);
env->SetProtoMethod(t, "open", Open);
+ env->SetProtoMethod(t, "getpeername",
+ GetSockOrPeerName<uv_pipe_getpeername>);
+ env->SetProtoMethod(t, "getsockname",
+ GetSockOrPeerName<uv_pipe_getsockname>);
#ifdef _WIN32
env->SetProtoMethod(t, "setPendingInstances", SetPendingInstances);
}
+template <int (*F)(const uv_pipe_t*, char*, size_t*)>
+void PipeWrap::GetSockOrPeerName(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CHECK(args[0]->IsObject());
+ char buffer[1024];
+ size_t size = sizeof(buffer);
+ const PipeWrap* wrap = Unwrap<PipeWrap>(args.Holder());
+ const int err = F(&wrap->handle_, buffer, &size);
+ if (err == 0) {
+ const uint8_t* data = reinterpret_cast<const uint8_t*>(buffer);
+ const String::NewStringType type = String::kNormalString;
+ Local<String> path =
+ String::NewFromOneByte(args.GetIsolate(), data, type, size);
+ Environment* env = Environment::GetCurrent(args);
+ Local<Object> out = args[0].As<Object>();
+ out->Set(env->address_string(), path);
+ out->Set(env->family_string(), env->pipe_string());
+ }
+ args.GetReturnValue().Set(err);
+}
+
+
} // namespace node
NODE_MODULE_CONTEXT_AWARE_BUILTIN(pipe_wrap, node::PipeWrap::Initialize)
static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Open(const v8::FunctionCallbackInfo<v8::Value>& args);
+ template <int (*F)(const uv_pipe_t*, char*, size_t*)>
+ static void GetSockOrPeerName(const v8::FunctionCallbackInfo<v8::Value>&);
+
#ifdef _WIN32
static void SetPendingInstances(
const v8::FunctionCallbackInfo<v8::Value>& args);
}});
if (exports.isWindows) {
- exports.PIPE = '\\\\.\\pipe\\libuv-test';
+ exports.PIPE = '\\\\?\\pipe\\libuv-test';
} else {
exports.PIPE = exports.tmpDir + '/test.sock';
}
}
http.createServer(function(req, res) {
- assert.equal(req.connection.remoteAddress, undefined);
- assert.equal(req.connection.localAddress, undefined); // TODO common.PIPE?
+ assert.equal(req.connection.remoteAddress, '');
+ assert.equal(req.connection.remoteFamily, 'pipe');
+ assert.equal(req.connection.remotePort, undefined);
+ assert.equal(req.connection.localAddress, common.PIPE);
+ assert.equal(req.connection.localPort, undefined);
res.writeHead(200);
res.end('OK');
}).listen(common.PIPE, function() {
var body_ok = false;
var server = http.createServer(function(req, res) {
+ assert.equal(req.socket.address().address, common.PIPE);
res.writeHead(200, {
'Content-Type': 'text/plain',
'Connection': 'close'
});
server.listen(common.PIPE, function() {
+ assert.equal(server.address().address, common.PIPE);
var options = {
socketPath: common.PIPE,
});
process.on('exit', function() {
- assert.equal(address, common.PIPE);
+ assert.equal(address.address, common.PIPE);
+ assert.equal(address.family, 'pipe');
});