diff options
author | Ryan <ry@tinyclouds.org> | 2009-05-19 21:53:26 +0200 |
---|---|---|
committer | Ryan <ry@tinyclouds.org> | 2009-05-19 21:53:26 +0200 |
commit | 82e773630b38f4a5c0ec6eaf18c361fbe687fc15 (patch) | |
tree | 019ebf6370b0e36c7e1a4692a15efd25faf32840 /src | |
parent | b445514898c200720400c04aeafc9fa326a966f4 (diff) | |
download | node-new-82e773630b38f4a5c0ec6eaf18c361fbe687fc15.tar.gz |
HTTP Client: add fix to allow TCP connection to reconnect.
Diffstat (limited to 'src')
-rw-r--r-- | src/http.cc | 10 | ||||
-rw-r--r-- | src/net.cc | 18 | ||||
-rw-r--r-- | src/net.h | 2 |
3 files changed, 25 insertions, 5 deletions
diff --git a/src/http.cc b/src/http.cc index be0f478130..4ebc639457 100644 --- a/src/http.cc +++ b/src/http.cc @@ -136,7 +136,7 @@ DEFINE_PARSER_CALLBACK(on_uri, ON_URI_SYMBOL) DEFINE_PARSER_CALLBACK(on_header_field, ON_HEADER_FIELD_SYMBOL) DEFINE_PARSER_CALLBACK(on_header_value, ON_HEADER_VALUE_SYMBOL) -static Local<String> +static inline Local<String> GetMethod (int method) { switch (method) { @@ -169,11 +169,13 @@ HTTPConnection::on_headers_complete (http_parser *parser) Local<Object> message_handler = message_handler_v->ToObject(); // METHOD - message_handler->Set(METHOD_SYMBOL, GetMethod(connection->parser_.method)); + if (connection->parser_.type == HTTP_REQUEST) + message_handler->Set(METHOD_SYMBOL, GetMethod(connection->parser_.method)); // STATUS - message_handler->Set(STATUS_CODE_SYMBOL, - Integer::New(connection->parser_.status_code)); + if (connection->parser_.type == HTTP_RESPONSE) + message_handler->Set(STATUS_CODE_SYMBOL, + Integer::New(connection->parser_.status_code)); // VERSION char version[10]; diff --git a/src/net.cc b/src/net.cc index fbed1afebb..e8bfffc6ec 100644 --- a/src/net.cc +++ b/src/net.cc @@ -137,11 +137,17 @@ Connection::Connection (Handle<Object> handle) : ObjectWrap(handle) { encoding_ = RAW; - double timeout = 60.0; // default host_ = NULL; port_ = NULL; + Init(); +} + +void +Connection::Init (void) +{ + double timeout = 60.0; // default oi_socket_init(&socket_, timeout); socket_.on_connect = Connection::on_connect; socket_.on_read = Connection::on_read; @@ -151,6 +157,7 @@ Connection::Connection (Handle<Object> handle) socket_.data = this; } + Connection::~Connection () { static int i = 0; @@ -190,6 +197,13 @@ Connection::Connect (const Arguments& args) HandleScope scope; + if (connection->ReadyState() != CLOSED) { + return ThrowException(String::New("Socket is already connected.")); + } else { + // XXX ugly. + connection->Init(); // in case we're reusing the socket... ? + } + if (args.Length() == 0 || args[0]->IsInt32() == false) return ThrowException(String::New("Must specify a port.")); @@ -258,6 +272,8 @@ Connection::AfterResolve (eio_req *req) return 0; } + puts("net.cc: resolve failed"); + connection->OnDisconnect(); connection->Detach(); @@ -115,6 +115,8 @@ private: connection->OnTimeout(); } + void Init (void); // constructor helper. + static int Resolve (eio_req *req); static int AfterResolve (eio_req *req); char *host_; |