From: Maciej MaƂecki Date: Sun, 23 Oct 2011 09:20:03 +0000 (+0200) Subject: net: `Server.listen`, `Server.close` and `Socket.connect` return `this` X-Git-Tag: v0.6.0~114 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ee29d1d5ba1655fa9f7a42afbe9ebf2f6e1c19f;p=platform%2Fupstream%2Fnodejs.git net: `Server.listen`, `Server.close` and `Socket.connect` return `this` Just a syntactic sugar for doing, for example: var server = net.createServer(function (c) { c.end('goodbye, cruel world!\r\n'); server.close().on('close', function () { console.log('really, goodbye!'); }); }).listen(1337); Fixes #1922. --- diff --git a/lib/net.js b/lib/net.js index 2d09e49..2d33c46 100644 --- a/lib/net.js +++ b/lib/net.js @@ -53,8 +53,7 @@ exports.connect = exports.createConnection = function(port /* [host], [cb] */) { s = new Socket(); } - s.connect(port, arguments[1], arguments[2]); - return s; + return s.connect(port, arguments[1], arguments[2]); }; /* called when creating new Socket, or when re-using a closed Socket */ @@ -536,6 +535,7 @@ Socket.prototype.connect = function(port /* [host], [cb] */) { debug('connect: missing host'); connect(self, '127.0.0.1', port, 4); } + return self; }; @@ -739,6 +739,7 @@ Server.prototype.listen = function() { } }); } + return self; }; Server.prototype.address = function() { @@ -787,6 +788,8 @@ Server.prototype.close = function() { this._handle.close(); this._handle = null; this._emitCloseIfDrained(); + + return this; }; Server.prototype._emitCloseIfDrained = function() {