summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-12-15 15:57:13 -0800
committerRyan Dahl <ry@tinyclouds.org>2010-12-15 15:57:41 -0800
commit632da2a393a633f8da432096b14bec5915480115 (patch)
treeecfc8372b2a110adee80101c1020ff895846229b
parentc4161f32f5e2f36db25629b3bf2ab617e66070ae (diff)
downloadnode-new-632da2a393a633f8da432096b14bec5915480115.tar.gz
Add callback paramenter to socket.connect()
-rw-r--r--doc/api/net.markdown7
-rw-r--r--lib/net.js5
-rw-r--r--test/simple/test-net-connect-buffer.js5
3 files changed, 11 insertions, 6 deletions
diff --git a/doc/api/net.markdown b/doc/api/net.markdown
index 6146fd751d..4e905686f6 100644
--- a/doc/api/net.markdown
+++ b/doc/api/net.markdown
@@ -153,8 +153,8 @@ and passed to the user through the `'connection'` event of a server.
`net.Stream` instances are EventEmitters with the following events:
-#### stream.connect(port, [host])
-#### stream.connect(path)
+#### stream.connect(port, [host], [callback])
+#### stream.connect(path, [callback])
Opens the connection for a given stream. If `port` and `host` are given,
then the stream will be opened as a TCP stream, if `host` is omitted,
@@ -170,6 +170,9 @@ stream is established. If there is a problem connecting, the `'connect'`
event will not be emitted, the `'error'` event will be emitted with
the exception.
+The `callback` paramenter will be added as an listener for the 'connect'
+event.
+
#### stream.setEncoding(encoding=null)
diff --git a/lib/net.js b/lib/net.js
index db491be59b..d29984668a 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -638,6 +638,11 @@ Stream.prototype.connect = function() {
self._connecting = true; // set false in doConnect
self.writable = true;
+ var lastArg = arguments[arguments.length - 1];
+ if (typeof lastArg == 'function') {
+ self.addListener('connect', lastArg);
+ }
+
var port = toPort(arguments[0]);
if (port === false) {
// UNIX
diff --git a/test/simple/test-net-connect-buffer.js b/test/simple/test-net-connect-buffer.js
index 6e6bc88528..4843f43d94 100644
--- a/test/simple/test-net-connect-buffer.js
+++ b/test/simple/test-net-connect-buffer.js
@@ -33,10 +33,7 @@ tcp.listen(common.PORT, function () {
console.log('Connecting to socket');
- socket.connect(tcpPort);
-
-
- socket.on('connect', function() {
+ socket.connect(tcpPort, function() {
console.log('socket connected');
connectHappened = true;
});