void EIO_AfterWatchPort(uv_work_t* req) { Nan::HandleScope scope; WatchPortBaton* data = static_cast<WatchPortBaton*>(req->data); if (data->disconnected) { data->disconnectedCallback->Call(0, NULL); DisposeWatchPortCallbacks(data); goto cleanup; } bool skipCleanup = false; if (data->bytesRead > 0) { v8::Local<v8::Value> argv[1]; argv[0] = Nan::NewBuffer(data->buffer, data->bytesRead, FinalizerCallback, req).ToLocalChecked(); skipCleanup = true; data->dataCallback->Call(1, argv); } else if (data->errorCode > 0) { if (data->errorCode == ERROR_INVALID_HANDLE && IsClosingHandle((int)data->fd)) { DisposeWatchPortCallbacks(data); goto cleanup; } else { v8::Local<v8::Value> argv[1]; argv[0] = Nan::Error(data->errorString); data->errorCallback->Call(1, argv); Sleep(100); // prevent the errors from occurring too fast } } AfterOpenSuccess((int)data->fd, data->dataCallback, data->disconnectedCallback, data->errorCallback); cleanup: if (!skipCleanup) { delete data; delete req; } }
void EIO_AfterOpen(uv_work_t* req) { NanScope(); OpenBaton* data = static_cast<OpenBaton*>(req->data); v8::Handle<v8::Value> argv[2]; if(data->errorString[0]) { argv[0] = v8::Exception::Error(v8::String::New(data->errorString)); argv[1] = v8::Undefined(); // not needed for AfterOpenSuccess delete data->dataCallback; delete data->errorCallback; delete data->disconnectedCallback; } else { argv[0] = v8::Undefined(); argv[1] = v8::Int32::New(data->result); AfterOpenSuccess(data->result, data->dataCallback, data->disconnectedCallback, data->errorCallback); } data->callback->Call(2, argv); delete data->callback; delete data; delete req; }
void EIO_AfterWatchPort(uv_work_t* req) { WatchPortBaton* data = static_cast<WatchPortBaton*>(req->data); if(data->disconnected) { v8::Handle<v8::Value> argv[1]; v8::Function::Cast(*data->disconnectedCallback)->Call(v8::Context::GetCurrent()->Global(), 0, argv); goto cleanup; } if(data->bytesRead > 0) { v8::Handle<v8::Value> argv[1]; argv[0] = node::Buffer::New(data->buffer, data->bytesRead)->handle_; v8::Function::Cast(*data->dataCallback)->Call(v8::Context::GetCurrent()->Global(), 1, argv); } else if(data->errorCode > 0) { if(data->errorCode == ERROR_INVALID_HANDLE && IsClosingHandle((int)data->fd)) { goto cleanup; } else { v8::Handle<v8::Value> argv[1]; argv[0] = v8::Exception::Error(v8::String::New(data->errorString)); v8::Function::Cast(*data->errorCallback)->Call(v8::Context::GetCurrent()->Global(), 1, argv); Sleep(100); // prevent the errors from occurring too fast } } AfterOpenSuccess((int)data->fd, data->dataCallback, data->disconnectedCallback, data->errorCallback); cleanup: data->dataCallback.Dispose(); data->errorCallback.Dispose(); delete data; delete req; }
void EIO_AfterWatchPort(uv_work_t* req) { NanScope(); WatchPortBaton* data = static_cast<WatchPortBaton*>(req->data); if(data->disconnected) { data->disconnectedCallback->Call(0, NULL); DisposeWatchPortCallbacks(data); goto cleanup; } if(data->bytesRead > 0) { v8::Handle<v8::Value> argv[1]; argv[0] = NanNewBufferHandle(data->buffer, data->bytesRead); data->dataCallback->Call(1, argv); } else if(data->errorCode > 0) { if(data->errorCode == ERROR_INVALID_HANDLE && IsClosingHandle((int)data->fd)) { DisposeWatchPortCallbacks(data); goto cleanup; } else { v8::Handle<v8::Value> argv[1]; argv[0] = v8::Exception::Error(v8::String::New(data->errorString)); data->errorCallback->Call(1, argv); Sleep(100); // prevent the errors from occurring too fast } } AfterOpenSuccess((int)data->fd, data->dataCallback, data->disconnectedCallback, data->errorCallback); cleanup: delete data; delete req; }
void EIO_AfterUpdate(uv_work_t* req) { NanScope(); OpenBaton* data = static_cast<OpenBaton*>(req->data); v8::Handle<v8::Value> argv[2]; if(data->errorString[0]) { argv[0] = v8::Exception::Error(NanNew<v8::String>(data->errorString)); argv[1] = NanUndefined(); // not needed for AfterOpenSuccess delete data->dataCallback; delete data->errorCallback; delete data->disconnectedCallback; } else { argv[0] = NanUndefined(); argv[1] = NanNew<v8::Int32>(data->result); int fd = argv[1]->ToInt32()->Int32Value(); newQForFD(fd); AfterOpenSuccess(data->result, data->dataCallback, data->disconnectedCallback, data->errorCallback); } data->callback->Call(2, argv); delete data->platformOptions; delete data->callback; delete data; delete req; }
void EIO_AfterOpen(uv_work_t* req) { OpenBaton* data = static_cast<OpenBaton*>(req->data); v8::Handle<v8::Value> argv[2]; if(data->errorString[0]) { argv[0] = v8::Exception::Error(v8::String::New(data->errorString)); argv[1] = v8::Undefined(); } else { argv[0] = v8::Undefined(); argv[1] = v8::Int32::New(data->result); AfterOpenSuccess(data->result, data->dataCallback, data->disconnectedCallback, data->errorCallback); } v8::Function::Cast(*data->callback)->Call(v8::Context::GetCurrent()->Global(), 2, argv); data->callback.Dispose(); delete data; delete req; }