不要怂,就是干,撸起袖子干!

Commit d235a604 by Sascha Depold

refactored to use callback for error handling

1 parent 2da1680f
Showing with 15 additions and 9 deletions
...@@ -14,16 +14,22 @@ ...@@ -14,16 +14,22 @@
return len; return len;
} }
exports.createTCPClient = function(host, port) exports.createTCPClient = function()
{ {
var host = host ? host : "localhost"; var args = exports.createTCPClient.arguments,
var port = port ? port : 3306; host = (args.length == 3) ? args['0'] : "localhost",
var connection = net.createConnection(port, host); port = (args.length == 3) ? args['1'] : 3306,
connection.pscache = {}; callback = (args.length == 3) ? args['2'] : args['0'],
connection.setEncoding("binary"); connection = net.createConnection(port, host)
connection.setTimeout(0);
connection.on("connect", function() {
return new socketClient(connection); connection.pscache = {};
connection.setEncoding("binary");
connection.setTimeout(0);
callback(null, new socketClient(connection))
})
connection.on("error", callback)
} }
exports.createUNIXClient = function(path) exports.createUNIXClient = function(path)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!