diff --git a/lib/net_uv.js b/lib/net_uv.js index f13322d6d44..4ea91221d09 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -284,6 +284,26 @@ function afterWrite(status, handle, req, buffer) { } +function connectip(self, port, ip) { + self.remoteAddress = ip; + self.remotePort = port; + + // TODO return promise from Socket.prototype.connect which + // wraps _connectReq. + + assert.ok(!self._connecting); + + var connectReq = self._handle.connect(ip, port); + + if (connectReq) { + self._connecting = true; + connectReq.oncomplete = afterConnect; + } else { + self.destroy(errnoException(errno, 'connect')); + } +} + + Socket.prototype.connect = function(port, host /* [cb] */) { var self = this; @@ -293,36 +313,23 @@ Socket.prototype.connect = function(port, host /* [cb] */) { timers.active(this); - require('dns').lookup(host, function(err, ip, addressType) { - if (err) { - self.emit('error', err); - } else { - timers.active(self); - - if (addressType != 4) { - throw new Error("ipv6 addresses not yet supported by libuv"); - } - - ip = ip || '127.0.0.1'; - - self.remoteAddress = ip; - self.remotePort = port; - - // TODO retrun promise from Socket.prototype.connect which - // wraps _connectReq. - - assert.ok(!self._connecting); - - var connectReq = self._handle.connect(ip, port); - - if (connectReq) { - self._connecting = true; - connectReq.oncomplete = afterConnect; + if (typeof host == 'undefined') { + connectip(self, port, '127.0.0.1'); + } else { + require('dns').lookup(host, function(err, ip, addressType) { + if (err) { + self.emit('error', err); } else { - self.destroy(errnoException(errno, 'connect')); + timers.active(self); + + if (addressType != 4) { + throw new Error("ipv6 addresses not yet supported by libuv"); + } + + connectip(self, port, ip || '127.0.0.1'); } - } - }); + }); + } }; @@ -391,6 +398,16 @@ exports.Server = Server; function toPort(x) { return (x = Number(x)) >= 0 ? x : false; } +function listenip(self, ip, port) { + var r = self._handle.bind(ip, port); + if (r) { + self.emit('error', errnoException(errno, 'listen')); + } else { + self._handle.listen(self._backlog || 128); + self.emit('listening'); + } +} + Server.prototype.listen = function() { var self = this; @@ -406,8 +423,13 @@ Server.prototype.listen = function() { // The port can be found with server.address() this._handle.listen(self._backlog || 128); this.emit('listening'); + + } else if (typeof arguments[1] == 'undefined') { + // The first argument is the port, no IP given. + listenip(self, '0.0.0.0', port); + } else { - // the first argument is the port, the second an IP + // The first argument is the port, the second an IP require('dns').lookup(arguments[1], function(err, ip, addressType) { if (err) { self.emit('error', err); @@ -415,14 +437,7 @@ Server.prototype.listen = function() { if (addressType != 4) { throw new Error("ipv6 addresses not yet supported by libuv"); } - - var r = self._handle.bind(ip || '0.0.0.0', port); - if (r) { - self.emit('error', errnoException(errno, 'listen')); - } else { - self._handle.listen(self._backlog || 128); - self.emit('listening'); - } + listenip(self, ip || '0.0.0.0', port); } }); } diff --git a/src/node.h b/src/node.h index f7299b57af0..1eca872a005 100644 --- a/src/node.h +++ b/src/node.h @@ -22,6 +22,15 @@ #ifndef SRC_NODE_H_ #define SRC_NODE_H_ +// A dependency include (libeio\xthread.h) defines _WIN32_WINNT to another value +// This should be defined in make system. +// See issue https://github.com/joyent/node/issues/1236 +#ifdef __MINGW32__ +#ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0501 +#endif +#endif + #include #include #include diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 0d3d119640b..668ae556a6f 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -1,5 +1,3 @@ -#include -#include #include #include diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 38954863836..87ccbe224bd 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -1,5 +1,3 @@ -#include -#include #include // Rules: diff --git a/test/simple/test-net-pingpong.js b/test/simple/test-net-pingpong.js index f20ec057f37..035e4f3892f 100644 --- a/test/simple/test-net-pingpong.js +++ b/test/simple/test-net-pingpong.js @@ -129,12 +129,19 @@ function pingPongTest(port, host) { } /* All are run at once, so run on different ports */ -pingPongTest(20989, 'localhost'); +if (!process.useUV) { + // these tests will not run yet with net_uv TODO: remove when net_uv supports dns + pingPongTest(20989, 'localhost'); + pingPongTest(20997, '::1'); + pingPongTest('/tmp/pingpong.sock'); +} pingPongTest(20988); -pingPongTest(20997, '::1'); -pingPongTest('/tmp/pingpong.sock'); -process.addListener('exit', function() { - assert.equal(4, tests_run); +process.addListener('exit', function () { + if (!process.useUV) { + assert.equal(4, tests_run); + } else { + assert.equal(1, tests_run); + } console.log('done'); });