From d945ba68a29067a16391d319053cf2c0b6e70a66 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 23 Feb 2009 13:48:34 +0100 Subject: [PATCH] compactify the code into a single file. will abstract later. --- Makefile | 5 +- count-hosts.js | 3 +- http_request.h | 36 --- js_http_request_processor.cc | 516 ----------------------------------- js_http_request_processor.h | 92 ------- server.cc | 268 ++++++++++++++++-- 6 files changed, 248 insertions(+), 672 deletions(-) delete mode 100644 http_request.h delete mode 100644 js_http_request_processor.cc delete mode 100644 js_http_request_processor.h diff --git a/Makefile b/Makefile index 2519fffed2..fbf96ebfe6 100644 --- a/Makefile +++ b/Makefile @@ -10,15 +10,12 @@ ifdef EVDIR LDFLAGS += -L$(EVDIR)/lib endif -server: js_http_request_processor.o server.o oi_socket.o ebb_request_parser.o oi_buf.o +server: server.o oi_socket.o ebb_request_parser.o oi_buf.o g++ -o server $^ $(LDFLAGS) $(V8LIB) server.o: server.cc g++ $(CFLAGS) -c $< -js_http_request_processor.o: js_http_request_processor.cc - g++ $(CFLAGS) -c $< - ebb_request_parser.o: ebb_request_parser.c deps/ebb/ebb_request_parser.h g++ $(CFLAGS) -c $< diff --git a/count-hosts.js b/count-hosts.js index e4bf3f9b68..c19bef015f 100644 --- a/count-hosts.js +++ b/count-hosts.js @@ -7,6 +7,7 @@ function Process(request) { } request.respond("HTTP/1.0 200 OK\r\n") - request.respond("Content-Type: text-plain\r\nContent-Length: 6\r\n\r\nhello\n"); + request.respond("Content-Type: text-plain\r\n") + request.respond("Content-Length: 6\r\n\r\nhello\n"); request.respond(null); // eof } diff --git a/http_request.h b/http_request.h deleted file mode 100644 index 5564315593..0000000000 --- a/http_request.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef http_request_h -#define http_request_h -extern "C" { -#include -#include -} -#include - -using namespace std; - -class Connection { -public: - Connection ( void) - { - oi_socket_init (&socket, 30.0); - ebb_request_parser_init (&parser); - } - ebb_request_parser parser; - oi_socket socket; -}; - -class HttpRequest { - public: - HttpRequest (Connection &c) : connection(c) - { - ebb_request_init(&parser_info); - } - ~HttpRequest() { } - - string path; - - Connection &connection; - ebb_request parser_info; -}; - -#endif // http_request_h diff --git a/js_http_request_processor.cc b/js_http_request_processor.cc deleted file mode 100644 index af2f6caf3e..0000000000 --- a/js_http_request_processor.cc +++ /dev/null @@ -1,516 +0,0 @@ -// Copyright 2008 the V8 project authors. All rights reserved. -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials provided -// with the distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include - -// To avoid warnings from on windows we disable exceptions. -#define _HAS_EXCEPTIONS 0 -#include -#include - -#include "js_http_request_processor.h" -#include - -using namespace std; -using namespace v8; - -static Handle LogCallback - ( const Arguments& args - ) -{ - if (args.Length() < 1) return v8::Undefined(); - HandleScope scope; - Handle arg = args[0]; - String::Utf8Value value(arg); - HttpRequestProcessor::Log(*value); - return v8::Undefined(); -} - - -// Execute the script and fetch the Process method. -bool JsHttpRequestProcessor::Initialize - ( map* opts - , map* output - ) -{ - // Create a handle scope to hold the temporary references. - HandleScope handle_scope; - - // Create a template for the global object where we set the - // built-in global functions. - Handle global = ObjectTemplate::New(); - global->Set(String::New("log"), FunctionTemplate::New(LogCallback)); - - // Each processor gets its own context so different processors - // don't affect each other (ignore the first three lines). - Handle context = Context::New(NULL, global); - - // Store the context in the processor object in a persistent handle, - // since we want the reference to remain after we return from this - // method. - context_ = Persistent::New(context); - - // Enter the new context so all the following operations take place - // within it. - Context::Scope context_scope(context); - - // Make the options mapping available within the context - if (!InstallMaps(opts, output)) - return false; - - // Compile and run the script - if (!ExecuteScript(script_)) - return false; - - // The script compiled and ran correctly. Now we fetch out the - // Process function from the global object. - Handle process_name = String::New("Process"); - Handle process_val = context->Global()->Get(process_name); - - // If there is no Process function, or if it is not a function, - // bail out - if (!process_val->IsFunction()) return false; - - // It is a function; cast it to a Function - Handle process_fun = Handle::Cast(process_val); - - // Store the function in a Persistent handle, since we also want - // that to remain after this call returns - process_ = Persistent::New(process_fun); - - // All done; all went well - return true; -} - - -bool JsHttpRequestProcessor::ExecuteScript - ( Handle script - ) -{ - HandleScope handle_scope; - - // We're just about to compile the script; set up an error handler to - // catch any exceptions the script might throw. - TryCatch try_catch; - - // Compile the script and check for errors. - Handle