HTTP works somewhat on net2 now

However it's not working very well: Hitting a 'hello world' server with many
requests (ab -t 60 -c 10) will cause it to crash with the following error.

  Obtained 3 stack frames.

  ./node(_Z11print_tracev+0x1c) [0x80d1b3c]
  ./node(_ZN4node6Parser7ExecuteERKN2v89ArgumentsE+0x69) [0x80d3759]
  ./node [0x811f44b]
  TypeError: Already parsing a buffer
      at Socket.<anonymous> (/home/ryan/projects/node/lib/http2.js:393:20)
      at IOWatcher.callback (/home/ryan/projects/node/lib/net.js:81:12)
      at node.js:985:9
      at node.js:989:1
This commit is contained in:
Ryan Dahl committed 2010-01-25 17:55:08 -08:00
1 parent dda1d681f7
commit 741e3fa91b
7 files changed
+124 -31

No files matched your search

+46
View File
@@ -19,6 +19,30 @@
// No copying is performed when slicing the buffer, only small reference
// allocations.
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
/* Obtain a backtrace and print it to stdout. */
void
print_trace (void)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size);
for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);
}
namespace node {
using namespace v8;
@@ -93,6 +117,7 @@ static Persistent<String> should_keep_alive_sym;
, Integer::New(length) \
}; \
Local<Value> ret = cb->Call(parser->handle_, 3, argv); \
assert(parser->buffer_); \
return ret.IsEmpty() ? -1 : 0; \
}
@@ -141,6 +166,10 @@ class Parser : public ObjectWrap {
parser_.data = this;
}
~Parser() {
assert(buffer_ == NULL && "Destroying a parser while it's parsing");
}
DEFINE_HTTP_CB(on_message_begin)
DEFINE_HTTP_CB(on_message_complete)
@@ -215,6 +244,7 @@ class Parser : public ObjectWrap {
Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
if (parser->buffer_) {
print_trace();
return ThrowException(Exception::TypeError(
String::New("Already parsing a buffer")));
}
@@ -243,9 +273,13 @@ class Parser : public ObjectWrap {
// Assign 'buffer_' while we parse. The callbacks will access that varible.
parser->buffer_ = buffer;
buffer_ref(parser->buffer_);
size_t nparsed =
http_parser_execute(&(parser->parser_), buffer_p(buffer, off), len);
buffer_unref(parser->buffer_);
// Unassign the 'buffer_' variable
assert(parser->buffer_);
parser->buffer_ = NULL;
@@ -266,6 +300,17 @@ class Parser : public ObjectWrap {
return scope.Close(nparsed_obj);
}
static Handle<Value> ExecuteEOF(const Arguments& args) {
HandleScope scope;
Parser *parser = ObjectWrap::Unwrap<Parser>(args.This());
assert(!parser->buffer_);
http_parser_execute(&parser->parser_, NULL, 0);
return Undefined();
}
private:
@@ -282,6 +327,7 @@ void InitHttpParser(Handle<Object> target) {
//t->SetClassName(String::NewSymbol("HTTPParser"));
NODE_SET_PROTOTYPE_METHOD(t, "execute", Parser::Execute);
NODE_SET_PROTOTYPE_METHOD(t, "executeEOF", Parser::ExecuteEOF);
target->Set(String::NewSymbol("HTTPParser"), t->GetFunction());