Create a node namespace
authorRyan <ry@tinyclouds.org>
Tue, 28 Apr 2009 21:09:56 +0000 (23:09 +0200)
committerRyan <ry@tinyclouds.org>
Tue, 28 Apr 2009 21:09:56 +0000 (23:09 +0200)
Part of general reorganization.

13 files changed:
src/file.cc
src/file.h
src/http.cc
src/http.h
src/net.cc
src/net.h
src/node.cc
src/node.h
src/process.cc
src/process.h
src/timers.cc
src/timers.h
test/test-pingpong.js

index b8380d72486bb03d9e2ad8a364616d47b3c271b1..dc9c4a83b9b540b02e8fa8ca141276652a7eac45 100644 (file)
@@ -1,4 +1,5 @@
 #include "node.h"
+#include "file.h"
 #include <string.h>
 
 #include <sys/types.h>
@@ -75,7 +76,7 @@ CallTopCallback (Handle<Object> handle, const int argc, Handle<Value> argv[])
       TryCatch try_catch;
       callback->Call(handle, argc, argv);
       if(try_catch.HasCaught()) {
-        node_fatal_exception(try_catch);
+        node::fatal_exception(try_catch);
         return;
       }
     }
@@ -106,7 +107,7 @@ FileSystem::Rename (const Arguments& args)
   String::Utf8Value path(args[0]->ToString());
   String::Utf8Value new_path(args[1]->ToString());
 
-  node_eio_warmup();
+  node::eio_warmup();
   eio_req *req = eio_rename(*path, *new_path, EIO_PRI_DEFAULT, AfterRename, NULL);
 
   return Undefined();
@@ -133,7 +134,7 @@ FileSystem::Stat (const Arguments& args)
 
   String::Utf8Value path(args[0]->ToString());
 
-  node_eio_warmup();
+  node::eio_warmup();
   eio_req *req = eio_stat(*path, EIO_PRI_DEFAULT, AfterStat, NULL);
 
   return Undefined();
@@ -263,7 +264,7 @@ File::Close (const Arguments& args)
 
   int fd = file->GetFD();
 
-  node_eio_warmup();
+  node::eio_warmup();
   eio_req *req = eio_close (fd, EIO_PRI_DEFAULT, File::AfterClose, file);
 
   return Undefined();
@@ -324,7 +325,7 @@ File::Open (const Arguments& args)
   }
 
   // TODO how should the mode be set?
-  node_eio_warmup();
+  node::eio_warmup();
   eio_req *req = eio_open (*path, flags, 0666, EIO_PRI_DEFAULT, File::AfterOpen, file);
 
   return Undefined();
@@ -392,7 +393,7 @@ File::Write (const Arguments& args)
 
   int fd = file->GetFD();
 
-  node_eio_warmup();
+  node::eio_warmup();
   eio_req *req = eio_write(fd, buf, length, pos, EIO_PRI_DEFAULT, File::AfterWrite, file);
 
   return Undefined();
@@ -433,7 +434,7 @@ File::Read (const Arguments& args)
   int fd = file->GetFD();
 
   // NOTE: NULL pointer tells eio to allocate it itself
-  node_eio_warmup();
+  node::eio_warmup();
   eio_req *req = eio_read(fd, NULL, length, pos, EIO_PRI_DEFAULT, File::AfterRead, file);
   assert(req);
 
@@ -485,7 +486,7 @@ File::New(const Arguments& args)
 }
 
 void
-NodeInit_file (Handle<Object> target)
+node::Init_file (Handle<Object> target)
 {
   if (!fs.IsEmpty())
     return;
index 75fddb787169c7d4aaee760364d40a081059e1ee..5fe372bb7dab3d72ab0b02f3c539aabf92acea3e 100644 (file)
@@ -3,6 +3,9 @@
 
 #include <v8.h>
 
-void NodeInit_file (v8::Handle<v8::Object> target);
+namespace node {
 
-#endif
+void Init_file (v8::Handle<v8::Object> target);
+
+} // namespace node
+#endif // node_file_h
index 101b185c5ec614535e6e271ae7e84f68ea0cfbac..a162fa05fff0f6558a6c3dd16da5bfcbaecdab29 100644 (file)
@@ -260,7 +260,7 @@ on_headers_complete (ebb_request *req)
   Handle<Value> r = request->connection.js_onrequest->Call(Context::GetCurrent()->Global(), argc, argv);
 
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 }
 
 static void
@@ -373,7 +373,7 @@ HttpRequest::MakeBodyCallback (const char *base, size_t length)
   Handle<Value> result = onbody->Call(js_object, argc, argv);
 
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 }
 
 Local<Object>
@@ -651,7 +651,7 @@ newHTTPHttpServer (const Arguments& args)
 }
 
 void
-NodeInit_http (Handle<Object> target)
+node::Init_http (Handle<Object> target)
 {
   HandleScope scope;
 
index 83367ab4f680dbb81eb02955167253a0f2b95a50..69e5f09f6cf14e609eca46ee51fb0698ce7d469f 100644 (file)
@@ -3,6 +3,9 @@
 
 #include <v8.h>
 
-void NodeInit_http (v8::Handle<v8::Object> target);
+namespace node {
 
+void Init_http (v8::Handle<v8::Object> target);
+
+} // namespace node
 #endif
index 5f83f34f1d891b5cfb4d40162ee675ebf18047ad..6afff74189ec90e2307aade2956f30bf31da9734 100644 (file)
@@ -307,7 +307,7 @@ Socket::ConnectTCP (const Arguments& args)
    * In the future I will move to a system using adns or udns: 
    * http://lists.schmorp.de/pipermail/libev/2009q1/000632.html
    */
-  node_eio_warmup();
+  node::eio_warmup();
   eio_req *req = eio_custom (Socket::Resolve, EIO_PRI_DEFAULT, Socket::AfterResolve, socket);
 
   return Undefined();
@@ -365,7 +365,7 @@ Socket::AfterResolve (eio_req *req)
 
   onconnect->Call(socket->handle_, argc, argv);
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 
   return 0;
 }
@@ -488,7 +488,7 @@ Socket::OnConnect (oi_socket *s)
   Handle<Value> r = on_connect->Call(socket->handle_, argc, argv);
 
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 }
 
 void
@@ -527,7 +527,7 @@ Socket::OnRead (oi_socket *s, const void *buf, size_t count)
   Handle<Value> r = onread->Call(socket->handle_, argc, argv);
 
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 }
 
 void
@@ -548,7 +548,7 @@ Socket::OnClose (oi_socket *s)
   Handle<Value> r = onclose->Call(socket->handle_, 0, NULL);
 
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 
   delete socket;
 }
@@ -568,7 +568,7 @@ Socket::OnDrain (oi_socket *s)
   Handle<Value> r = ondrain->Call(socket->handle_, 0, NULL);
 
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 }
 
 
@@ -587,7 +587,7 @@ Socket::OnError (oi_socket *s, oi_error e)
   Handle<Value> r = onerror->Call(socket->handle_, 0, NULL);
 
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 }
 
 void
@@ -605,11 +605,11 @@ Socket::OnTimeout (oi_socket *s)
   Handle<Value> r = ontimeout->Call(socket->handle_, 0, NULL);
 
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 }
 
 void
-NodeInit_net (Handle<Object> target)
+node::Init_net (Handle<Object> target)
 {
   HandleScope scope;
 
index 347a3ebceb7d23f32b12f88af0b78e5fd2958d2d..9e6662f9b471f079312dea98e62d2034a32d7be3 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -3,6 +3,9 @@
 
 #include <v8.h>
 
-void NodeInit_net (v8::Handle<v8::Object> target);
+namespace node {
 
+void Init_net (v8::Handle<v8::Object> target);
+
+} // namespace node
 #endif
index 002dc71d2d6300fad220072e8534298bfa98b153..a77748928e7a77b10e3ba4d6c03cf7d49a005830 100644 (file)
@@ -75,13 +75,13 @@ ExecuteString(v8::Handle<v8::String> source,
   Handle<Script> script = Script::Compile(source, filename);
   if (script.IsEmpty()) {
     ReportException(&try_catch);
-    exit(1);
+    ::exit(1);
   }
 
   Handle<Value> result = script->Run();
   if (result.IsEmpty()) {
     ReportException(&try_catch);
-    exit(1);
+    ::exit(1);
   }
 
   return scope.Close(result);
@@ -121,19 +121,20 @@ OnFatalError (const char* location, const char* message)
   else 
     fprintf(stderr, FATAL_ERROR " %s\n", message);
 
-  exit(1);
+  ::exit(1);
 }
 
 
 void
-node_fatal_exception (TryCatch &try_catch)
+node::fatal_exception (TryCatch &try_catch)
 {
   ReportException(&try_catch);
   ev_unloop(EV_DEFAULT_UC_ EVUNLOOP_ALL);
   exit_code = 1;
 }
 
-void node_exit (int code)
+void
+node::exit (int code)
 {
   exit_code = code;
   ev_unloop(EV_DEFAULT_UC_ EVUNLOOP_ALL);
@@ -152,19 +153,19 @@ thread_pool_cb (EV_P_ ev_async *w, int revents)
   //  it require three locks in eio
   //  what's the better way?
   if (eio_nreqs () == 0 && eio_nready() == 0 && eio_npending() == 0) 
-    ev_async_stop(EV_DEFAULT_ w);
+    ev_async_stop(EV_DEFAULT_UC_ w);
 }
 
 static void
 thread_pool_want_poll (void)
 {
-  ev_async_send(EV_DEFAULT_ &thread_pool_watcher); 
+  ev_async_send(EV_DEFAULT_UC_ &thread_pool_watcher); 
 }
 
 void
-node_eio_warmup (void)
+node::eio_warmup (void)
 {
-  ev_async_start(EV_DEFAULT_ &thread_pool_watcher);
+  ev_async_start(EV_DEFAULT_UC_ &thread_pool_watcher);
 }
 
 int
@@ -207,11 +208,11 @@ main (int argc, char *argv[])
   g->Set(String::New("ARGV"), arguments);
 
   // BUILT-IN MODULES
-  NodeInit_net(g);
-  NodeInit_timers(g);
-  NodeInit_process(g);
-  NodeInit_file(g);
-  NodeInit_http(g);
+  node::Init_net(g);
+  node::Init_timers(g);
+  node::Init_process(g);
+  node::Init_file(g);
+  node::Init_http(g);
 
   // NATIVE JAVASCRIPT MODULES
   TryCatch try_catch;
index 5c30b4c90ee5f0c7188aac3fe391f4ff7f9d2dc1..b43d514d2283b9007caf5f9c20fb4725b6cff810 100644 (file)
@@ -5,18 +5,18 @@
 #include <eio.h>
 #include <v8.h>
 
+namespace node {
+
 #define NODE_SYMBOL(name) v8::String::NewSymbol(name)
 #define NODE_METHOD(name) v8::Handle<v8::Value> name (const v8::Arguments& args)
 #define NODE_SET_METHOD(obj, name, callback) \
   obj->Set(NODE_SYMBOL(name), v8::FunctionTemplate::New(callback)->GetFunction())
 
 enum encoding {UTF8, RAW};
+void fatal_exception (v8::TryCatch &try_catch); 
+void exit (int code);
+void eio_warmup (void); // call this before creating a new eio event.
 
-void node_fatal_exception (v8::TryCatch &try_catch); 
-void node_exit (int code);
-
-// call this after creating a new eio event.
-void node_eio_warmup (void);
-
+} // namespace node
 #endif // node_h
 
index db18ad29d73bff7ac6846e439ee2e2ccfb43e02b..ba0c31fb16a3e986ec2316c4efde8900570afd49 100644 (file)
@@ -21,7 +21,7 @@ OnCallback (const Arguments& args)
 }
 
 void
-NodeInit_process (Handle<Object> target)
+node::Init_process (Handle<Object> target)
 {
   HandleScope scope;
 
index b7ea663ed297e78882135868e455fde8606eb60d..4be64b516f1899fa1b37ede0a0236126b149081a 100644 (file)
@@ -3,6 +3,9 @@
 
 #include <v8.h>
 
-void NodeInit_process (v8::Handle<v8::Object> target);
+namespace node {
 
+void Init_process (v8::Handle<v8::Object> target);
+
+} // namespace node
 #endif
index a427b22f6b60871025acc0d9e11c3abec6655c39..7e23662c1d8830dd2a798755f84ced15c799ddf5 100644 (file)
@@ -48,7 +48,7 @@ Timer::OnTimeout (EV_P_ ev_timer *watcher, int revents)
   TryCatch try_catch;
   callback->Call (Context::GetCurrent()->Global(), 0, NULL);
   if(try_catch.HasCaught())
-    node_fatal_exception(try_catch);
+    node::fatal_exception(try_catch);
 
   // use ev_is_active instead?
   if(watcher->repeat == 0.) 
@@ -132,7 +132,7 @@ Timer::clearTimeout (const Arguments& args)
 }
 
 void
-NodeInit_timers (Handle<Object> target)
+node::Init_timers (Handle<Object> target)
 {
   HandleScope scope;
 
index ba0a4a495c192146430ff4c358b896e7f119253a..c63e05af45b8787c6b1f22eacccf74e2fbd5a1cd 100644 (file)
@@ -3,6 +3,9 @@
 
 #include <v8.h>
 
-void NodeInit_timers (v8::Handle<v8::Object> target);
+namespace node {
 
+void Init_timers (v8::Handle<v8::Object> target);
+
+} // namespace node 
 #endif //  node_timers_h
index 017af24058da7505c31b11ff9182ed54d0ce5832..780e5d9509695daf4813d1f60eaaa176d8dc503e 100644 (file)
@@ -1,5 +1,5 @@
 include("mjsunit");
-var N = 1000;
+var N = 100;
 function onLoad() {
   server = new Server(1024);
   var count = 0;