Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

isolates: isolate-ify the main loop

  • Loading branch information...
commit 356992fe4ded4d48e487aa9f0826a9b9ce022bcb 1 parent e9f8e28
Ben Noordhuis bnoordhuis authored
2  node.gyp
@@ -74,6 +74,7 @@
74 74 'src/node.cc',
75 75 'src/node_vars.cc',
76 76 'src/node_buffer.cc',
  77 + 'src/node_isolate.cc',
77 78 'src/node_constants.cc',
78 79 'src/node_extensions.cc',
79 80 'src/node_file.cc',
@@ -97,6 +98,7 @@
97 98 'src/node.h',
98 99 'src/node_vars.h',
99 100 'src/node_buffer.h',
  101 + 'src/node_isolate.h',
100 102 'src/node_constants.h',
101 103 'src/node_crypto.h',
102 104 'src/node_extensions.h',
8 src/cares_wrap.cc
@@ -607,7 +607,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) {
607 607
608 608 if (status) {
609 609 // Error
610   - SetErrno(uv_last_error(uv_default_loop()));
  610 + SetErrno(uv_last_error(NODE_LOOP()));
611 611 argv[0] = Local<Value>::New(Null());
612 612 } else {
613 613 // Success
@@ -710,7 +710,7 @@ static Handle<Value> GetAddrInfo(const Arguments& args) {
710 710 hints.ai_family = fam;
711 711 hints.ai_socktype = SOCK_STREAM;
712 712
713   - int r = uv_getaddrinfo(uv_default_loop(),
  713 + int r = uv_getaddrinfo(NODE_LOOP(),
714 714 &req_wrap->req_,
715 715 AfterGetAddrInfo,
716 716 *hostname,
@@ -719,7 +719,7 @@ static Handle<Value> GetAddrInfo(const Arguments& args) {
719 719 req_wrap->Dispatched();
720 720
721 721 if (r) {
722   - SetErrno(uv_last_error(uv_default_loop()));
  722 + SetErrno(uv_last_error(NODE_LOOP()));
723 723 delete req_wrap;
724 724 return scope.Close(v8::Null());
725 725 } else {
@@ -736,7 +736,7 @@ static void Initialize(Handle<Object> target) {
736 736 assert(r == ARES_SUCCESS);
737 737
738 738 struct ares_options options;
739   - uv_ares_init_options(uv_default_loop(), &ares_channel, &options, 0);
  739 + uv_ares_init_options(NODE_LOOP(), &ares_channel, &options, 0);
740 740 assert(r == 0);
741 741
742 742 NODE_SET_METHOD(target, "queryA", Query<QueryAWrap>);
8 src/fs_event_wrap.cc
@@ -109,15 +109,15 @@ Handle<Value> FSEventWrap::Start(const Arguments& args) {
109 109
110 110 String::Utf8Value path(args[0]->ToString());
111 111
112   - int r = uv_fs_event_init(uv_default_loop(), &wrap->handle_, *path, OnEvent, 0);
  112 + int r = uv_fs_event_init(NODE_LOOP(), &wrap->handle_, *path, OnEvent, 0);
113 113 if (r == 0) {
114 114 // Check for persistent argument
115 115 if (!args[1]->IsTrue()) {
116   - uv_unref(uv_default_loop());
  116 + uv_unref(NODE_LOOP());
117 117 }
118 118 wrap->initialized_ = true;
119 119 } else {
120   - SetErrno(uv_last_error(uv_default_loop()));
  120 + SetErrno(uv_last_error(NODE_LOOP()));
121 121 }
122 122
123 123 return scope.Close(Integer::New(r));
@@ -145,7 +145,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
145 145 // assumption that a rename implicitly means an attribute change. Not too
146 146 // unreasonable, right? Still, we should revisit this before v1.0.
147 147 if (status) {
148   - SetErrno(uv_last_error(uv_default_loop()));
  148 + SetErrno(uv_last_error(NODE_LOOP()));
149 149 eventStr = String::Empty();
150 150 }
151 151 else if (events & UV_RENAME) {
3  src/handle_wrap.cc
@@ -70,7 +70,7 @@ Handle<Value> HandleWrap::Unref(const Arguments& args) {
70 70 }
71 71
72 72 wrap->unref = true;
73   - uv_unref(uv_default_loop());
  73 + uv_unref(NODE_LOOP());
74 74
75 75 return v8::Undefined();
76 76 }
@@ -102,7 +102,6 @@ Handle<Value> HandleWrap::Close(const Arguments& args) {
102 102 assert(!wrap->object_.IsEmpty());
103 103 uv_close(wrap->handle__, OnClose);
104 104
105   -
106 105 HandleWrap::Ref(args);
107 106
108 107 wrap->StateChange();
37 src/node.cc
@@ -170,7 +170,7 @@ static void Idle(uv_idle_t* watcher, int status) {
170 170 static void Check(uv_check_t* watcher, int status) {
171 171 assert(watcher == &gc_check);
172 172
173   - tick_times[tick_time_head] = uv_now(uv_default_loop());
  173 + tick_times[tick_time_head] = uv_now(NODE_LOOP());
174 174 tick_time_head = (tick_time_head + 1) % RPM_SAMPLES;
175 175
176 176 StartGCTimer();
@@ -200,7 +200,7 @@ static void Tick(void) {
200 200 need_tick_cb = false;
201 201 if (uv_is_active((uv_handle_t*) &tick_spinner)) {
202 202 uv_idle_stop(&tick_spinner);
203   - uv_unref(uv_default_loop());
  203 + uv_unref(NODE_LOOP());
204 204 }
205 205
206 206 HandleScope scope;
@@ -242,7 +242,7 @@ static Handle<Value> NeedTickCallback(const Arguments& args) {
242 242 // tick_spinner to keep the event loop alive long enough to handle it.
243 243 if (!uv_is_active((uv_handle_t*) &tick_spinner)) {
244 244 uv_idle_start(&tick_spinner, Spin);
245   - uv_ref(uv_default_loop());
  245 + uv_ref(NODE_LOOP());
246 246 }
247 247 return Undefined();
248 248 }
@@ -1494,7 +1494,7 @@ static void CheckStatus(uv_timer_t* watcher, int status) {
1494 1494 }
1495 1495 }
1496 1496
1497   - double d = uv_now(uv_default_loop()) - TICK_TIME(3);
  1497 + double d = uv_now(NODE_LOOP()) - TICK_TIME(3);
1498 1498
1499 1499 //printfb("timer d = %f\n", d);
1500 1500
@@ -1523,7 +1523,7 @@ static Handle<Value> Uptime(const Arguments& args) {
1523 1523 v8::Handle<v8::Value> UVCounters(const v8::Arguments& args) {
1524 1524 HandleScope scope;
1525 1525
1526   - uv_counters_t* c = &uv_default_loop()->counters;
  1526 + uv_counters_t* c = &NODE_LOOP()->counters;
1527 1527
1528 1528 Local<Object> obj = Object::New();
1529 1529
@@ -2566,26 +2566,29 @@ char** Init(int argc, char *argv[]) {
2566 2566 RegisterSignalHandler(SIGTERM, SignalExit);
2567 2567 #endif // __POSIX__
2568 2568
  2569 + // Don't use NODE_LOOP(), the node::Isolate() has not yet been initialized.
  2570 + uv_loop_t* const loop = uv_default_loop();
  2571 +
2569 2572 uv_prepare_init(uv_default_loop(), &prepare_tick_watcher);
2570 2573 uv_prepare_start(&prepare_tick_watcher, PrepareTick);
2571   - uv_unref(uv_default_loop());
  2574 + uv_unref(loop);
2572 2575
2573 2576 uv_check_init(uv_default_loop(), &check_tick_watcher);
2574 2577 uv_check_start(&check_tick_watcher, node::CheckTick);
2575   - uv_unref(uv_default_loop());
  2578 + uv_unref(loop);
2576 2579
2577 2580 uv_idle_init(uv_default_loop(), &tick_spinner);
2578   - uv_unref(uv_default_loop());
  2581 + uv_unref(loop);
2579 2582
2580 2583 uv_check_init(uv_default_loop(), &gc_check);
2581 2584 uv_check_start(&gc_check, node::Check);
2582   - uv_unref(uv_default_loop());
  2585 + uv_unref(loop);
2583 2586
2584 2587 uv_idle_init(uv_default_loop(), &gc_idle);
2585   - uv_unref(uv_default_loop());
  2588 + uv_unref(loop);
2586 2589
2587 2590 uv_timer_init(uv_default_loop(), &gc_timer);
2588   - uv_unref(uv_default_loop());
  2591 + uv_unref(loop);
2589 2592
2590 2593 V8::SetFatalErrorHandler(node::OnFatalError);
2591 2594
@@ -2598,13 +2601,13 @@ char** Init(int argc, char *argv[]) {
2598 2601 // main thread to execute a random bit of javascript - which will give V8
2599 2602 // control so it can handle whatever new message had been received on the
2600 2603 // debug thread.
2601   - uv_async_init(uv_default_loop(), &debug_watcher, node::DebugMessageCallback);
  2604 + uv_async_init(loop, &debug_watcher, node::DebugMessageCallback);
2602 2605 // unref it so that we exit the event loop despite it being active.
2603   - uv_unref(uv_default_loop());
  2606 + uv_unref(loop);
2604 2607
2605 2608 // Fetch a reference to the main isolate, so we have a reference to it
2606 2609 // even when we need it to access it from another (debugger) thread.
2607   - node_isolate = Isolate::GetCurrent();
  2610 + node_isolate = v8::Isolate::GetCurrent();
2608 2611
2609 2612 // If the --debug flag was specified then initialize the debug thread.
2610 2613 if (use_debug_agent) {
@@ -2646,7 +2649,11 @@ int Start(int argc, char *argv[]) {
2646 2649 Persistent<v8::Context> context = v8::Context::New();
2647 2650 v8::Context::Scope context_scope(context);
2648 2651
  2652 + // Create the main node::Isolate object
  2653 + Isolate::New(uv_default_loop());
  2654 +
2649 2655 Handle<Object> process_l = SetupProcessObject(argc, argv);
  2656 +
2650 2657 v8_typed_array::AttachBindings(context->Global());
2651 2658
2652 2659 // Create all the objects, load modules, do everything.
@@ -2658,7 +2665,7 @@ int Start(int argc, char *argv[]) {
2658 2665 // there are no watchers on the loop (except for the ones that were
2659 2666 // uv_unref'd) then this function exits. As long as there are active
2660 2667 // watchers, it blocks.
2661   - uv_run(uv_default_loop());
  2668 + uv_run(NODE_LOOP());
2662 2669
2663 2670 EmitExit(process_l);
2664 2671
3  src/node.h
@@ -64,6 +64,7 @@
64 64 #include <sys/stat.h>
65 65 #include <assert.h>
66 66
  67 +#include <node_isolate.h>
67 68 #include <node_object_wrap.h>
68 69
69 70 #ifndef offset_of
@@ -87,6 +88,8 @@
87 88 #define NODE_STRINGIFY_HELPER(n) #n
88 89 #endif
89 90
  91 +#define NODE_LOOP() (node::Isolate::GetCurrent()->GetLoop())
  92 +
90 93 namespace node {
91 94
92 95 int Start(int argc, char *argv[]);
5 src/node_crypto.cc
@@ -4117,7 +4117,8 @@ PBKDF2(const Arguments& args) {
4117 4117
4118 4118 req = new uv_work_t();
4119 4119 req->data = request;
4120   - uv_queue_work(uv_default_loop(), req, EIO_PBKDF2, EIO_PBKDF2After);
  4120 + uv_queue_work(NODE_LOOP(), req, EIO_PBKDF2, EIO_PBKDF2After);
  4121 +
4121 4122 return Undefined();
4122 4123
4123 4124 err:
@@ -4239,7 +4240,7 @@ Handle<Value> RandomBytes(const Arguments& args) {
4239 4240 Local<Function> callback_v = Local<Function>(Function::Cast(*args[1]));
4240 4241 req->callback_ = Persistent<Function>::New(callback_v);
4241 4242
4242   - uv_queue_work(uv_default_loop(),
  4243 + uv_queue_work(NODE_LOOP(),
4243 4244 &req->work_req_,
4244 4245 RandomBytesWork<generator>,
4245 4246 RandomBytesAfter<generator>);
42 src/node_isolate.cc
... ... @@ -0,0 +1,42 @@
  1 +// Copyright Joyent, Inc. and other Node contributors.
  2 +//
  3 +// Permission is hereby granted, free of charge, to any person obtaining a
  4 +// copy of this software and associated documentation files (the
  5 +// "Software"), to deal in the Software without restriction, including
  6 +// without limitation the rights to use, copy, modify, merge, publish,
  7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
  8 +// persons to whom the Software is furnished to do so, subject to the
  9 +// following conditions:
  10 +//
  11 +// The above copyright notice and this permission notice shall be included
  12 +// in all copies or substantial portions of the Software.
  13 +//
  14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
  21 +
  22 +#include "node_isolate.h"
  23 +#include <assert.h>
  24 +
  25 +
  26 +namespace node {
  27 +
  28 +
  29 +Isolate* Isolate::New(uv_loop_t* loop) {
  30 + return new Isolate(loop);
  31 +}
  32 +
  33 +
  34 +Isolate::Isolate(uv_loop_t* loop) {
  35 + loop_ = loop;
  36 + isolate_ = v8::Isolate::GetCurrent();
  37 + assert(isolate_->GetData() == NULL);
  38 + isolate_->SetData(this);
  39 +}
  40 +
  41 +
  42 +} // namespace node
69 src/node_isolate.h
... ... @@ -0,0 +1,69 @@
  1 +// Copyright Joyent, Inc. and other Node contributors.
  2 +//
  3 +// Permission is hereby granted, free of charge, to any person obtaining a
  4 +// copy of this software and associated documentation files (the
  5 +// "Software"), to deal in the Software without restriction, including
  6 +// without limitation the rights to use, copy, modify, merge, publish,
  7 +// distribute, sublicense, and/or sell copies of the Software, and to permit
  8 +// persons to whom the Software is furnished to do so, subject to the
  9 +// following conditions:
  10 +//
  11 +// The above copyright notice and this permission notice shall be included
  12 +// in all copies or substantial portions of the Software.
  13 +//
  14 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15 +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16 +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17 +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18 +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19 +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20 +// USE OR OTHER DEALINGS IN THE SOFTWARE.
  21 +
  22 +#ifndef SRC_NODE_ISOLATE_H_
  23 +#define SRC_NODE_ISOLATE_H_
  24 +
  25 +#include <v8.h>
  26 +#include <uv.h>
  27 +
  28 +#ifdef NDEBUG
  29 +# define NODE_ISOLATE_CHECK(ptr) ((void) (ptr))
  30 +#else
  31 +# include <assert.h>
  32 +# define NODE_ISOLATE_CHECK(ptr) \
  33 + do { \
  34 + node::Isolate* data_ = node::Isolate::GetCurrent(); \
  35 + assert(data_ == (ptr)); \
  36 + } \
  37 + while (0)
  38 +#endif
  39 +
  40 +
  41 +namespace node {
  42 +
  43 +class Isolate {
  44 +public:
  45 + static Isolate* New(uv_loop_t* loop);
  46 +
  47 + static Isolate* GetCurrent() {
  48 + return reinterpret_cast<Isolate*>(v8::Isolate::GetCurrent()->GetData());
  49 + }
  50 +
  51 + uv_loop_t* GetLoop() {
  52 + NODE_ISOLATE_CHECK(this);
  53 + return loop_;
  54 + }
  55 +
  56 + operator v8::Isolate*() {
  57 + NODE_ISOLATE_CHECK(this);
  58 + return isolate_;
  59 + }
  60 +
  61 +private:
  62 + Isolate(uv_loop_t* loop);
  63 + v8::Isolate* isolate_;
  64 + uv_loop_t* loop_;
  65 +};
  66 +
  67 +} // namespace node
  68 +
  69 +#endif // SRC_NODE_ISOLATE_H_
2  src/node_zlib.cc
@@ -133,7 +133,7 @@ template <node_zlib_mode mode> class ZCtx : public ObjectWrap {
133 133 uv_work_t* work_req = new uv_work_t();
134 134 work_req->data = req_wrap;
135 135
136   - uv_queue_work(uv_default_loop(),
  136 + uv_queue_work(NODE_LOOP(),
137 137 work_req,
138 138 ZCtx<mode>::Process,
139 139 ZCtx<mode>::After);
8 src/pipe_wrap.cc
@@ -123,7 +123,7 @@ Handle<Value> PipeWrap::New(const Arguments& args) {
123 123
124 124 PipeWrap::PipeWrap(Handle<Object> object, bool ipc)
125 125 : StreamWrap(object, (uv_stream_t*) &handle_) {
126   - int r = uv_pipe_init(uv_default_loop(), &handle_, ipc);
  126 + int r = uv_pipe_init(NODE_LOOP(), &handle_, ipc);
127 127 assert(r == 0); // How do we proxy this error up to javascript?
128 128 // Suggestion: uv_pipe_init() returns void.
129 129 handle_.data = reinterpret_cast<void*>(this);
@@ -141,7 +141,7 @@ Handle<Value> PipeWrap::Bind(const Arguments& args) {
141 141 int r = uv_pipe_bind(&wrap->handle_, *name);
142 142
143 143 // Error starting the pipe.
144   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  144 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
145 145
146 146 return scope.Close(Integer::New(r));
147 147 }
@@ -172,7 +172,7 @@ Handle<Value> PipeWrap::Listen(const Arguments& args) {
172 172 int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection);
173 173
174 174 // Error starting the pipe.
175   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  175 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
176 176
177 177 return scope.Close(Integer::New(r));
178 178 }
@@ -225,7 +225,7 @@ void PipeWrap::AfterConnect(uv_connect_t* req, int status) {
225 225 assert(wrap->object_.IsEmpty() == false);
226 226
227 227 if (status) {
228   - SetErrno(uv_last_error(uv_default_loop()));
  228 + SetErrno(uv_last_error(NODE_LOOP()));
229 229 }
230 230
231 231 Local<Value> argv[3] = {
6 src/process_wrap.cc
@@ -175,7 +175,7 @@ class ProcessWrap : public HandleWrap {
175 175 Get(String::NewSymbol("windowsVerbatimArguments"))->IsTrue();
176 176 #endif
177 177
178   - int r = uv_spawn(uv_default_loop(), &wrap->process_, options);
  178 + int r = uv_spawn(NODE_LOOP(), &wrap->process_, options);
179 179
180 180 wrap->SetHandle((uv_handle_t*)&wrap->process_);
181 181 assert(wrap->process_.data == wrap);
@@ -195,7 +195,7 @@ class ProcessWrap : public HandleWrap {
195 195 delete [] options.env;
196 196 }
197 197
198   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  198 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
199 199
200 200 return scope.Close(Integer::New(r));
201 201 }
@@ -209,7 +209,7 @@ class ProcessWrap : public HandleWrap {
209 209
210 210 int r = uv_process_kill(&wrap->process_, signal);
211 211
212   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  212 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
213 213
214 214 return scope.Close(Integer::New(r));
215 215 }
14 src/stream_wrap.cc
@@ -132,7 +132,7 @@ Handle<Value> StreamWrap::ReadStart(const Arguments& args) {
132 132 }
133 133
134 134 // Error starting the tcp.
135   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  135 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
136 136
137 137 return scope.Close(Integer::New(r));
138 138 }
@@ -146,7 +146,7 @@ Handle<Value> StreamWrap::ReadStop(const Arguments& args) {
146 146 int r = uv_read_stop(wrap->stream_);
147 147
148 148 // Error starting the tcp.
149   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  149 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
150 150
151 151 return scope.Close(Integer::New(r));
152 152 }
@@ -225,7 +225,7 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, ssize_t nread,
225 225 slab_used -= buf.len;
226 226 }
227 227
228   - SetErrno(uv_last_error(uv_default_loop()));
  228 + SetErrno(uv_last_error(NODE_LOOP()));
229 229 MakeCallback(wrap->object_, "onread", 0, NULL);
230 230 return;
231 231 }
@@ -338,7 +338,7 @@ Handle<Value> StreamWrap::Write(const Arguments& args) {
338 338 wrap->UpdateWriteQueueSize();
339 339
340 340 if (r) {
341   - SetErrno(uv_last_error(uv_default_loop()));
  341 + SetErrno(uv_last_error(NODE_LOOP()));
342 342 delete req_wrap;
343 343 return scope.Close(v8::Null());
344 344 } else {
@@ -358,7 +358,7 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) {
358 358 assert(wrap->object_.IsEmpty() == false);
359 359
360 360 if (status) {
361   - SetErrno(uv_last_error(uv_default_loop()));
  361 + SetErrno(uv_last_error(NODE_LOOP()));
362 362 }
363 363
364 364 wrap->UpdateWriteQueueSize();
@@ -388,7 +388,7 @@ Handle<Value> StreamWrap::Shutdown(const Arguments& args) {
388 388 req_wrap->Dispatched();
389 389
390 390 if (r) {
391   - SetErrno(uv_last_error(uv_default_loop()));
  391 + SetErrno(uv_last_error(NODE_LOOP()));
392 392 delete req_wrap;
393 393 return scope.Close(v8::Null());
394 394 } else {
@@ -408,7 +408,7 @@ void StreamWrap::AfterShutdown(uv_shutdown_t* req, int status) {
408 408 HandleScope scope;
409 409
410 410 if (status) {
411   - SetErrno(uv_last_error(uv_default_loop()));
  411 + SetErrno(uv_last_error(NODE_LOOP()));
412 412 }
413 413
414 414 Local<Value> argv[3] = {
26 src/tcp_wrap.cc
@@ -154,7 +154,7 @@ Handle<Value> TCPWrap::New(const Arguments& args) {
154 154
155 155 TCPWrap::TCPWrap(Handle<Object> object)
156 156 : StreamWrap(object, (uv_stream_t*) &handle_) {
157   - int r = uv_tcp_init(uv_default_loop(), &handle_);
  157 + int r = uv_tcp_init(NODE_LOOP(), &handle_);
158 158 assert(r == 0); // How do we proxy this error up to javascript?
159 159 // Suggestion: uv_tcp_init() returns void.
160 160 UpdateWriteQueueSize();
@@ -182,7 +182,7 @@ Handle<Value> TCPWrap::GetSockName(const Arguments& args) {
182 182
183 183 Local<Object> sockname = Object::New();
184 184 if (r != 0) {
185   - SetErrno(uv_last_error(uv_default_loop()));
  185 + SetErrno(uv_last_error(NODE_LOOP()));
186 186 } else {
187 187 family = address.ss_family;
188 188
@@ -224,7 +224,7 @@ Handle<Value> TCPWrap::GetPeerName(const Arguments& args) {
224 224
225 225 Local<Object> sockname = Object::New();
226 226 if (r != 0) {
227   - SetErrno(uv_last_error(uv_default_loop()));
  227 + SetErrno(uv_last_error(NODE_LOOP()));
228 228 } else {
229 229 family = address.ss_family;
230 230
@@ -257,7 +257,7 @@ Handle<Value> TCPWrap::SetNoDelay(const Arguments& args) {
257 257
258 258 int r = uv_tcp_nodelay(&wrap->handle_, 1);
259 259 if (r)
260   - SetErrno(uv_last_error(uv_default_loop()));
  260 + SetErrno(uv_last_error(NODE_LOOP()));
261 261
262 262 return Undefined();
263 263 }
@@ -273,7 +273,7 @@ Handle<Value> TCPWrap::SetKeepAlive(const Arguments& args) {
273 273
274 274 int r = uv_tcp_keepalive(&wrap->handle_, enable, delay);
275 275 if (r)
276   - SetErrno(uv_last_error(uv_default_loop()));
  276 + SetErrno(uv_last_error(NODE_LOOP()));
277 277
278 278 return Undefined();
279 279 }
@@ -289,7 +289,7 @@ Handle<Value> TCPWrap::SetSimultaneousAccepts(const Arguments& args) {
289 289
290 290 int r = uv_tcp_simultaneous_accepts(&wrap->handle_, enable ? 1 : 0);
291 291 if (r)
292   - SetErrno(uv_last_error(uv_default_loop()));
  292 + SetErrno(uv_last_error(NODE_LOOP()));
293 293
294 294 return Undefined();
295 295 }
@@ -308,7 +308,7 @@ Handle<Value> TCPWrap::Bind(const Arguments& args) {
308 308 int r = uv_tcp_bind(&wrap->handle_, address);
309 309
310 310 // Error starting the tcp.
311   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  311 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
312 312
313 313 return scope.Close(Integer::New(r));
314 314 }
@@ -326,7 +326,7 @@ Handle<Value> TCPWrap::Bind6(const Arguments& args) {
326 326 int r = uv_tcp_bind6(&wrap->handle_, address);
327 327
328 328 // Error starting the tcp.
329   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  329 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
330 330
331 331 return scope.Close(Integer::New(r));
332 332 }
@@ -342,7 +342,7 @@ Handle<Value> TCPWrap::Listen(const Arguments& args) {
342 342 int r = uv_listen((uv_stream_t*)&wrap->handle_, backlog, OnConnection);
343 343
344 344 // Error starting the tcp.
345   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  345 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
346 346
347 347 return scope.Close(Integer::New(r));
348 348 }
@@ -377,7 +377,7 @@ void TCPWrap::OnConnection(uv_stream_t* handle, int status) {
377 377 // Successful accept. Call the onconnection callback in JavaScript land.
378 378 argv[0] = client_obj;
379 379 } else {
380   - SetErrno(uv_last_error(uv_default_loop()));
  380 + SetErrno(uv_last_error(NODE_LOOP()));
381 381 argv[0] = v8::Null();
382 382 }
383 383
@@ -396,7 +396,7 @@ void TCPWrap::AfterConnect(uv_connect_t* req, int status) {
396 396 assert(wrap->object_.IsEmpty() == false);
397 397
398 398 if (status) {
399   - SetErrno(uv_last_error(uv_default_loop()));
  399 + SetErrno(uv_last_error(NODE_LOOP()));
400 400 }
401 401
402 402 Local<Value> argv[3] = {
@@ -432,7 +432,7 @@ Handle<Value> TCPWrap::Connect(const Arguments& args) {
432 432 req_wrap->Dispatched();
433 433
434 434 if (r) {
435   - SetErrno(uv_last_error(uv_default_loop()));
  435 + SetErrno(uv_last_error(NODE_LOOP()));
436 436 delete req_wrap;
437 437 return scope.Close(v8::Null());
438 438 } else {
@@ -459,7 +459,7 @@ Handle<Value> TCPWrap::Connect6(const Arguments& args) {
459 459 req_wrap->Dispatched();
460 460
461 461 if (r) {
462   - SetErrno(uv_last_error(uv_default_loop()));
  462 + SetErrno(uv_last_error(NODE_LOOP()));
463 463 delete req_wrap;
464 464 return scope.Close(v8::Null());
465 465 } else {
18 src/timer_wrap.cc
@@ -91,7 +91,7 @@ class TimerWrap : public HandleWrap {
91 91 : HandleWrap(object, (uv_handle_t*) &handle_) {
92 92 active_ = false;
93 93
94   - int r = uv_timer_init(uv_default_loop(), &handle_);
  94 + int r = uv_timer_init(NODE_LOOP(), &handle_);
95 95 assert(r == 0);
96 96
97 97 handle_.data = this;
@@ -99,11 +99,11 @@ class TimerWrap : public HandleWrap {
99 99 // uv_timer_init adds a loop reference. (That is, it calls uv_ref.) This
100 100 // is not the behavior we want in Node. Timers should not increase the
101 101 // ref count of the loop except when active.
102   - uv_unref(uv_default_loop());
  102 + uv_unref(NODE_LOOP());
103 103 }
104 104
105 105 ~TimerWrap() {
106   - if (!active_) uv_ref(uv_default_loop());
  106 + if (!active_) uv_ref(NODE_LOOP());
107 107 }
108 108
109 109 void StateChange() {
@@ -113,11 +113,11 @@ class TimerWrap : public HandleWrap {
113 113 if (!was_active && active_) {
114 114 // If our state is changing from inactive to active, we
115 115 // increase the loop's reference count.
116   - uv_ref(uv_default_loop());
  116 + uv_ref(NODE_LOOP());
117 117 } else if (was_active && !active_) {
118 118 // If our state is changing from active to inactive, we
119 119 // decrease the loop's reference count.
120   - uv_unref(uv_default_loop());
  120 + uv_unref(NODE_LOOP());
121 121 }
122 122 }
123 123
@@ -132,7 +132,7 @@ class TimerWrap : public HandleWrap {
132 132 int r = uv_timer_start(&wrap->handle_, OnTimeout, timeout, repeat);
133 133
134 134 // Error starting the timer.
135   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  135 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
136 136
137 137 wrap->StateChange();
138 138
@@ -146,7 +146,7 @@ class TimerWrap : public HandleWrap {
146 146
147 147 int r = uv_timer_stop(&wrap->handle_);
148 148
149   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  149 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
150 150
151 151 wrap->StateChange();
152 152
@@ -160,7 +160,7 @@ class TimerWrap : public HandleWrap {
160 160
161 161 int r = uv_timer_again(&wrap->handle_);
162 162
163   - if (r) SetErrno(uv_last_error(uv_default_loop()));
  163 + if (r) SetErrno(uv_last_error(NODE_LOOP()));
164 164
165 165 wrap->StateChange();
166 166
@@ -186,7 +186,7 @@ class TimerWrap : public HandleWrap {
186 186
187 187 int64_t repeat = uv_timer_get_repeat(&wrap->handle_);
188 188
189   - if (repeat < 0) SetErrno(uv_last_error(uv_default_loop()));
  189 + if (repeat < 0) SetErrno(uv_last_error(NODE_LOOP()));
190 190
191 191 return scope.Close(Integer::New(repeat));
192 192 }
6 src/tty_wrap.cc
@@ -124,7 +124,7 @@ class TTYWrap : StreamWrap {
124 124 int r = uv_tty_get_winsize(&wrap->handle_, &width, &height);
125 125
126 126 if (r) {
127   - SetErrno(uv_last_error(uv_default_loop()));
  127 + SetErrno(uv_last_error(NODE_LOOP()));
128 128 return v8::Undefined();
129 129 }
130 130
@@ -143,7 +143,7 @@ class TTYWrap : StreamWrap {
143 143 int r = uv_tty_set_mode(&wrap->handle_, args[0]->IsTrue());
144 144
145 145 if (r) {
146   - SetErrno(uv_last_error(uv_default_loop()));
  146 + SetErrno(uv_last_error(NODE_LOOP()));
147 147 }
148 148
149 149 return scope.Close(Integer::New(r));
@@ -169,7 +169,7 @@ class TTYWrap : StreamWrap {
169 169
170 170 TTYWrap(Handle<Object> object, int fd, bool readable)
171 171 : StreamWrap(object, (uv_stream_t*)&handle_) {
172   - uv_tty_init(uv_default_loop(), &handle_, fd, readable);
  172 + uv_tty_init(NODE_LOOP(), &handle_, fd, readable);
173 173 }
174 174
175 175 uv_tty_t handle_;
16 src/udp_wrap.cc
@@ -103,7 +103,7 @@ class UDPWrap: public HandleWrap {
103 103
104 104 UDPWrap::UDPWrap(Handle<Object> object): HandleWrap(object,
105 105 (uv_handle_t*)&handle_) {
106   - int r = uv_udp_init(uv_default_loop(), &handle_);
  106 + int r = uv_udp_init(NODE_LOOP(), &handle_);
107 107 assert(r == 0); // can't fail anyway
108 108 handle_.data = reinterpret_cast<void*>(this);
109 109 }
@@ -176,7 +176,7 @@ Handle<Value> UDPWrap::DoBind(const Arguments& args, int family) {
176 176 }
177 177
178 178 if (r)
179   - SetErrno(uv_last_error(uv_default_loop()));
  179 + SetErrno(uv_last_error(NODE_LOOP()));
180 180
181 181 return scope.Close(Integer::New(r));
182 182 }
@@ -233,7 +233,7 @@ Handle<Value> UDPWrap::DoSend(const Arguments& args, int family) {
233 233 req_wrap->Dispatched();
234 234
235 235 if (r) {
236   - SetErrno(uv_last_error(uv_default_loop()));
  236 + SetErrno(uv_last_error(NODE_LOOP()));
237 237 delete req_wrap;
238 238 return Null();
239 239 }
@@ -260,8 +260,8 @@ Handle<Value> UDPWrap::RecvStart(const Arguments& args) {
260 260
261 261 // UV_EALREADY means that the socket is already bound but that's okay
262 262 int r = uv_udp_recv_start(&wrap->handle_, OnAlloc, OnRecv);
263   - if (r && uv_last_error(uv_default_loop()).code != UV_EALREADY) {
264   - SetErrno(uv_last_error(uv_default_loop()));
  263 + if (r && uv_last_error(NODE_LOOP()).code != UV_EALREADY) {
  264 + SetErrno(uv_last_error(NODE_LOOP()));
265 265 return False();
266 266 }
267 267
@@ -297,7 +297,7 @@ Handle<Value> UDPWrap::GetSockName(const Arguments& args) {
297 297 return scope.Close(sockname);
298 298 }
299 299 else {
300   - SetErrno(uv_last_error(uv_default_loop()));
  300 + SetErrno(uv_last_error(NODE_LOOP()));
301 301 return Null();
302 302 }
303 303 }
@@ -316,7 +316,7 @@ void UDPWrap::OnSend(uv_udp_send_t* req, int status) {
316 316 assert(wrap->object_.IsEmpty() == false);
317 317
318 318 if (status) {
319   - SetErrno(uv_last_error(uv_default_loop()));
  319 + SetErrno(uv_last_error(NODE_LOOP()));
320 320 }
321 321
322 322 Local<Value> argv[4] = {
@@ -364,7 +364,7 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
364 364 };
365 365
366 366 if (nread == -1) {
367   - SetErrno(uv_last_error(uv_default_loop()));
  367 + SetErrno(uv_last_error(NODE_LOOP()));
368 368 }
369 369 else {
370 370 Local<Object> rinfo = Object::New();

0 comments on commit 356992f

Please sign in to comment.
Something went wrong with that request. Please try again.