Browse Source

Fixes for ipv6

v0.7.4-release
Ryan 16 years ago
parent
commit
e30e4415ee
  1. 0
      http_simple.js
  2. 20
      src/net.cc
  3. 46
      test/test-tcp-pingpong.js
  4. 41
      test_client.js

0
test-http_simple.js → http_simple.js

20
src/net.cc

@ -42,14 +42,14 @@ using namespace node;
#define CLOSED_SYMBOL String::NewSymbol("closed")
static const struct addrinfo server_tcp_hints =
/* ai_flags */ { AI_PASSIVE | AI_ADDRCONFIG
/* ai_flags */ { AI_PASSIVE
/* ai_family */ , AF_UNSPEC
/* ai_socktype */ , SOCK_STREAM
, 0
};
static const struct addrinfo client_tcp_hints =
/* ai_flags */ { AI_ADDRCONFIG
/* ai_flags */ { 0
/* ai_family */ , AF_UNSPEC
/* ai_socktype */ , SOCK_STREAM
, 0
@ -591,21 +591,21 @@ static void
SetRemoteAddress (Local<Object> connection_handle, struct sockaddr *addr)
{
HandleScope scope;
char ip4[INET_ADDRSTRLEN], ip6[INET6_ADDRSTRLEN];
char ip[INET6_ADDRSTRLEN];
Local<String> remote_address;
if (addr->sa_family == AF_INET) {
struct sockaddr_in *sa = reinterpret_cast<struct sockaddr_in*>(addr);
inet_ntop(AF_INET, &(sa->sin_addr), ip4, INET_ADDRSTRLEN);
remote_address = String::New(ip4);
inet_ntop(AF_INET, &(sa->sin_addr), ip, INET6_ADDRSTRLEN);
remote_address = String::New(ip);
} else if (addr->sa_family == AF_INET6) {
struct sockaddr_in6 *sa6 = reinterpret_cast<struct sockaddr_in6*>(addr);
inet_ntop(AF_INET6, &(sa6->sin6_addr), ip6, INET6_ADDRSTRLEN);
remote_address = String::New(ip6);
inet_ntop(AF_INET6, &(sa6->sin6_addr), ip, INET6_ADDRSTRLEN);
remote_address = String::New(ip);
} else assert(0 && "received a bad sa_family");
} else {
assert(0 && "received a bad sa_family");
}
connection_handle->Set(REMOTE_ADDRESS_SYMBOL, remote_address);
}

46
test/test-tcp-pingpong.js

@ -1,17 +1,24 @@
include("mjsunit.js");
var port = 12123;
var N = 1000;
var count = 0;
var sent_final_ping = false;
var tests_run = 0;
function pingPongTest (port, host, on_complete) {
var N = 1000;
var count = 0;
var sent_final_ping = false;
var server = new node.tcp.Server(function (socket) {
assertTrue(socket.remoteAddress !== null);
assertTrue(socket.remoteAddress !== undefined);
if (host === "127.0.0.1")
assertEquals(socket.remoteAddress, "127.0.0.1");
else if (host == null)
assertEquals(socket.remoteAddress, "127.0.0.1");
function Ponger (socket) {
socket.setEncoding("utf8");
socket.timeout = 0;
assertEquals("127.0.0.1", socket.remoteAddress);
socket.onReceive = function (data) {
assertEquals("open", socket.readyState);
assertTrue(count <= N);
@ -30,11 +37,8 @@ function Ponger (socket) {
assertEquals("closed", socket.readyState);
socket.server.close();
};
}
function onLoad () {
var server = new node.tcp.Server(Ponger);
server.listen(port);
});
server.listen(port, host);
var client = new node.tcp.Connection();
assertEquals("closed", client.readyState);
@ -66,14 +70,24 @@ function onLoad () {
}
};
client.onEOF = function () {
client.onDisconnect = function () {
assertEquals(N+1, count);
assertTrue(sent_final_ping);
if (on_complete) on_complete();
tests_run += 1;
};
assertEquals("closed", client.readyState);
client.connect(port, "localhost");
client.connect(port, host);
}
function onLoad () {
/* All are run at once, so run on different ports */
pingPongTest(20989, "localhost");
pingPongTest(20988, null);
pingPongTest(20997, "::1");
}
function onExit () {
assertEquals(N+1, count);
assertTrue(sent_final_ping);
assertEquals(3, tests_run);
}

41
test_client.js

@ -1,41 +0,0 @@
var c = new node.http.Client(8000, "127.0.0.1");
c.onError = function () {
puts("http client connection error.");
};
var req = c.get("/bytes/123", [["Accept", "*/*"]]);
req.finish(function (res) {
puts("response 1: " + res.statusCode.toString());
res.onBody = function (chunk) {
chunk = chunk.encodeUtf8();
puts("response 1 body <" + JSON.stringify(chunk) + ">");
return true;
};
res.onBodyComplete = function () {
puts("response 1 complete!");
return true;
};
});
setTimeout(function () {
var req2 = c.get("/something/else");
//node.debug("start req2");
req2.finish(function (res) {
puts("response 2: " + res.statusCode.toString());
res.onBody = function (chunk) {
chunk = chunk.encodeUtf8();
puts("response 2 body <" + JSON.stringify(chunk) + ">");
return true;
};
res.onBodyComplete = function () {
puts("response 2 complete!");
return true;
};
});
}, 2000);
Loading…
Cancel
Save