Browse Source

allow null host parameter to listen on localhost

v0.7.4-release
Ryan 16 years ago
parent
commit
1e5de42a75
  1. 23
      Makefile
  2. 10
      node_http.cc
  3. 8
      node_tcp.cc
  4. 32
      tcp_example.js
  5. 2
      test/test_http_server_echo.rb
  6. 2
      test/test_http_server_null_response.rb

23
Makefile

@ -1,9 +1,13 @@
EVDIR=$(HOME)/local/libev
OIINC = $(HOME)/projects/oi/
OILIB = $(HOME)/projects/oi/liboi.a
V8INC = $(HOME)/src/v8/include
V8LIB = $(HOME)/src/v8/libv8_g.a
#V8LIB = $(HOME)/src/v8/libv8.a
#V8LIB = $(HOME)/src/v8/libv8_g.a
V8LIB = $(HOME)/src/v8/libv8.a
CFLAGS = -g -I$(V8INC) -Ideps/oi -DHAVE_GNUTLS=0 -Ideps/ebb
CFLAGS = -g -I$(V8INC) -I$(OIINC) -DHAVE_GNUTLS=0 -Ideps/ebb
LDFLAGS = -lev -pthread # -lefence
ifdef EVDIR
@ -11,8 +15,8 @@ ifdef EVDIR
LDFLAGS += -L$(EVDIR)/lib
endif
node: node.o node_tcp.o node_http.o node_timer.o oi_socket.o oi_async.o oi_buf.o ebb_request_parser.o
g++ -o node $^ $(LDFLAGS) $(V8LIB)
node: node.o node_tcp.o node_http.o node_timer.o ebb_request_parser.o
g++ -o node $^ $(LDFLAGS) $(V8LIB) $(OILIB)
node.o: node.cc
g++ $(CFLAGS) -c $<
@ -25,15 +29,6 @@ node_http.o: node_http.cc
node_timer.o: node_timer.cc
g++ $(CFLAGS) -c $<
oi_socket.o: deps/oi/oi_socket.c deps/oi/oi_socket.h
gcc $(CFLAGS) -c $<
oi_async.o: deps/oi/oi_async.c deps/oi/oi_async.h
gcc $(CFLAGS) -c $<
oi_buf.o: deps/oi/oi_buf.c deps/oi/oi_buf.h
gcc $(CFLAGS) -c $<
ebb_request_parser.o: ebb_request_parser.c deps/ebb/ebb_request_parser.h
g++ $(CFLAGS) -c $<

10
node_http.cc

@ -153,8 +153,6 @@ RespondCallback (const Arguments& args)
void
HttpRequest::Respond (Handle<Value> data)
{
// TODO ByteArray ?
if(data == Null()) {
done = true;
} else {
@ -607,7 +605,11 @@ newHTTPServer (const Arguments& args)
HandleScope scope;
String::AsciiValue host(args[0]->ToString());
char *host = NULL;
String::AsciiValue host_v(args[0]->ToString());
if(args[0]->IsString()) {
host = *host_v;
}
String::AsciiValue port(args[1]->ToString());
Handle<Function> onrequest = Handle<Function>::Cast(args[2]);
@ -621,7 +623,7 @@ newHTTPServer (const Arguments& args)
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
// FIXME BLOCKING
int r = getaddrinfo(*host, *port, &hints, &servinfo);
int r = getaddrinfo(host, *port, &hints, &servinfo);
if (r != 0)
return Undefined(); // XXX raise error?

8
node_tcp.cc

@ -84,14 +84,18 @@ static Handle<Value> newTCPClient
HandleScope scope;
String::AsciiValue host(args[0]);
char *host = NULL;
String::AsciiValue host_v(args[0]->ToString());
if(args[0]->IsString()) {
host = *host_v;
}
String::AsciiValue port(args[1]);
TCPClient *client = new TCPClient(args.This());
if(client == NULL)
return Undefined(); // XXX raise error?
int r = client->Connect(*host, *port);
int r = client->Connect(host, *port);
if (r != 0)
return Undefined(); // XXX raise error?

32
tcp_example.js

@ -1,33 +1,12 @@
/*
[Constructor(in DOMString url)]
interface TCP.Client {
readonly attribute DOMString host;
readonly attribute DOMString port;
// ready state
const unsigned short CONNECTING = 0;
const unsigned short OPEN = 1;
const unsigned short CLOSED = 2;
readonly attribute long readyState;
// networking
attribute Function onopen;
attribute Function onrecv;
attribute Function onclose;
void send(in DOMString data);
void disconnect();
};
*/
client = new TCPClient("localhost", 11222);
client = new TCPClient("google.com", 80);
log("readyState: " + client.readyState);
//assertEqual(client.readystate, TCP.CONNECTING);
client.onopen = function () {
log("connected to dynomite");
log("connected to google");
log("readyState: " + client.readyState);
client.write("get 1 /\n");
client.write("GET / HTTP/1.1\r\n\r\n");
};
client.onread = function (chunk) {
@ -38,8 +17,11 @@ client.onclose = function () {
log("connection closed");
};
setTimeout(function () {
client.disconnect();
}, 1000);
}, 10 * 1000);
log("hello");

2
test/test_http_server_echo.rb

@ -32,7 +32,7 @@ function encode(data) {
}
var port = 8000;
var server = new HTTPServer("localhost", port, function (request) {
var server = new HTTPServer(null, port, function (request) {
// onBody sends null on the last chunk.
request.onbody = function (chunk) {

2
test/test_http_server_null_response.rb

@ -16,7 +16,7 @@ ensure
end
__END__
var server = new HTTPServer("localhost", 8000, function (request) {
var server = new HTTPServer(null, 8000, function (request) {
log("request");
request.respond("HTTP/1.1 200 OK\r\n");
request.respond("Content-Length: 0\r\n");

Loading…
Cancel
Save