diff --git a/Makefile b/Makefile index 82d1d344b6..8396309bfe 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ V8INC = $(HOME)/src/v8/include V8LIB = $(HOME)/src/v8/libv8.a CFLAGS = -g -I$(V8INC) -Ideps/oi -DHAVE_GNUTLS=0 -Ideps/ebb -LDFLAGS = -lev -pthread -lefence +LDFLAGS = -lev -pthread # -lefence ifdef EVDIR CFLAGS += -I$(EVDIR)/include diff --git a/count-hosts.js b/count-hosts.js index d341d6d1bc..caaf4a8289 100644 --- a/count-hosts.js +++ b/count-hosts.js @@ -5,12 +5,12 @@ function Process(request) { // request.headers => { "Content-Length": "123" } // request.http_version => "1.1" // - log("Processing " + request.path + ". method: " + request.method); + //log("Processing " + request.path + ". method: " + request.method); // sends null on the last chunk. request.onBody = function (chunk) { - log("got chunk length: " + chunk.length.toString(16) ); if(chunk) { + //log( "got chunk length: " + chunk.length.toString() ); this.respond(chunk.length.toString(16) + "\r\n" + chunk + "\r\n"); } else { this.respond("0\r\n\r\n"); @@ -22,6 +22,7 @@ function Process(request) { request.respond("Content-Type: text-plain\r\n"); request.respond("Transfer-Encoding: chunked\r\n"); request.respond("\r\n"); + request.respond("0\r\n\r\n"); //request.respond("Content-Length: 6\r\n\r\nhello\n"); // } diff --git a/server.cc b/server.cc index 5cc8256684..2d5257e2be 100644 --- a/server.cc +++ b/server.cc @@ -61,9 +61,10 @@ static void make_onBody_callback { HandleScope handle_scope; + Handle obj = request->js_object; // XXX don't always allocate onBody strings - Handle onBody_val = obj->Get(String::New("onBody")); + Handle onBody_val = request->js_object->Get(String::NewSymbol("onBody")); if (!onBody_val->IsFunction()) return; Handle onBody = Handle::Cast(onBody_val); @@ -78,7 +79,7 @@ static void make_onBody_callback argv[0] = Null(); } - Handle result = onBody->Call(obj, argc, argv); + Handle result = onBody->Call(request->js_object, argc, argv); if (result.IsEmpty()) { String::Utf8Value error(try_catch.Exception()); @@ -121,21 +122,21 @@ static Handle RespondCallback // keep-alive it's possible that one response can return before the last // one has been sent!!! - printf("response called\n"); + //printf("response called\n"); if(arg == Null()) { - printf("response got null\n"); - //delete request; + //printf("response got null\n"); + delete request; } else { Handle s = arg->ToString(); - printf("response called len %d\n", s->Length()); + //printf("response called len %d\n", s->Length()); oi_buf *buf = oi_buf_new2(s->Length()); - s->WriteAscii(buf->base, s->Length()); + s->WriteAscii(buf->base, 0, s->Length()); oi_socket_write(&request->connection.socket, buf); @@ -146,9 +147,7 @@ static Handle RespondCallback HttpRequest::~HttpRequest () { - //make_onBody_callback(this, NULL, 0); // EOF - - printf("request is being destructed\n"); + //printf("request is being destructed\n"); connection.socket.on_drain = oi_socket_close; @@ -208,7 +207,7 @@ static void on_headers_complete , GetMethodString(request->parser_info.method) ); - Persistent js_object = Persistent::New(result); + request->js_object = Persistent::New(result); // Enter this processor's context so all the remaining operations // take place there @@ -220,7 +219,7 @@ static void on_headers_complete // Invoke the process function, giving the global object as 'this' // and one argument, the request. const int argc = 1; - Handle argv[argc] = { js_object }; + Handle argv[argc] = { request->js_object }; Handle r = process_->Call(context_->Global(), argc, argv); if (r.IsEmpty()) { String::Utf8Value error(try_catch.Exception()); @@ -234,7 +233,7 @@ static void on_request_complete { HttpRequest *request = static_cast (req->data); - //delete request; + make_onBody_callback(request, NULL, 0); // EOF } @@ -244,7 +243,7 @@ static void on_body , size_t length ) { - printf("on body %d\n", length); + //printf("on body %d\n", length); HttpRequest *request = static_cast (req->data); @@ -416,6 +415,7 @@ static Handle LogCallback String::Utf8Value value(arg); printf("Logged: %s\n", *value); + fflush(stdout); return v8::Undefined(); }