Fix test-net-pingpong.js on windows

This commit is contained in:
Henry Rawas 2011-06-24 12:32:09 -07:00 committed by Ryan Dahl
parent f657d58fe1
commit 47a5d93256
5 changed files with 73 additions and 46 deletions

View File

@ -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);
}
});
}

View File

@ -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 <uv.h>
#include <eio.h>
#include <v8.h>

View File

@ -1,5 +1,3 @@
#include <v8.h>
#include <uv.h>
#include <node.h>
#include <node_buffer.h>

View File

@ -1,5 +1,3 @@
#include <v8.h>
#include <uv.h>
#include <node.h>
// Rules:

View File

@ -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');
});