Part of general reorganization.
#include "node.h"
+#include "file.h"
#include <string.h>
#include <sys/types.h>
TryCatch try_catch;
callback->Call(handle, argc, argv);
if(try_catch.HasCaught()) {
- node_fatal_exception(try_catch);
+ node::fatal_exception(try_catch);
return;
}
}
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();
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();
int fd = file->GetFD();
- node_eio_warmup();
+ node::eio_warmup();
eio_req *req = eio_close (fd, EIO_PRI_DEFAULT, File::AfterClose, file);
return Undefined();
}
// 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();
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();
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);
}
void
-NodeInit_file (Handle<Object> target)
+node::Init_file (Handle<Object> target)
{
if (!fs.IsEmpty())
return;
#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
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
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>
}
void
-NodeInit_http (Handle<Object> target)
+node::Init_http (Handle<Object> target)
{
HandleScope scope;
#include <v8.h>
-void NodeInit_http (v8::Handle<v8::Object> target);
+namespace node {
+void Init_http (v8::Handle<v8::Object> target);
+
+} // namespace node
#endif
* 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();
onconnect->Call(socket->handle_, argc, argv);
if(try_catch.HasCaught())
- node_fatal_exception(try_catch);
+ node::fatal_exception(try_catch);
return 0;
}
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
Handle<Value> r = onread->Call(socket->handle_, argc, argv);
if(try_catch.HasCaught())
- node_fatal_exception(try_catch);
+ node::fatal_exception(try_catch);
}
void
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;
}
Handle<Value> r = ondrain->Call(socket->handle_, 0, NULL);
if(try_catch.HasCaught())
- node_fatal_exception(try_catch);
+ node::fatal_exception(try_catch);
}
Handle<Value> r = onerror->Call(socket->handle_, 0, NULL);
if(try_catch.HasCaught())
- node_fatal_exception(try_catch);
+ node::fatal_exception(try_catch);
}
void
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;
#include <v8.h>
-void NodeInit_net (v8::Handle<v8::Object> target);
+namespace node {
+void Init_net (v8::Handle<v8::Object> target);
+
+} // namespace node
#endif
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);
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);
// 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
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;
#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
}
void
-NodeInit_process (Handle<Object> target)
+node::Init_process (Handle<Object> target)
{
HandleScope scope;
#include <v8.h>
-void NodeInit_process (v8::Handle<v8::Object> target);
+namespace node {
+void Init_process (v8::Handle<v8::Object> target);
+
+} // namespace node
#endif
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.)
}
void
-NodeInit_timers (Handle<Object> target)
+node::Init_timers (Handle<Object> target)
{
HandleScope scope;
#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
include("mjsunit");
-var N = 1000;
+var N = 100;
function onLoad() {
server = new Server(1024);
var count = 0;