|
@ -34,6 +34,7 @@ void IOWatcher::Initialize(Handle<Object> target) { |
|
|
void IOWatcher::Callback(EV_P_ ev_io *w, int revents) { |
|
|
void IOWatcher::Callback(EV_P_ ev_io *w, int revents) { |
|
|
IOWatcher *io = static_cast<IOWatcher*>(w->data); |
|
|
IOWatcher *io = static_cast<IOWatcher*>(w->data); |
|
|
assert(w == &io->watcher_); |
|
|
assert(w == &io->watcher_); |
|
|
|
|
|
assert(!(revents & EV_ERROR)); |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
Local<Value> callback_v = io->handle_->Get(callback_symbol); |
|
|
Local<Value> callback_v = io->handle_->Get(callback_symbol); |
|
@ -50,7 +51,9 @@ void IOWatcher::Callback(EV_P_ ev_io *w, int revents) { |
|
|
argv[0] = Local<Value>::New(revents & EV_READ ? True() : False()); |
|
|
argv[0] = Local<Value>::New(revents & EV_READ ? True() : False()); |
|
|
argv[1] = Local<Value>::New(revents & EV_WRITE ? True() : False()); |
|
|
argv[1] = Local<Value>::New(revents & EV_WRITE ? True() : False()); |
|
|
|
|
|
|
|
|
|
|
|
io->Ref(); |
|
|
callback->Call(io->handle_, 2, argv); |
|
|
callback->Call(io->handle_, 2, argv); |
|
|
|
|
|
io->Unref(); |
|
|
|
|
|
|
|
|
if (try_catch.HasCaught()) { |
|
|
if (try_catch.HasCaught()) { |
|
|
FatalException(try_catch); |
|
|
FatalException(try_catch); |
|
@ -76,27 +79,16 @@ Handle<Value> IOWatcher::New(const Arguments& args) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> IOWatcher::Start(const Arguments& args) { |
|
|
|
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
|
|
|
IOWatcher *io = Unwrap(args.Holder()); |
|
|
|
|
|
|
|
|
|
|
|
ev_io_start(EV_DEFAULT_UC_ &io->watcher_); |
|
|
|
|
|
assert(ev_is_active(&io->watcher_)); |
|
|
|
|
|
|
|
|
|
|
|
return Undefined(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> IOWatcher::Set(const Arguments& args) { |
|
|
Handle<Value> IOWatcher::Set(const Arguments& args) { |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
|
|
|
|
|
|
|
IOWatcher *io = Unwrap(args.Holder()); |
|
|
|
|
|
|
|
|
|
|
|
if (!args[0]->IsInt32()) { |
|
|
if (!args[0]->IsInt32()) { |
|
|
return ThrowException(Exception::TypeError( |
|
|
return ThrowException(Exception::TypeError( |
|
|
String::New("First arg should be a file descriptor."))); |
|
|
String::New("First arg should be a file descriptor."))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IOWatcher *io = ObjectWrap::Unwrap<IOWatcher>(args.This()); |
|
|
|
|
|
|
|
|
int fd = args[0]->Int32Value(); |
|
|
int fd = args[0]->Int32Value(); |
|
|
|
|
|
|
|
|
if (!args[1]->IsBoolean()) { |
|
|
if (!args[1]->IsBoolean()) { |
|
@ -120,19 +112,38 @@ Handle<Value> IOWatcher::Set(const Arguments& args) { |
|
|
return Undefined(); |
|
|
return Undefined(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> IOWatcher::Start(const Arguments& args) { |
|
|
|
|
|
HandleScope scope; |
|
|
|
|
|
IOWatcher *io = ObjectWrap::Unwrap<IOWatcher>(args.This()); |
|
|
|
|
|
io->Start(); |
|
|
|
|
|
return Undefined(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Handle<Value> IOWatcher::Stop(const Arguments& args) { |
|
|
Handle<Value> IOWatcher::Stop(const Arguments& args) { |
|
|
HandleScope scope; |
|
|
HandleScope scope; |
|
|
IOWatcher *io = Unwrap(args.This()); |
|
|
IOWatcher *io = ObjectWrap::Unwrap<IOWatcher>(args.This()); |
|
|
io->Stop(); |
|
|
io->Stop(); |
|
|
return Undefined(); |
|
|
return Undefined(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IOWatcher::Start () { |
|
|
|
|
|
if (!ev_is_active(&watcher_)) { |
|
|
|
|
|
ev_io_start(EV_DEFAULT_UC_ &watcher_); |
|
|
|
|
|
Ref(); |
|
|
|
|
|
} |
|
|
|
|
|
assert(ev_is_active(&watcher_)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IOWatcher::Stop () { |
|
|
void IOWatcher::Stop () { |
|
|
if (ev_is_active(&watcher_)) { |
|
|
if (ev_is_active(&watcher_)) { |
|
|
ev_io_stop(EV_DEFAULT_UC_ &watcher_); |
|
|
ev_io_stop(EV_DEFAULT_UC_ &watcher_); |
|
|
assert(!ev_is_active(&watcher_)); |
|
|
Unref(); |
|
|
} |
|
|
} |
|
|
|
|
|
assert(!ev_is_active(&watcher_)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|