Permalink
Browse files

Create a node namespace

Part of general reorganization.
  • Loading branch information...
1 parent 90fc8d3 commit cf1c58063e1ba07efcfc304a1f8372380b62cf95 @ry ry committed Apr 28, 2009
Showing with 67 additions and 50 deletions.
  1. +9 −8 src/file.cc
  2. +5 −2 src/file.h
  3. +3 −3 src/http.cc
  4. +4 −1 src/http.h
  5. +9 −9 src/net.cc
  6. +4 −1 src/net.h
  7. +15 −14 src/node.cc
  8. +6 −6 src/node.h
  9. +1 −1 src/process.cc
  10. +4 −1 src/process.h
  11. +2 −2 src/timers.cc
  12. +4 −1 src/timers.h
  13. +1 −1 test/test-pingpong.js
View
17 src/file.cc
@@ -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;
View
7 src/file.h
@@ -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
View
6 src/http.cc
@@ -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;
View
5 src/http.h
@@ -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
View
18 src/net.cc
@@ -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;
View
5 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
View
29 src/node.cc
@@ -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;
View
12 src/node.h
@@ -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
View
2 src/process.cc
@@ -21,7 +21,7 @@ OnCallback (const Arguments& args)
}
void
-NodeInit_process (Handle<Object> target)
+node::Init_process (Handle<Object> target)
{
HandleScope scope;
View
5 src/process.h
@@ -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
View
4 src/timers.cc
@@ -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;
View
5 src/timers.h
@@ -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
View
2 test/test-pingpong.js
@@ -1,5 +1,5 @@
include("mjsunit");
-var N = 1000;
+var N = 100;
function onLoad() {
server = new Server(1024);
var count = 0;

0 comments on commit cf1c580

Please sign in to comment.