Browse Source

isolates: isolate-ify the main loop

v0.7.4-release
Ben Noordhuis 13 years ago
committed by Ryan Dahl
parent
commit
c3346f6760
  1. 2
      node.gyp
  2. 8
      src/cares_wrap.cc
  3. 8
      src/fs_event_wrap.cc
  4. 3
      src/handle_wrap.cc
  5. 37
      src/node.cc
  6. 3
      src/node.h
  7. 5
      src/node_crypto.cc
  8. 42
      src/node_isolate.cc
  9. 69
      src/node_isolate.h
  10. 2
      src/node_zlib.cc
  11. 8
      src/pipe_wrap.cc
  12. 6
      src/process_wrap.cc
  13. 14
      src/stream_wrap.cc
  14. 26
      src/tcp_wrap.cc
  15. 18
      src/timer_wrap.cc
  16. 6
      src/tty_wrap.cc
  17. 16
      src/udp_wrap.cc

2
node.gyp

@ -74,6 +74,7 @@
'src/node.cc', 'src/node.cc',
'src/node_vars.cc', 'src/node_vars.cc',
'src/node_buffer.cc', 'src/node_buffer.cc',
'src/node_isolate.cc',
'src/node_constants.cc', 'src/node_constants.cc',
'src/node_extensions.cc', 'src/node_extensions.cc',
'src/node_file.cc', 'src/node_file.cc',
@ -97,6 +98,7 @@
'src/node.h', 'src/node.h',
'src/node_vars.h', 'src/node_vars.h',
'src/node_buffer.h', 'src/node_buffer.h',
'src/node_isolate.h',
'src/node_constants.h', 'src/node_constants.h',
'src/node_crypto.h', 'src/node_crypto.h',
'src/node_extensions.h', 'src/node_extensions.h',

8
src/cares_wrap.cc

@ -607,7 +607,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
if (status) { if (status) {
// Error // Error
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
argv[0] = Local<Value>::New(Null()); argv[0] = Local<Value>::New(Null());
} else { } else {
// Success // Success
@ -710,7 +710,7 @@ static Handle<Value> GetAddrInfo(const Arguments& args) {
hints.ai_family = fam; hints.ai_family = fam;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
int r = uv_getaddrinfo(uv_default_loop(), int r = uv_getaddrinfo(NODE_LOOP(),
&req_wrap->req_, &req_wrap->req_,
AfterGetAddrInfo, AfterGetAddrInfo,
*hostname, *hostname,
@ -719,7 +719,7 @@ static Handle<Value> GetAddrInfo(const Arguments& args) {
req_wrap->Dispatched(); req_wrap->Dispatched();
if (r) { if (r) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap; delete req_wrap;
return scope.Close(v8::Null()); return scope.Close(v8::Null());
} else { } else {
@ -736,7 +736,7 @@ static void Initialize(Handle<Object> target) {
assert(r == ARES_SUCCESS); assert(r == ARES_SUCCESS);
struct ares_options options; 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); assert(r == 0);
NODE_SET_METHOD(target, "queryA", Query<QueryAWrap>); NODE_SET_METHOD(target, "queryA", Query<QueryAWrap>);

8
src/fs_event_wrap.cc

@ -109,15 +109,15 @@ Handle<Value> FSEventWrap::Start(const Arguments& args) {
String::Utf8Value path(args[0]->ToString()); 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) { if (r == 0) {
// Check for persistent argument // Check for persistent argument
if (!args[1]->IsTrue()) { if (!args[1]->IsTrue()) {
uv_unref(uv_default_loop()); uv_unref(NODE_LOOP());
} }
wrap->initialized_ = true; wrap->initialized_ = true;
} else { } else {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} }
return scope.Close(Integer::New(r)); 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 // assumption that a rename implicitly means an attribute change. Not too
// unreasonable, right? Still, we should revisit this before v1.0. // unreasonable, right? Still, we should revisit this before v1.0.
if (status) { if (status) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
eventStr = String::Empty(); eventStr = String::Empty();
} }
else if (events & UV_RENAME) { else if (events & UV_RENAME) {

3
src/handle_wrap.cc

@ -70,7 +70,7 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) {
} }
wrap->unref = true; wrap->unref = true;
uv_unref(uv_default_loop()); uv_unref(NODE_LOOP());
return v8::Undefined(); return v8::Undefined();
} }
@ -102,7 +102,6 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {
assert(!wrap->object_.IsEmpty()); assert(!wrap->object_.IsEmpty());
uv_close(wrap->handle__, OnClose); uv_close(wrap->handle__, OnClose);
HandleWrap::Ref(args); HandleWrap::Ref(args);
wrap->StateChange(); wrap->StateChange();

37
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) { static void Check(uv_check_t* watcher, int status) {
assert(watcher == &gc_check); 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; tick_time_head = (tick_time_head + 1) % RPM_SAMPLES;
StartGCTimer(); StartGCTimer();
@ -200,7 +200,7 @@ static void Tick(void) {
need_tick_cb = false; need_tick_cb = false;
if (uv_is_active((uv_handle_t*) &tick_spinner)) { if (uv_is_active((uv_handle_t*) &tick_spinner)) {
uv_idle_stop(&tick_spinner); uv_idle_stop(&tick_spinner);
uv_unref(uv_default_loop()); uv_unref(NODE_LOOP());
} }
HandleScope scope; HandleScope scope;
@ -242,7 +242,7 @@ static Handle<Value> NeedTickCallback(const Arguments& args) {
// tick_spinner to keep the event loop alive long enough to handle it. // tick_spinner to keep the event loop alive long enough to handle it.
if (!uv_is_active((uv_handle_t*) &tick_spinner)) { if (!uv_is_active((uv_handle_t*) &tick_spinner)) {
uv_idle_start(&tick_spinner, Spin); uv_idle_start(&tick_spinner, Spin);
uv_ref(uv_default_loop()); uv_ref(NODE_LOOP());
} }
return Undefined(); 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); //printfb("timer d = %f\n", d);
@ -1523,7 +1523,7 @@ static Handle<Value> Uptime(const Arguments& args) {
v8::Handle<v8::Value> UVCounters(const v8::Arguments& args) { v8::Handle<v8::Value> UVCounters(const v8::Arguments& args) {
HandleScope scope; HandleScope scope;
uv_counters_t* c = &uv_default_loop()->counters; uv_counters_t* c = &NODE_LOOP()->counters;
Local<Object> obj = Object::New(); Local<Object> obj = Object::New();
@ -2566,26 +2566,29 @@ char** Init(int argc, char *argv[]) {
RegisterSignalHandler(SIGTERM, SignalExit); RegisterSignalHandler(SIGTERM, SignalExit);
#endif // __POSIX__ #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_init(uv_default_loop(), &prepare_tick_watcher);
uv_prepare_start(&prepare_tick_watcher, PrepareTick); 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_init(uv_default_loop(), &check_tick_watcher);
uv_check_start(&check_tick_watcher, node::CheckTick); 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_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_init(uv_default_loop(), &gc_check);
uv_check_start(&gc_check, node::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_idle_init(uv_default_loop(), &gc_idle);
uv_unref(uv_default_loop()); uv_unref(loop);
uv_timer_init(uv_default_loop(), &gc_timer); uv_timer_init(uv_default_loop(), &gc_timer);
uv_unref(uv_default_loop()); uv_unref(loop);
V8::SetFatalErrorHandler(node::OnFatalError); 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 // 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 // control so it can handle whatever new message had been received on the
// debug thread. // 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. // 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 // 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. // 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 the --debug flag was specified then initialize the debug thread.
if (use_debug_agent) { if (use_debug_agent) {
@ -2646,7 +2649,11 @@ int Start(int argc, char *argv[]) {
Persistent<v8::Context> context = v8::Context::New(); Persistent<v8::Context> context = v8::Context::New();
v8::Context::Scope context_scope(context); v8::Context::Scope context_scope(context);
// Create the main node::Isolate object
Isolate::New(uv_default_loop());
Handle<Object> process_l = SetupProcessObject(argc, argv); Handle<Object> process_l = SetupProcessObject(argc, argv);
v8_typed_array::AttachBindings(context->Global()); v8_typed_array::AttachBindings(context->Global());
// Create all the objects, load modules, do everything. // 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 // 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 // uv_unref'd) then this function exits. As long as there are active
// watchers, it blocks. // watchers, it blocks.
uv_run(uv_default_loop()); uv_run(NODE_LOOP());
EmitExit(process_l); EmitExit(process_l);

3
src/node.h

@ -64,6 +64,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <assert.h> #include <assert.h>
#include <node_isolate.h>
#include <node_object_wrap.h> #include <node_object_wrap.h>
#ifndef offset_of #ifndef offset_of
@ -87,6 +88,8 @@
#define NODE_STRINGIFY_HELPER(n) #n #define NODE_STRINGIFY_HELPER(n) #n
#endif #endif
#define NODE_LOOP() (node::Isolate::GetCurrent()->GetLoop())
namespace node { namespace node {
int Start(int argc, char *argv[]); int Start(int argc, char *argv[]);

5
src/node_crypto.cc

@ -4117,7 +4117,8 @@ PBKDF2(const Arguments& args) {
req = new uv_work_t(); req = new uv_work_t();
req->data = request; 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(); return Undefined();
err: err:
@ -4239,7 +4240,7 @@ Handle<Value> RandomBytes(const Arguments& args) {
Local<Function> callback_v = Local<Function>(Function::Cast(*args[1])); Local<Function> callback_v = Local<Function>(Function::Cast(*args[1]));
req->callback_ = Persistent<Function>::New(callback_v); req->callback_ = Persistent<Function>::New(callback_v);
uv_queue_work(uv_default_loop(), uv_queue_work(NODE_LOOP(),
&req->work_req_, &req->work_req_,
RandomBytesWork<generator>, RandomBytesWork<generator>,
RandomBytesAfter<generator>); RandomBytesAfter<generator>);

42
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 <assert.h>
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

69
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 <v8.h>
#include <uv.h>
#ifdef NDEBUG
# define NODE_ISOLATE_CHECK(ptr) ((void) (ptr))
#else
# include <assert.h>
# 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<Isolate*>(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_

2
src/node_zlib.cc

@ -133,7 +133,7 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
uv_work_t* work_req = new uv_work_t(); uv_work_t* work_req = new uv_work_t();
work_req->data = req_wrap; work_req->data = req_wrap;
uv_queue_work(uv_default_loop(), uv_queue_work(NODE_LOOP(),
work_req, work_req,
ZCtx<mode>::Process, ZCtx<mode>::Process,
ZCtx<mode>::After); ZCtx<mode>::After);

8
src/pipe_wrap.cc

@ -123,7 +123,7 @@ Handle<Value> PipeWrap::New(const Arguments& args) {
PipeWrap::PipeWrap(Handle<Object> object, bool ipc) PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
: StreamWrap(object, (uv_stream_t*) &handle_) { : 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? assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_pipe_init() returns void. // Suggestion: uv_pipe_init() returns void.
handle_.data = reinterpret_cast<void*>(this); handle_.data = reinterpret_cast<void*>(this);
@ -141,7 +141,7 @@ Handle<Value> PipeWrap::Bind(const Arguments& args) {
int r = uv_pipe_bind(&wrap->handle_, *name); int r = uv_pipe_bind(&wrap->handle_, *name);
// Error starting the pipe. // 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)); return scope.Close(Integer::New(r));
} }
@ -172,7 +172,7 @@ Handle<Value> PipeWrap::Listen(const Arguments& args) {
int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection); int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection);
// Error starting the pipe. // 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)); return scope.Close(Integer::New(r));
} }
@ -225,7 +225,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
assert(wrap->object_.IsEmpty() == false); assert(wrap->object_.IsEmpty() == false);
if (status) { if (status) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} }
Local<Value> argv[3] = { Local<Value> argv[3] = {

6
src/process_wrap.cc

@ -175,7 +175,7 @@ class ProcessWrap : public HandleWrap {
Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue(); Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue();
#endif #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_); wrap->SetHandle((uv_handle_t*)&wrap->process_);
assert(wrap->process_.data == wrap); assert(wrap->process_.data == wrap);
@ -195,7 +195,7 @@ class ProcessWrap : public HandleWrap {
delete [] options.env; 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)); return scope.Close(Integer::New(r));
} }
@ -209,7 +209,7 @@ class ProcessWrap : public HandleWrap {
int r = uv_process_kill(&wrap->process_, signal); 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)); return scope.Close(Integer::New(r));
} }

14
src/stream_wrap.cc

@ -132,7 +132,7 @@ Handle<Value> StreamWrap::ReadStart(const Arguments& args) {
} }
// Error starting the tcp. // 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)); return scope.Close(Integer::New(r));
} }
@ -146,7 +146,7 @@ Handle<Value> StreamWrap::ReadStop(const Arguments& args) {
int r = uv_read_stop(wrap->stream_); int r = uv_read_stop(wrap->stream_);
// Error starting the tcp. // 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)); return scope.Close(Integer::New(r));
} }
@ -225,7 +225,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread,
slab_used -= buf.len; slab_used -= buf.len;
} }
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
MakeCallback(wrap->object_, "onread", 0, NULL); MakeCallback(wrap->object_, "onread", 0, NULL);
return; return;
} }
@ -338,7 +338,7 @@ Handle<Value> StreamWrap::Write(const Arguments& args) {
wrap->UpdateWriteQueueSize(); wrap->UpdateWriteQueueSize();
if (r) { if (r) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap; delete req_wrap;
return scope.Close(v8::Null()); return scope.Close(v8::Null());
} else { } else {
@ -358,7 +358,7 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
assert(wrap->object_.IsEmpty() == false); assert(wrap->object_.IsEmpty() == false);
if (status) { if (status) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} }
wrap->UpdateWriteQueueSize(); wrap->UpdateWriteQueueSize();
@ -388,7 +388,7 @@ Handle<Value> StreamWrap::Shutdown(const Arguments& args) {
req_wrap->Dispatched(); req_wrap->Dispatched();
if (r) { if (r) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap; delete req_wrap;
return scope.Close(v8::Null()); return scope.Close(v8::Null());
} else { } else {
@ -408,7 +408,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
HandleScope scope; HandleScope scope;
if (status) { if (status) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} }
Local<Value> argv[3] = { Local<Value> argv[3] = {

26
src/tcp_wrap.cc

@ -154,7 +154,7 @@ Handle<Value> TCPWrap::New(const Arguments& args) {
TCPWrap::TCPWrap(Handle<Object> object) TCPWrap::TCPWrap(Handle<Object> object)
: StreamWrap(object, (uv_stream_t*) &handle_) { : 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? assert(r == 0); // How do we proxy this error up to javascript?
// Suggestion: uv_tcp_init() returns void. // Suggestion: uv_tcp_init() returns void.
UpdateWriteQueueSize(); UpdateWriteQueueSize();
@ -182,7 +182,7 @@ Handle<Value> TCPWrap::GetSockName(const Arguments& args) {
Local<Object> sockname = Object::New(); Local<Object> sockname = Object::New();
if (r != 0) { if (r != 0) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} else { } else {
family = address.ss_family; family = address.ss_family;
@ -224,7 +224,7 @@ Handle<Value> TCPWrap::GetPeerName(const Arguments& args) {
Local<Object> sockname = Object::New(); Local<Object> sockname = Object::New();
if (r != 0) { if (r != 0) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} else { } else {
family = address.ss_family; family = address.ss_family;
@ -257,7 +257,7 @@ Handle<Value> TCPWrap::SetNoDelay(const Arguments& args) {
int r = uv_tcp_nodelay(&wrap->handle_, 1); int r = uv_tcp_nodelay(&wrap->handle_, 1);
if (r) if (r)
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
return Undefined(); return Undefined();
} }
@ -273,7 +273,7 @@ Handle<Value> TCPWrap::SetKeepAlive(const Arguments& args) {
int r = uv_tcp_keepalive(&wrap->handle_, enable, delay); int r = uv_tcp_keepalive(&wrap->handle_, enable, delay);
if (r) if (r)
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
return Undefined(); return Undefined();
} }
@ -289,7 +289,7 @@ Handle<Value> TCPWrap::SetSimultaneousAccepts(const Arguments& args) {
int r = uv_tcp_simultaneous_accepts(&wrap->handle_, enable ? 1 : 0); int r = uv_tcp_simultaneous_accepts(&wrap->handle_, enable ? 1 : 0);
if (r) if (r)
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
return Undefined(); return Undefined();
} }
@ -308,7 +308,7 @@ Handle<Value> TCPWrap::Bind(const Arguments& args) {
int r = uv_tcp_bind(&wrap->handle_, address); int r = uv_tcp_bind(&wrap->handle_, address);
// Error starting the tcp. // 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)); return scope.Close(Integer::New(r));
} }
@ -326,7 +326,7 @@ Handle<Value> TCPWrap::Bind6(const Arguments& args) {
int r = uv_tcp_bind6(&wrap->handle_, address); int r = uv_tcp_bind6(&wrap->handle_, address);
// Error starting the tcp. // 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)); return scope.Close(Integer::New(r));
} }
@ -342,7 +342,7 @@ Handle<Value> TCPWrap::Listen(const Arguments& args) {
int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection); int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection);
// Error starting the tcp. // 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)); 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. // Successful accept. Call the onconnection callback in JavaScript land.
argv[0] = client_obj; argv[0] = client_obj;
} else { } else {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
argv[0] = v8::Null(); argv[0] = v8::Null();
} }
@ -396,7 +396,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
assert(wrap->object_.IsEmpty() == false); assert(wrap->object_.IsEmpty() == false);
if (status) { if (status) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} }
Local<Value> argv[3] = { Local<Value> argv[3] = {
@ -432,7 +432,7 @@ Handle<Value> TCPWrap::Connect(const Arguments& args) {
req_wrap->Dispatched(); req_wrap->Dispatched();
if (r) { if (r) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap; delete req_wrap;
return scope.Close(v8::Null()); return scope.Close(v8::Null());
} else { } else {
@ -459,7 +459,7 @@ Handle<Value> TCPWrap::Connect6(const Arguments& args) {
req_wrap->Dispatched(); req_wrap->Dispatched();
if (r) { if (r) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap; delete req_wrap;
return scope.Close(v8::Null()); return scope.Close(v8::Null());
} else { } else {

18
src/timer_wrap.cc

@ -91,7 +91,7 @@ class TimerWrap : public HandleWrap {
: HandleWrap(object, (uv_handle_t*) &handle_) { : HandleWrap(object, (uv_handle_t*) &handle_) {
active_ = false; active_ = false;
int r = uv_timer_init(uv_default_loop(), &handle_); int r = uv_timer_init(NODE_LOOP(), &handle_);
assert(r == 0); assert(r == 0);
handle_.data = this; 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 // 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 // is not the behavior we want in Node. Timers should not increase the
// ref count of the loop except when active. // ref count of the loop except when active.
uv_unref(uv_default_loop()); uv_unref(NODE_LOOP());
} }
~TimerWrap() { ~TimerWrap() {
if (!active_) uv_ref(uv_default_loop()); if (!active_) uv_ref(NODE_LOOP());
} }
void StateChange() { void StateChange() {
@ -113,11 +113,11 @@ class TimerWrap : public HandleWrap {
if (!was_active && active_) { if (!was_active && active_) {
// If our state is changing from inactive to active, we // If our state is changing from inactive to active, we
// increase the loop's reference count. // increase the loop's reference count.
uv_ref(uv_default_loop()); uv_ref(NODE_LOOP());
} else if (was_active && !active_) { } else if (was_active && !active_) {
// If our state is changing from active to inactive, we // If our state is changing from active to inactive, we
// decrease the loop's reference count. // 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); int r = uv_timer_start(&wrap->handle_, OnTimeout, timeout, repeat);
// Error starting the timer. // Error starting the timer.
if (r) SetErrno(uv_last_error(uv_default_loop())); if (r) SetErrno(uv_last_error(NODE_LOOP()));
wrap->StateChange(); wrap->StateChange();
@ -146,7 +146,7 @@ class TimerWrap : public HandleWrap {
int r = uv_timer_stop(&wrap->handle_); 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(); wrap->StateChange();
@ -160,7 +160,7 @@ class TimerWrap : public HandleWrap {
int r = uv_timer_again(&wrap->handle_); 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(); wrap->StateChange();
@ -186,7 +186,7 @@ class TimerWrap : public HandleWrap {
int64_t repeat = uv_timer_get_repeat(&wrap->handle_); 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)); return scope.Close(Integer::New(repeat));
} }

6
src/tty_wrap.cc

@ -124,7 +124,7 @@ class TTYWrap : StreamWrap {
int r = uv_tty_get_winsize(&wrap->handle_, &width, &height); int r = uv_tty_get_winsize(&wrap->handle_, &width, &height);
if (r) { if (r) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
return v8::Undefined(); return v8::Undefined();
} }
@ -143,7 +143,7 @@ class TTYWrap : StreamWrap {
int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue()); int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
if (r) { if (r) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} }
return scope.Close(Integer::New(r)); return scope.Close(Integer::New(r));
@ -169,7 +169,7 @@ class TTYWrap : StreamWrap {
TTYWrap(Handle<Object> object, int fd, bool readable) TTYWrap(Handle<Object> object, int fd, bool readable)
: StreamWrap(object, (uv_stream_t*)&handle_) { : 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_; uv_tty_t handle_;

16
src/udp_wrap.cc

@ -103,7 +103,7 @@ private:
UDPWrap::UDPWrap(Handle<Object> object): HandleWrap(object, UDPWrap::UDPWrap(Handle<Object> object): HandleWrap(object,
(uv_handle_t*)&handle_) { (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 assert(r == 0); // can't fail anyway
handle_.data = reinterpret_cast<void*>(this); handle_.data = reinterpret_cast<void*>(this);
} }
@ -176,7 +176,7 @@ Handle<Value> UDPWrap::DoBind(const Arguments& args, int family) {
} }
if (r) if (r)
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
return scope.Close(Integer::New(r)); return scope.Close(Integer::New(r));
} }
@ -233,7 +233,7 @@ Handle<Value> UDPWrap::DoSend(const Arguments& args, int family) {
req_wrap->Dispatched(); req_wrap->Dispatched();
if (r) { if (r) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
delete req_wrap; delete req_wrap;
return Null(); return Null();
} }
@ -260,8 +260,8 @@ Handle<Value> UDPWrap::RecvStart(const Arguments& args) {
// UV_EALREADY means that the socket is already bound but that's okay // UV_EALREADY means that the socket is already bound but that's okay
int r = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv); int r = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
if (r && uv_last_error(uv_default_loop()).code != UV_EALREADY) { if (r && uv_last_error(NODE_LOOP()).code != UV_EALREADY) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
return False(); return False();
} }
@ -297,7 +297,7 @@ Handle<Value> UDPWrap::GetSockName(const Arguments& args) {
return scope.Close(sockname); return scope.Close(sockname);
} }
else { else {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
return Null(); return Null();
} }
} }
@ -316,7 +316,7 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
assert(wrap->object_.IsEmpty() == false); assert(wrap->object_.IsEmpty() == false);
if (status) { if (status) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} }
Local<Value> argv[4] = { Local<Value> argv[4] = {
@ -364,7 +364,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
}; };
if (nread == -1) { if (nread == -1) {
SetErrno(uv_last_error(uv_default_loop())); SetErrno(uv_last_error(NODE_LOOP()));
} }
else { else {
Local<Object> rinfo = Object::New(); Local<Object> rinfo = Object::New();

Loading…
Cancel
Save