From f5c0f8046aed4fb3c403526e3aa3e8e3664b1789 Mon Sep 17 00:00:00 2001 From: Niek Date: Tue, 24 Jan 2012 10:45:00 +0100 Subject: [PATCH 1/2] Added UNIX socket support --- lib/client.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index e784b87..04b0dc2 100644 --- a/lib/client.js +++ b/lib/client.js @@ -142,8 +142,13 @@ var Client = exports.Client = function Client (port, host, options) { this.connectionsMade = 0; - // Setup the TCP connection - var stream = this.stream = net.createConnection(this.port = port, this.host = host); + if (port == 0) { + // Assume UNIX socket, take host as path to socket file + var stream = this.stream = net.createConnection(this.host = host); + } else { + // Regular TCP socket, setup the TCP connection + var stream = this.stream = net.createConnection(this.port = port, this.host = host); + } stream.on("data", this.handleData.bind(this)); // currReply = null; From 65b5d7305080bf51e85092ec4f4f34932349b985 Mon Sep 17 00:00:00 2001 From: Niek Date: Mon, 30 Jan 2012 14:30:54 +0100 Subject: [PATCH 2/2] Fixed UNIX socket at reconnect --- lib/client.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 04b0dc2..e6315fe 100644 --- a/lib/client.js +++ b/lib/client.js @@ -142,8 +142,9 @@ var Client = exports.Client = function Client (port, host, options) { this.connectionsMade = 0; - if (port == 0) { + if (port === 0) { // Assume UNIX socket, take host as path to socket file + this.port = port; var stream = this.stream = net.createConnection(this.host = host); } else { // Regular TCP socket, setup the TCP connection @@ -341,7 +342,11 @@ Client.prototype.attemptReconnect = function () { client = this; this.reconnectionTimer = setTimeout( function () { client.emit("reconnecting", client); - stream.connect(client.port, client.host); + if (client.port === 0) { // UNIX socket + stream.connect(client.host); + } else { // TCP socket + stream.connect(client.port, client.host); + } }, delay); };