Skip to content

Commit

Permalink
untested .connect() code
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Nov 29, 2011
1 parent 8e91b8a commit e34abfa
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ exports.createServer = function (domain, cb) {
};

exports.connect = function (port, host, cb) {
if (typeof port === 'string' && typeof host === 'number') {
var host_ = port, port_ = host;
host = host_, port = port_;
var args = [].slice.call(arguments).reduce(function (acc, arg) {
acc[typeof arg] = arg;
return acc;
}, {});
var cb = args.function;

if (args.string && args.string.match(/^[.\/]/)) {
// unix socket
var stream = net.createConnection(args.string, function () {
cb(proto.server(stream));
});
}
if (typeof host === 'function') {
cb = host;
host = 'localhost';
else {
var port = args.number || 25;
var host = args.string || 'localhost';
var stream = net.createConnection(port, host, function () {
cb(proto.server(stream));
});
}

var stream = net.createConnection(port, host, function () {
cb(proto.server(stream));
});
return stream;
};

0 comments on commit e34abfa

Please sign in to comment.