From 356992fe4ded4d48e487aa9f0826a9b9ce022bcb Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 22 Nov 2011 17:10:09 +0100 Subject: [PATCH] isolates: isolate-ify the main loop --- node.gyp | 2 ++ src/cares_wrap.cc | 8 ++--- src/fs_event_wrap.cc | 8 ++--- src/handle_wrap.cc | 3 +- src/node.cc | 37 ++++++++++++++---------- src/node.h | 3 ++ src/node_crypto.cc | 5 ++-- src/node_isolate.cc | 42 +++++++++++++++++++++++++++ src/node_isolate.h | 69 ++++++++++++++++++++++++++++++++++++++++++++ src/node_zlib.cc | 2 +- src/pipe_wrap.cc | 8 ++--- src/process_wrap.cc | 6 ++-- src/stream_wrap.cc | 14 ++++----- src/tcp_wrap.cc | 26 ++++++++--------- src/timer_wrap.cc | 18 ++++++------ src/tty_wrap.cc | 6 ++-- src/udp_wrap.cc | 16 +++++----- 17 files changed, 198 insertions(+), 75 deletions(-) create mode 100644 src/node_isolate.cc create mode 100644 src/node_isolate.h diff --git a/node.gyp b/node.gyp index bc351219964..0fff5b4e99a 100644 --- a/node.gyp +++ b/node.gyp @@ -74,6 +74,7 @@ 'src/node.cc', 'src/node_vars.cc', 'src/node_buffer.cc', + 'src/node_isolate.cc', 'src/node_constants.cc', 'src/node_extensions.cc', 'src/node_file.cc', @@ -97,6 +98,7 @@ 'src/node.h', 'src/node_vars.h', 'src/node_buffer.h', + 'src/node_isolate.h', 'src/node_constants.h', 'src/node_crypto.h', 'src/node_extensions.h', diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 89ae4581dad..976f774c9db 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -607,7 +607,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { if (status) { // Error - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); argv[0] = Local::New(Null()); } else { // Success @@ -710,7 +710,7 @@ static Handle GetAddrInfo(const Arguments& args) { hints.ai_family = fam; hints.ai_socktype = SOCK_STREAM; - int r = uv_getaddrinfo(uv_default_loop(), + int r = uv_getaddrinfo(NODE_LOOP(), &req_wrap->req_, AfterGetAddrInfo, *hostname, @@ -719,7 +719,7 @@ static Handle GetAddrInfo(const Arguments& args) { req_wrap->Dispatched(); if (r) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); delete req_wrap; return scope.Close(v8::Null()); } else { @@ -736,7 +736,7 @@ static void Initialize(Handle target) { assert(r == ARES_SUCCESS); struct ares_options options; - uv_ares_init_options(uv_default_loop(), &ares_channel, &options, 0); + uv_ares_init_options(NODE_LOOP(), &ares_channel, &options, 0); assert(r == 0); NODE_SET_METHOD(target, "queryA", Query); diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 48cdabc00e2..ca584a79388 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -109,15 +109,15 @@ Handle FSEventWrap::Start(const Arguments& args) { String::Utf8Value path(args[0]->ToString()); - int r = uv_fs_event_init(uv_default_loop(), &wrap->handle_, *path, OnEvent, 0); + int r = uv_fs_event_init(NODE_LOOP(), &wrap->handle_, *path, OnEvent, 0); if (r == 0) { // Check for persistent argument if (!args[1]->IsTrue()) { - uv_unref(uv_default_loop()); + uv_unref(NODE_LOOP()); } wrap->initialized_ = true; } else { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } return scope.Close(Integer::New(r)); @@ -145,7 +145,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, // assumption that a rename implicitly means an attribute change. Not too // unreasonable, right? Still, we should revisit this before v1.0. if (status) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); eventStr = String::Empty(); } else if (events & UV_RENAME) { diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 5b6594a3a90..bce82bdb05c 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -70,7 +70,7 @@ Handle HandleWrap::Unref(const Arguments& args) { } wrap->unref = true; - uv_unref(uv_default_loop()); + uv_unref(NODE_LOOP()); return v8::Undefined(); } @@ -102,7 +102,6 @@ Handle HandleWrap::Close(const Arguments& args) { assert(!wrap->object_.IsEmpty()); uv_close(wrap->handle__, OnClose); - HandleWrap::Ref(args); wrap->StateChange(); diff --git a/src/node.cc b/src/node.cc index f18f754cd3b..a3bc1296413 100644 --- a/src/node.cc +++ b/src/node.cc @@ -170,7 +170,7 @@ static void Idle(uv_idle_t* watcher, int status) { static void Check(uv_check_t* watcher, int status) { assert(watcher == &gc_check); - tick_times[tick_time_head] = uv_now(uv_default_loop()); + tick_times[tick_time_head] = uv_now(NODE_LOOP()); tick_time_head = (tick_time_head + 1) % RPM_SAMPLES; StartGCTimer(); @@ -200,7 +200,7 @@ static void Tick(void) { need_tick_cb = false; if (uv_is_active((uv_handle_t*) &tick_spinner)) { uv_idle_stop(&tick_spinner); - uv_unref(uv_default_loop()); + uv_unref(NODE_LOOP()); } HandleScope scope; @@ -242,7 +242,7 @@ static Handle NeedTickCallback(const Arguments& args) { // tick_spinner to keep the event loop alive long enough to handle it. if (!uv_is_active((uv_handle_t*) &tick_spinner)) { uv_idle_start(&tick_spinner, Spin); - uv_ref(uv_default_loop()); + uv_ref(NODE_LOOP()); } return Undefined(); } @@ -1494,7 +1494,7 @@ static void CheckStatus(uv_timer_t* watcher, int status) { } } - double d = uv_now(uv_default_loop()) - TICK_TIME(3); + double d = uv_now(NODE_LOOP()) - TICK_TIME(3); //printfb("timer d = %f\n", d); @@ -1523,7 +1523,7 @@ static Handle Uptime(const Arguments& args) { v8::Handle UVCounters(const v8::Arguments& args) { HandleScope scope; - uv_counters_t* c = &uv_default_loop()->counters; + uv_counters_t* c = &NODE_LOOP()->counters; Local obj = Object::New(); @@ -2566,26 +2566,29 @@ char** Init(int argc, char *argv[]) { RegisterSignalHandler(SIGTERM, SignalExit); #endif // __POSIX__ + // Don't use NODE_LOOP(), the node::Isolate() has not yet been initialized. + uv_loop_t* const loop = uv_default_loop(); + uv_prepare_init(uv_default_loop(), &prepare_tick_watcher); uv_prepare_start(&prepare_tick_watcher, PrepareTick); - uv_unref(uv_default_loop()); + uv_unref(loop); uv_check_init(uv_default_loop(), &check_tick_watcher); uv_check_start(&check_tick_watcher, node::CheckTick); - uv_unref(uv_default_loop()); + uv_unref(loop); uv_idle_init(uv_default_loop(), &tick_spinner); - uv_unref(uv_default_loop()); + uv_unref(loop); uv_check_init(uv_default_loop(), &gc_check); uv_check_start(&gc_check, node::Check); - uv_unref(uv_default_loop()); + uv_unref(loop); uv_idle_init(uv_default_loop(), &gc_idle); - uv_unref(uv_default_loop()); + uv_unref(loop); uv_timer_init(uv_default_loop(), &gc_timer); - uv_unref(uv_default_loop()); + uv_unref(loop); V8::SetFatalErrorHandler(node::OnFatalError); @@ -2598,13 +2601,13 @@ char** Init(int argc, char *argv[]) { // main thread to execute a random bit of javascript - which will give V8 // control so it can handle whatever new message had been received on the // debug thread. - uv_async_init(uv_default_loop(), &debug_watcher, node::DebugMessageCallback); + uv_async_init(loop, &debug_watcher, node::DebugMessageCallback); // unref it so that we exit the event loop despite it being active. - uv_unref(uv_default_loop()); + uv_unref(loop); // Fetch a reference to the main isolate, so we have a reference to it // even when we need it to access it from another (debugger) thread. - node_isolate = Isolate::GetCurrent(); + node_isolate = v8::Isolate::GetCurrent(); // If the --debug flag was specified then initialize the debug thread. if (use_debug_agent) { @@ -2646,7 +2649,11 @@ int Start(int argc, char *argv[]) { Persistent context = v8::Context::New(); v8::Context::Scope context_scope(context); + // Create the main node::Isolate object + Isolate::New(uv_default_loop()); + Handle process_l = SetupProcessObject(argc, argv); + v8_typed_array::AttachBindings(context->Global()); // Create all the objects, load modules, do everything. @@ -2658,7 +2665,7 @@ int Start(int argc, char *argv[]) { // there are no watchers on the loop (except for the ones that were // uv_unref'd) then this function exits. As long as there are active // watchers, it blocks. - uv_run(uv_default_loop()); + uv_run(NODE_LOOP()); EmitExit(process_l); diff --git a/src/node.h b/src/node.h index 38d3c621bfa..03ae934edf3 100644 --- a/src/node.h +++ b/src/node.h @@ -64,6 +64,7 @@ #include #include +#include #include #ifndef offset_of @@ -87,6 +88,8 @@ #define NODE_STRINGIFY_HELPER(n) #n #endif +#define NODE_LOOP() (node::Isolate::GetCurrent()->GetLoop()) + namespace node { int Start(int argc, char *argv[]); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index eb040ebc8c8..70ae99d1fbd 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -4117,7 +4117,8 @@ PBKDF2(const Arguments& args) { req = new uv_work_t(); req->data = request; - uv_queue_work(uv_default_loop(), req, EIO_PBKDF2, EIO_PBKDF2After); + uv_queue_work(NODE_LOOP(), req, EIO_PBKDF2, EIO_PBKDF2After); + return Undefined(); err: @@ -4239,7 +4240,7 @@ Handle RandomBytes(const Arguments& args) { Local callback_v = Local(Function::Cast(*args[1])); req->callback_ = Persistent::New(callback_v); - uv_queue_work(uv_default_loop(), + uv_queue_work(NODE_LOOP(), &req->work_req_, RandomBytesWork, RandomBytesAfter); diff --git a/src/node_isolate.cc b/src/node_isolate.cc new file mode 100644 index 00000000000..af2f83fa8e6 --- /dev/null +++ b/src/node_isolate.cc @@ -0,0 +1,42 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +#include "node_isolate.h" +#include + + +namespace node { + + +Isolate* Isolate::New(uv_loop_t* loop) { + return new Isolate(loop); +} + + +Isolate::Isolate(uv_loop_t* loop) { + loop_ = loop; + isolate_ = v8::Isolate::GetCurrent(); + assert(isolate_->GetData() == NULL); + isolate_->SetData(this); +} + + +} // namespace node diff --git a/src/node_isolate.h b/src/node_isolate.h new file mode 100644 index 00000000000..df74a5f01d2 --- /dev/null +++ b/src/node_isolate.h @@ -0,0 +1,69 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +#ifndef SRC_NODE_ISOLATE_H_ +#define SRC_NODE_ISOLATE_H_ + +#include +#include + +#ifdef NDEBUG +# define NODE_ISOLATE_CHECK(ptr) ((void) (ptr)) +#else +# include +# define NODE_ISOLATE_CHECK(ptr) \ + do { \ + node::Isolate* data_ = node::Isolate::GetCurrent(); \ + assert(data_ == (ptr)); \ + } \ + while (0) +#endif + + +namespace node { + +class Isolate { +public: + static Isolate* New(uv_loop_t* loop); + + static Isolate* GetCurrent() { + return reinterpret_cast(v8::Isolate::GetCurrent()->GetData()); + } + + uv_loop_t* GetLoop() { + NODE_ISOLATE_CHECK(this); + return loop_; + } + + operator v8::Isolate*() { + NODE_ISOLATE_CHECK(this); + return isolate_; + } + +private: + Isolate(uv_loop_t* loop); + v8::Isolate* isolate_; + uv_loop_t* loop_; +}; + +} // namespace node + +#endif // SRC_NODE_ISOLATE_H_ diff --git a/src/node_zlib.cc b/src/node_zlib.cc index e16092f9285..dc0bc4691c5 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -133,7 +133,7 @@ template class ZCtx : public ObjectWrap { uv_work_t* work_req = new uv_work_t(); work_req->data = req_wrap; - uv_queue_work(uv_default_loop(), + uv_queue_work(NODE_LOOP(), work_req, ZCtx::Process, ZCtx::After); diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index 1870837bcae..9f667511508 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -123,7 +123,7 @@ Handle PipeWrap::New(const Arguments& args) { PipeWrap::PipeWrap(Handle object, bool ipc) : StreamWrap(object, (uv_stream_t*) &handle_) { - int r = uv_pipe_init(uv_default_loop(), &handle_, ipc); + int r = uv_pipe_init(NODE_LOOP(), &handle_, ipc); assert(r == 0); // How do we proxy this error up to javascript? // Suggestion: uv_pipe_init() returns void. handle_.data = reinterpret_cast(this); @@ -141,7 +141,7 @@ Handle PipeWrap::Bind(const Arguments& args) { int r = uv_pipe_bind(&wrap->handle_, *name); // Error starting the pipe. - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -172,7 +172,7 @@ Handle PipeWrap::Listen(const Arguments& args) { int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection); // Error starting the pipe. - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -225,7 +225,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) { assert(wrap->object_.IsEmpty() == false); if (status) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } Local argv[3] = { diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 7a6a8518a2d..50c88a9db13 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -175,7 +175,7 @@ class ProcessWrap : public HandleWrap { Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue(); #endif - int r = uv_spawn(uv_default_loop(), &wrap->process_, options); + int r = uv_spawn(NODE_LOOP(), &wrap->process_, options); wrap->SetHandle((uv_handle_t*)&wrap->process_); assert(wrap->process_.data == wrap); @@ -195,7 +195,7 @@ class ProcessWrap : public HandleWrap { delete [] options.env; } - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -209,7 +209,7 @@ class ProcessWrap : public HandleWrap { int r = uv_process_kill(&wrap->process_, signal); - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 7193f77c126..2e143284720 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -132,7 +132,7 @@ Handle StreamWrap::ReadStart(const Arguments& args) { } // Error starting the tcp. - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -146,7 +146,7 @@ Handle StreamWrap::ReadStop(const Arguments& args) { int r = uv_read_stop(wrap->stream_); // Error starting the tcp. - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -225,7 +225,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread, slab_used -= buf.len; } - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); MakeCallback(wrap->object_, "onread", 0, NULL); return; } @@ -338,7 +338,7 @@ Handle StreamWrap::Write(const Arguments& args) { wrap->UpdateWriteQueueSize(); if (r) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); delete req_wrap; return scope.Close(v8::Null()); } else { @@ -358,7 +358,7 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) { assert(wrap->object_.IsEmpty() == false); if (status) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } wrap->UpdateWriteQueueSize(); @@ -388,7 +388,7 @@ Handle StreamWrap::Shutdown(const Arguments& args) { req_wrap->Dispatched(); if (r) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); delete req_wrap; return scope.Close(v8::Null()); } else { @@ -408,7 +408,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) { HandleScope scope; if (status) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } Local argv[3] = { diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 9ac6aedfa3d..2197850d16e 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -154,7 +154,7 @@ Handle TCPWrap::New(const Arguments& args) { TCPWrap::TCPWrap(Handle object) : StreamWrap(object, (uv_stream_t*) &handle_) { - int r = uv_tcp_init(uv_default_loop(), &handle_); + int r = uv_tcp_init(NODE_LOOP(), &handle_); assert(r == 0); // How do we proxy this error up to javascript? // Suggestion: uv_tcp_init() returns void. UpdateWriteQueueSize(); @@ -182,7 +182,7 @@ Handle TCPWrap::GetSockName(const Arguments& args) { Local sockname = Object::New(); if (r != 0) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } else { family = address.ss_family; @@ -224,7 +224,7 @@ Handle TCPWrap::GetPeerName(const Arguments& args) { Local sockname = Object::New(); if (r != 0) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } else { family = address.ss_family; @@ -257,7 +257,7 @@ Handle TCPWrap::SetNoDelay(const Arguments& args) { int r = uv_tcp_nodelay(&wrap->handle_, 1); if (r) - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); return Undefined(); } @@ -273,7 +273,7 @@ Handle TCPWrap::SetKeepAlive(const Arguments& args) { int r = uv_tcp_keepalive(&wrap->handle_, enable, delay); if (r) - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); return Undefined(); } @@ -289,7 +289,7 @@ Handle TCPWrap::SetSimultaneousAccepts(const Arguments& args) { int r = uv_tcp_simultaneous_accepts(&wrap->handle_, enable ? 1 : 0); if (r) - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); return Undefined(); } @@ -308,7 +308,7 @@ Handle TCPWrap::Bind(const Arguments& args) { int r = uv_tcp_bind(&wrap->handle_, address); // Error starting the tcp. - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -326,7 +326,7 @@ Handle TCPWrap::Bind6(const Arguments& args) { int r = uv_tcp_bind6(&wrap->handle_, address); // Error starting the tcp. - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -342,7 +342,7 @@ Handle TCPWrap::Listen(const Arguments& args) { int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection); // Error starting the tcp. - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -377,7 +377,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) { // Successful accept. Call the onconnection callback in JavaScript land. argv[0] = client_obj; } else { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); argv[0] = v8::Null(); } @@ -396,7 +396,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) { assert(wrap->object_.IsEmpty() == false); if (status) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } Local argv[3] = { @@ -432,7 +432,7 @@ Handle TCPWrap::Connect(const Arguments& args) { req_wrap->Dispatched(); if (r) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); delete req_wrap; return scope.Close(v8::Null()); } else { @@ -459,7 +459,7 @@ Handle TCPWrap::Connect6(const Arguments& args) { req_wrap->Dispatched(); if (r) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); delete req_wrap; return scope.Close(v8::Null()); } else { diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 470c2d6b98d..fb860369238 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -91,7 +91,7 @@ class TimerWrap : public HandleWrap { : HandleWrap(object, (uv_handle_t*) &handle_) { active_ = false; - int r = uv_timer_init(uv_default_loop(), &handle_); + int r = uv_timer_init(NODE_LOOP(), &handle_); assert(r == 0); handle_.data = this; @@ -99,11 +99,11 @@ class TimerWrap : public HandleWrap { // uv_timer_init adds a loop reference. (That is, it calls uv_ref.) This // is not the behavior we want in Node. Timers should not increase the // ref count of the loop except when active. - uv_unref(uv_default_loop()); + uv_unref(NODE_LOOP()); } ~TimerWrap() { - if (!active_) uv_ref(uv_default_loop()); + if (!active_) uv_ref(NODE_LOOP()); } void StateChange() { @@ -113,11 +113,11 @@ class TimerWrap : public HandleWrap { if (!was_active && active_) { // If our state is changing from inactive to active, we // increase the loop's reference count. - uv_ref(uv_default_loop()); + uv_ref(NODE_LOOP()); } else if (was_active && !active_) { // If our state is changing from active to inactive, we // decrease the loop's reference count. - uv_unref(uv_default_loop()); + uv_unref(NODE_LOOP()); } } @@ -132,7 +132,7 @@ class TimerWrap : public HandleWrap { int r = uv_timer_start(&wrap->handle_, OnTimeout, timeout, repeat); // Error starting the timer. - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); wrap->StateChange(); @@ -146,7 +146,7 @@ class TimerWrap : public HandleWrap { int r = uv_timer_stop(&wrap->handle_); - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); wrap->StateChange(); @@ -160,7 +160,7 @@ class TimerWrap : public HandleWrap { int r = uv_timer_again(&wrap->handle_); - if (r) SetErrno(uv_last_error(uv_default_loop())); + if (r) SetErrno(uv_last_error(NODE_LOOP())); wrap->StateChange(); @@ -186,7 +186,7 @@ class TimerWrap : public HandleWrap { int64_t repeat = uv_timer_get_repeat(&wrap->handle_); - if (repeat < 0) SetErrno(uv_last_error(uv_default_loop())); + if (repeat < 0) SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(repeat)); } diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 486c2a70b4b..b3ed49fa84b 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -124,7 +124,7 @@ class TTYWrap : StreamWrap { int r = uv_tty_get_winsize(&wrap->handle_, &width, &height); if (r) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); return v8::Undefined(); } @@ -143,7 +143,7 @@ class TTYWrap : StreamWrap { int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue()); if (r) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } return scope.Close(Integer::New(r)); @@ -169,7 +169,7 @@ class TTYWrap : StreamWrap { TTYWrap(Handle object, int fd, bool readable) : StreamWrap(object, (uv_stream_t*)&handle_) { - uv_tty_init(uv_default_loop(), &handle_, fd, readable); + uv_tty_init(NODE_LOOP(), &handle_, fd, readable); } uv_tty_t handle_; diff --git a/src/udp_wrap.cc b/src/udp_wrap.cc index cd4c58ecabd..81405f4f698 100644 --- a/src/udp_wrap.cc +++ b/src/udp_wrap.cc @@ -103,7 +103,7 @@ private: UDPWrap::UDPWrap(Handle object): HandleWrap(object, (uv_handle_t*)&handle_) { - int r = uv_udp_init(uv_default_loop(), &handle_); + int r = uv_udp_init(NODE_LOOP(), &handle_); assert(r == 0); // can't fail anyway handle_.data = reinterpret_cast(this); } @@ -176,7 +176,7 @@ Handle UDPWrap::DoBind(const Arguments& args, int family) { } if (r) - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); return scope.Close(Integer::New(r)); } @@ -233,7 +233,7 @@ Handle UDPWrap::DoSend(const Arguments& args, int family) { req_wrap->Dispatched(); if (r) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); delete req_wrap; return Null(); } @@ -260,8 +260,8 @@ Handle UDPWrap::RecvStart(const Arguments& args) { // UV_EALREADY means that the socket is already bound but that's okay int r = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv); - if (r && uv_last_error(uv_default_loop()).code != UV_EALREADY) { - SetErrno(uv_last_error(uv_default_loop())); + if (r && uv_last_error(NODE_LOOP()).code != UV_EALREADY) { + SetErrno(uv_last_error(NODE_LOOP())); return False(); } @@ -297,7 +297,7 @@ Handle UDPWrap::GetSockName(const Arguments& args) { return scope.Close(sockname); } else { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); return Null(); } } @@ -316,7 +316,7 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) { assert(wrap->object_.IsEmpty() == false); if (status) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } Local argv[4] = { @@ -364,7 +364,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle, }; if (nread == -1) { - SetErrno(uv_last_error(uv_default_loop())); + SetErrno(uv_last_error(NODE_LOOP())); } else { Local rinfo = Object::New();