static PyObject * Idle_func_start(Idle *self, PyObject *args) { int err; PyObject *tmp, *callback; tmp = NULL; RAISE_IF_HANDLE_NOT_INITIALIZED(self, NULL); RAISE_IF_HANDLE_CLOSED(self, PyExc_HandleClosedError, NULL); if (!PyArg_ParseTuple(args, "O:start", &callback)) { return NULL; } if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "a callable is required"); return NULL; } err = uv_idle_start(&self->idle_h, pyuv__idle_cb); if (err < 0) { RAISE_UV_EXCEPTION(err, PyExc_IdleError); return NULL; } tmp = self->callback; Py_INCREF(callback); self->callback = callback; Py_XDECREF(tmp); PYUV_HANDLE_INCREF(self); Py_RETURN_NONE; }
static void(loop_stop)() { uv_stop(loop); uv_idle_t* idle = s_malloc0(sizeof(*idle)); uv_idle_init(loop, idle); uv_idle_start(idle, loop_stop_cb); }
static void check_cb(uv_check_t* handle, int status) { int i, r; LOG("CHECK_CB\n"); ASSERT(handle == &check_handle); ASSERT(status == 0); if (loop_iteration < ITERATIONS) { /* Make some idle watchers active */ for (i = 0; i < 1 + (loop_iteration % IDLE_COUNT); i++) { r = uv_idle_start(&idle_1_handles[i], idle_1_cb); ASSERT(r == 0); idles_1_active++; } } else { /* End of the test - close all handles */ uv_close((uv_handle_t*)&prepare_1_handle, prepare_1_close_cb); uv_close((uv_handle_t*)&check_handle, check_close_cb); uv_close((uv_handle_t*)&prepare_2_handle, prepare_2_close_cb); for (i = 0; i < IDLE_COUNT; i++) { uv_close((uv_handle_t*)&idle_1_handles[i], idle_1_close_cb); } /* This handle is closed/recreated every time, close it only if it is */ /* active.*/ if (idle_2_is_active) { uv_close((uv_handle_t*)&idle_2_handle, idle_2_close_cb); } } check_cb_called++; }
static void idle_1_cb(uv_handle_t* handle, int status) { int r; LOG("IDLE_1_CB\n"); ASSERT(handle != NULL); ASSERT(status == 0); ASSERT(idles_1_active > 0); /* Init idle_2 and make it active */ if (!idle_2_is_active) { r = uv_idle_init(&idle_2_handle, idle_2_close_cb, NULL); ASSERT(r == 0); r = uv_idle_start(&idle_2_handle, idle_2_cb); ASSERT(r == 0); idle_2_is_active = 1; idle_2_cb_started++; } idle_1_cb_called++; if (idle_1_cb_called % 5 == 0) { r = uv_idle_stop((uv_idle_t*)handle); ASSERT(r == 0); idles_1_active--; } }
static void frame_event_cb(cg_onscreen_t *onscreen, cg_frame_event_t event, cg_frame_info_t *info, void *data) { if (event == CG_FRAME_EVENT_SYNC) { struct demo *demo = data; uv_idle_start(&demo->idle, paint_cb); } }
int main() { uv_loop_t* loop = uv_default_loop(); uv_idle_t handler = idleHandler(loop); uv_idle_start(&handler, callback); uv_run(loop, UV_RUN_DEFAULT); uv_loop_close(loop); return 0; }
/// Starts watching for events from a `RStream` instance. /// /// @param rstream The `RStream` instance void rstream_start(RStream *rstream) { if (rstream->file_type == UV_FILE) { uv_idle_start(rstream->fread_idle, fread_idle_cb); } else { uv_read_start(rstream->stream, alloc_cb, read_cb); } }
static void next_tick(uv_idle_t* handle, int status) { uv_loop_t* loop = handle->loop; uv_idle_stop(handle); uv_idle_init(loop, &idle_handle); uv_idle_start(&idle_handle, idle_cb); uv_timer_init(loop, &timer_handle); uv_timer_start(&timer_handle, timer_cb, 0, 0); }
rust_uvtmp_thread() { task = rust_scheduler::get_task(); stop_flag = false; loop = uv_loop_new(); uv_idle_init(loop, &idle); idle.data = this; uv_idle_start(&idle, idle_cb); }
static int luv_idle_start(lua_State* L) { uv_idle_t* handle = luv_check_idle(L, 1); int ret; luv_check_callback(L, (luv_handle_t *)handle->data, LUV_IDLE, 2); ret = uv_idle_start(handle, luv_idle_cb); if (ret < 0) return luv_error(L, ret); lua_pushinteger(L, ret); return 1; }
void run_UVloop(void *arg) { uv_idle_t idler; uv_idle_init(UV_loop,&idler); //uv_async_init(UV_loop,&Tasks_async,async_handler); uv_idle_start(&idler,SuperNET_idler); uv_run(UV_loop,UV_RUN_DEFAULT); printf("end of uv_run\n"); }
void wait_for_next_input() { int r; // Note: the example in the uvbook contains a small mistake IMO since it's reading from fd: 1 which is stdout, // however it works either way r = uv_fs_read(loop, &stdin_watcher, STDIN, buffer, 1024, -1, stdin_fs_cb); if (r) ERROR("reading stdin", r); r = uv_idle_start(&idler, idle_cb); if (r) ERROR("starting idler", r); }
static void enter_loop(MVMThreadContext *tc, MVMCallsite *callsite, MVMRegister *args) { uv_idle_t idle; if (uv_idle_init(tc->loop, &idle) != 0) MVM_panic(1, "Unable to initialize idle worker for event loop"); idle.data = tc; if (uv_idle_start(&idle, idle_handler) != 0) MVM_panic(1, "Unable to start idle worker for event loop"); uv_run(tc->loop, UV_RUN_DEFAULT); MVM_panic(1, "Supposedly unending event loop thread ended"); }
/** @internal Schedule deferred continuation. */ static int l_ffi_defer(lua_State *L) { uv_idle_t *check = malloc(sizeof(*check)); if (!check) { return kr_error(ENOMEM); } uv_idle_init(uv_default_loop(), check); check->data = L; return uv_idle_start(check, l_ffi_resume_cb); }
int main() { uv_idle_t idler; uv_idle_init(uv_default_loop(), &idler); uv_idle_start(&idler, wait_for_a_while); printf("Idling...\n"); uv_run(uv_default_loop(), UV_RUN_DEFAULT); return 0; }
static int64_t HHVM_METHOD(UVIdle, start, const Variant &idle_cb) { auto* data = Native::data<UVNativeData>(this_); uv_idle_ext_t *idle_handle = fetchResource(data); data->callback = idle_cb; int64_t ret = uv_idle_start(idle_handle, (uv_idle_cb) idle_handle_callback); if(ret == 0){ idle_handle->start = true; idle_handle->idle_object_data = this_; this_->incRefCount(); } return ret; }
int main() { uv_idle_t idler; uv_idle_init(get_loop(), &idler); uv_idle_start(&idler, wait_for_a_while); printf("Now quitting.\n"); uv_run(get_loop(), UV_RUN_DEFAULT); return 0; }
int main(int argc, char **argv) { uv_idle_t idler; uv_idle_init(uv_default_loop(), &idler); uv_idle_start(&idler, waitForAWhile); printf(".. idling..."); uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_loop_close(uv_default_loop()); return 0; }
int main(int argc, char **argv) { cg_onscreen_t *onscreen; cg_error_t *error = NULL; struct demo demo; float fovy, aspect, z_near, z_2d, z_far; uv_loop_t *loop = uv_default_loop(); demo.dev = cg_device_new (); if (!demo.dev || error != NULL) c_error("Failed to create Cogl context\n"); onscreen = cg_onscreen_new(demo.dev, WIDTH, HEIGHT); demo.fb = onscreen; demo.width = cg_framebuffer_get_width(demo.fb); demo.height = cg_framebuffer_get_height(demo.fb); cg_onscreen_show(onscreen); cg_framebuffer_set_viewport(demo.fb, 0, 0, demo.width, demo.height); fovy = 45; aspect = (float)demo.width / (float)demo.height; z_near = 0.1; z_2d = 1000; z_far = 2000; cg_framebuffer_perspective(demo.fb, fovy, aspect, z_near, z_far); c_matrix_init_identity(&demo.view); c_matrix_view_2d_in_perspective(&demo.view, fovy, aspect, z_near, z_2d, demo.width, demo.height); cg_framebuffer_set_modelview_matrix(demo.fb, &demo.view); demo.swap_ready = true; cg_onscreen_add_frame_callback(demo.fb, frame_event_cb, &demo, NULL); init_particle_emitters(&demo); demo.timer = c_timer_new(); demo.spin_rate = 0; demo.angle_between_emitters = 2 * M_PI / C_N_ELEMENTS(demo.emitter); uv_idle_init(loop, &demo.idle); demo.idle.data = &demo; uv_idle_start(&demo.idle, paint_cb); cg_uv_set_mainloop(demo.dev, loop); uv_run(loop, UV_RUN_DEFAULT); return 0; }
unsigned int lcbuv_close_socket(lcb_io_opt_t iobase, lcb_sockdata_t *sockbase) { dCOMMON_VARS(iobase, sockbase) uv_idle_t *idle = calloc(1, sizeof(*idle)); assert(sock->lcb_close_called == 0); sock->lcb_close_called = 1; idle->data = sock; uv_idle_init(io->loop, idle); uv_idle_start(idle, socket_closing_cb); (void)io; return 0; }
int main(int argc, char* argv[]) { uv_idle_t idle; uv_loop_t* loop = uv_default_loop(); uv_idle_init(loop, &idle); uv_idle_start(&idle, idle_routine); fprintf(stdout, "[%lu]Idling begin ...\n", clock()); uv_run(loop, UV_RUN_DEFAULT); fprintf(stdout, "[%lu]Idling finish ...\n", clock()); return 0; }
static void run(void) { uv_idle_t runner; uv_idle_init(uv_default_loop(), &runner); uv_idle_start(&runner, do_run); uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_loop_close(uv_default_loop()); log_info(LOG, "Client stopped."); automaton->free(automaton); ch->free(ch); cgi_channel->free(cgi_channel); mh->free(mh); zmq_channel->free(zmq_channel); }
static unsigned int close_socket(lcb_io_opt_t iobase, lcb_sockdata_t *sockbase) { my_sockdata_t *sock = (my_sockdata_t *)sockbase; my_iops_t *io = (my_iops_t *)iobase; uv_idle_t *idle = calloc(1, sizeof(*idle)); lcb_assert(sock->lcb_close_called == 0); sock->lcb_close_called = 1; idle->data = sock; uv_idle_init(io->loop, idle); uv_idle_start(idle, socket_closing_cb); return 0; }
int main() { uv_idle_t idler; LOG = circus_new_log_file_descriptor(stdlib_memory, LOG_INFO, 1); uv_idle_init(uv_default_loop(), &idler); uv_idle_start(&idler, wait_for_a_while); LOG->set_format(LOG, "[%T] %O:%G\n"); uv_run(uv_default_loop(), UV_RUN_DEFAULT); uv_loop_close(uv_default_loop()); LOG->free(LOG); return 0; }
static void lws_io_cb(uv_poll_t *watcher, int status, int revents) { struct lws_io_watcher *lws_io = lws_container_of(watcher, struct lws_io_watcher, uv_watcher); struct lws *wsi = lws_container_of(lws_io, struct lws, w_read); struct lws_context *context = wsi->context; struct lws_pollfd eventfd; #if defined(WIN32) || defined(_WIN32) eventfd.fd = watcher->socket; #else eventfd.fd = watcher->io_watcher.fd; #endif eventfd.events = 0; eventfd.revents = 0; if (status < 0) { /* * At this point status will be an UV error, like UV_EBADF, * we treat all errors as LWS_POLLHUP * * You might want to return; instead of servicing the fd in * some cases */ if (status == UV_EAGAIN) return; eventfd.events |= LWS_POLLHUP; eventfd.revents |= LWS_POLLHUP; } else { if (revents & UV_READABLE) { eventfd.events |= LWS_POLLIN; eventfd.revents |= LWS_POLLIN; } if (revents & UV_WRITABLE) { eventfd.events |= LWS_POLLOUT; eventfd.revents |= LWS_POLLOUT; } } lws_service_fd(context, &eventfd); uv_idle_start(&context->pt[(int)wsi->tsi].uv_idle, lws_uv_idle); }
int main() { /* our reference to the default loop */ uv_loop_t *loop; /* a idler of uv_idle_t struct type */ uv_idle_t idler; /* let uv return the default loop */ loop = uv_default_loop(); /* initialize a idle handle with the default loop and the reference of our idle type */ uv_idle_init(loop, &idler); /* start executing the idle handler and call the wait_for_a_while callback */ uv_idle_start(&idler, wait_for_a_while); printf("Idling ...\n"); /* start runing the loop in default mode */ uv_run(loop, UV_RUN_DEFAULT); }
static void send_error(lcb_io_opt_t iobase, lcb_sockdata_t *sockbase, lcb_io_error_cb callback) { my_sockdata_t *sock = (my_sockdata_t *)sockbase; my_iops_t *io = (my_iops_t *)iobase; my_uvreq_t *uvr; if (!sock) { return; } uvr = alloc_uvreq(sock, (generic_callback_t)callback); if (!uvr) { return; } uv_idle_init(io->loop, &uvr->uvreq.idle); uv_idle_start(&uvr->uvreq.idle, err_idle_cb); incref_sock(sock); }
int main() { uv_idle_t idler; uv_loop_t *loop = uv_default_loop(); // 初始化 idle handle uv_idle_init(loop, &idler); // 启用 idle handle 并传入回调 uv_idle_start(&idler, wait_for_a_while); printf("Idling... \n"); // ========================================== // http://docs.libuv.org/en/v1.x/loop.html // ========================================== // int uv_run(uv_loop_t* loop, uv_run_mode mode) // This function runs the event loop. It will act differently depending on the specified mode: // UV_RUN_DEFAULT: Runs the event loop until there are no more active and referenced handles or requests. // Returns non-zero if uv_stop() was called and there are still active handles or requests. Returns zero in all other cases. // // UV_RUN_ONCE: Poll for i/o once. Note that this function blocks if there are no pending callbacks. // Returns zero when done (no active handles or requests left), or non-zero if more callbacks // are expected (meaning you should run the event loop again sometime in the future). // // UV_RUN_NOWAIT: Poll for i/o once but don’t block if there are no pending callbacks. // Returns zero if done (no active handles or requests left), or non-zero if more callbacks // are expected (meaning you should run the event loop again sometime in the future). // 开始轮询,直到该loop中没有活动的引用 // 在此例中,当uv_idle_stop(handle)调用后,所有的活动执行完成 // 此时将会停止loop uv_run(loop, UV_RUN_DEFAULT); // 关闭轮询 // Releases all internal loop resources. uv_loop_close(loop); return 0; }
/* for libuv */ static void on_uv_timer_cb(uv_timer_t * handle) { sg_etp_session_t * session = handle->data; IUINT32 now = 0; /*LOG_D("update %d", client->conv);*/ /* update ikcp */ now = (IUINT32)uv_now(session->loop); sg_etp_update_speed((sg_etp_t *)session, now); if (now >= session->kcp_update_time) { ikcp_update(session->kcp, now); session->kcp_update_time = ikcp_check(session->kcp, now); LOG_D("update %lu @ %lu, timeout: %lu", session->conv, session->kcp_update_time, session->recv_data_time); /* check received data and add to work queue */ //recv_data_check(session); if (ikcp_peeksize(session->kcp) > 0) { uv_idle_start(&(session->idle), on_uv_idle_cb); } } /* check if session is timeout */ if (session->recv_data_time < now) { session->to_close = true; /* mark to close this session. */ ikcp_flush(session->kcp); LOG_I("session %lu timeout, will be closed", session->conv); } /* check if should close this session */ if (session->to_close) { sg_etp_session_close(session); } }
void uv_eio_init(uv_loop_t* loop) { if (loop->flags & UV_LOOP_EIO_INITIALIZED) return; loop->flags |= UV_LOOP_EIO_INITIALIZED; uv_idle_init(loop, &loop->uv_eio_poller); uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll); loop->uv_eio_poller.flags |= UV__HANDLE_INTERNAL; loop->uv_eio_want_poll_notifier.data = loop; uv_async_init(loop, &loop->uv_eio_want_poll_notifier, uv_eio_want_poll_notifier_cb); loop->uv_eio_want_poll_notifier.flags |= UV__HANDLE_INTERNAL; uv__handle_unref(&loop->uv_eio_want_poll_notifier); uv_async_init(loop, &loop->uv_eio_done_poll_notifier, uv_eio_done_poll_notifier_cb); loop->uv_eio_done_poll_notifier.flags |= UV__HANDLE_INTERNAL; uv__handle_unref(&loop->uv_eio_done_poll_notifier); uv_once(&uv__eio_init_once_guard, uv__eio_init); }