#include #include "node_tcp.h" #include "node_http.h" #include "node_timer.h" #include #include #include #include #include #include using namespace v8; using namespace std; static struct ev_loop *loop; static Persistent context; static Persistent process_; // Reads a file into a v8 string. static Handle ReadFile ( const string& name ) { FILE* file = fopen(name.c_str(), "rb"); if (file == NULL) return Handle(); fseek(file, 0, SEEK_END); int size = ftell(file); rewind(file); char* chars = new char[size + 1]; chars[size] = '\0'; for (int i = 0; i < size;) { int read = fread(&chars[i], 1, size - i, file); i += read; } fclose(file); Handle result = String::New(chars, size); delete[] chars; return result; } static void ParseOptions ( int argc , char* argv[] , map& options , string* file ) { for (int i = 1; i < argc; i++) { string arg = argv[i]; int index = arg.find('=', 0); if (index == string::npos) { *file = arg; } else { string key = arg.substr(0, index); string value = arg.substr(index+1); options[key] = value; } } } static bool compile ( 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