static void log_reader_init_watches(LogReader *self) { gint fd; GIOCondition cond; log_proto_prepare(self->proto, &fd, &cond); IV_FD_INIT(&self->fd_watch); self->fd_watch.cookie = self; IV_TIMER_INIT(&self->follow_timer); self->follow_timer.cookie = self; self->follow_timer.handler = log_reader_io_follow_file; IV_TASK_INIT(&self->restart_task); self->restart_task.cookie = self; self->restart_task.handler = log_reader_io_process_input; IV_EVENT_INIT(&self->schedule_wakeup); self->schedule_wakeup.cookie = self; self->schedule_wakeup.handler = log_reader_wakeup_triggered; main_loop_io_worker_job_init(&self->io_job); self->io_job.user_data = self; self->io_job.work = (void (*)(void *)) log_reader_work_perform; self->io_job.completion = (void (*)(void *)) log_reader_work_finished; }
static void open_child_request(struct req *req) { int f; IV_POPEN_REQUEST_INIT(&req->popen_req); req->popen_req.file = "/usr/bin/vmstat"; req->argv[0] = "/usr/bin/vmstat"; req->argv[1] = "1"; req->argv[2] = NULL; req->popen_req.argv = req->argv; req->popen_req.type = "r"; f = iv_popen_request_submit(&req->popen_req); printf("submitted the popen request, fd is %d\n", f); IV_FD_INIT(&req->popen_fd); req->popen_fd.fd = f; req->popen_fd.cookie = req; req->popen_fd.handler_in = got_data; iv_fd_register(&req->popen_fd); IV_TIMER_INIT(&req->closeit); iv_validate_now(); req->closeit.expires = iv_now; req->closeit.expires.tv_sec += 5; req->closeit.cookie = req; req->closeit.handler = do_close; iv_timer_register(&req->closeit); }
static void afsocket_sd_start_watches(AFSocketSourceDriver *self) { IV_FD_INIT(&self->listen_fd); self->listen_fd.fd = self->fd; self->listen_fd.cookie = self; self->listen_fd.handler_in = afsocket_sd_accept; iv_fd_register(&self->listen_fd); }
static void control_connection_start_watches(ControlConnection *self, gint sock) { IV_FD_INIT(&self->control_io); self->control_io.cookie = self; self->control_io.fd = sock; iv_fd_register_try(&self->control_io); control_connection_update_watches(self); }
ControlServer * control_server_new(const gchar *path, Commands *commands) { ControlServerUnix *self = g_new(ControlServerUnix,1); control_server_init_instance(&self->super, path, commands); IV_FD_INIT(&self->control_listen); self->super.free_fn = control_server_unix_free; return &self->super; }
static void afsocket_dd_init_watches(AFSocketDestDriver *self) { IV_FD_INIT(&self->connect_fd); self->connect_fd.cookie = self; self->connect_fd.handler_out = (void (*)(void *)) afsocket_dd_connected; IV_TIMER_INIT(&self->reconnect_timer); self->reconnect_timer.cookie = self; self->reconnect_timer.handler = (void (*)(void *)) afsocket_dd_reconnect; }
void control_connection_start_watches(ControlConnection *s) { ControlConnectionUnix *self = (ControlConnectionUnix *)s; IV_FD_INIT(&self->control_io); self->control_io.cookie = self; self->control_io.fd = self->fd; iv_fd_register(&self->control_io); control_connection_update_watches(s); }
static void afsocket_dd_init_watches(AFSocketDestDriver *self) { IV_FD_INIT(&self->connect_fd); self->connect_fd.cookie = self; self->connect_fd.handler_out = (void (*)(void *)) afsocket_dd_connected; IV_TIMER_INIT(&self->reconnect_timer); self->reconnect_timer.cookie = self; /* Using reinit as a handler before establishing the first successful connection. * We'll change this to afsocket_dd_reconnect when the initialization of the * connection succeeds.*/ self->reconnect_timer.handler = (void (*)(void *)) afsocket_dd_try_connect; }
static gboolean _is_fd_pollable(gint fd) { struct iv_fd check_fd; gboolean pollable; IV_FD_INIT(&check_fd); check_fd.fd = fd; check_fd.cookie = NULL; pollable = (iv_fd_register_try(&check_fd) == 0); if (pollable) iv_fd_unregister(&check_fd); return pollable; }
void control_init(const gchar *control_name) { GSockAddr *saddr; saddr = g_sockaddr_unix_new(control_name); control_socket = socket(PF_UNIX, SOCK_STREAM, 0); if (control_socket == -1) { msg_error("Error opening control socket, external controls will not be available", evt_tag_str("socket", control_name), NULL); return; } if (g_bind(control_socket, saddr) != G_IO_STATUS_NORMAL) { msg_error("Error opening control socket, bind() failed", evt_tag_str("socket", control_name), evt_tag_errno("error", errno), NULL); goto error; } if (listen(control_socket, 255) < 0) { msg_error("Error opening control socket, listen() failed", evt_tag_str("socket", control_name), evt_tag_errno("error", errno), NULL); goto error; } IV_FD_INIT(&control_listen); control_listen.fd = control_socket; control_listen.handler_in = control_socket_accept; iv_fd_register(&control_listen); g_sockaddr_unref(saddr); return; error: if (control_socket != -1) { close(control_socket); control_socket = -1; } g_sockaddr_unref(saddr); }
PollEvents * poll_fd_events_new(gint fd) { PollFdEvents *self = g_new0(PollFdEvents, 1); g_assert(fd >= 0); self->super.start_watches = poll_fd_events_start_watches; self->super.stop_watches = poll_fd_events_stop_watches; self->super.update_watches = poll_fd_events_update_watches; IV_FD_INIT(&self->fd_watch); self->fd_watch.fd = fd; self->fd_watch.cookie = self; return &self->super; }
void http_client_request_start(struct http_client_request *req) { req->state = EINPROGRESS; req->hostname_lookup_callback_scheduled = 0; IV_TASK_INIT(&req->hostname_lookup); req->hostname_lookup.cookie = (void *)req; req->hostname_lookup.handler = hostname_lookup_done; req->redirect = NULL; req->redirect_last = NULL; req->redirect_hostname = req->hostname; req->redirect_port = req->port; req->redirect_url = req->url; req->recursion_limit = 10; IV_FD_INIT(&req->fd); req->fd.fd = -1; start_hostname_lookup(req); }
void __test_fd_handling(Journald *journald) { gint fd = journald_get_fd(journald); journald_process(journald); task_called = FALSE; poll_triggered = FALSE; struct iv_task add_entry_task; struct iv_fd fd_to_poll; struct iv_timer stop_timer; IV_TASK_INIT(&add_entry_task); add_entry_task.cookie = journald; add_entry_task.handler = add_mock_entries; IV_FD_INIT(&fd_to_poll); fd_to_poll.fd = fd; fd_to_poll.cookie = journald; fd_to_poll.handler_in = handle_new_entry; iv_validate_now(); IV_TIMER_INIT(&stop_timer); stop_timer.cookie = NULL; stop_timer.expires = iv_now; stop_timer.expires.tv_sec++; stop_timer.handler = stop_timer_expired; iv_task_register(&add_entry_task); iv_fd_register(&fd_to_poll); iv_timer_register(&stop_timer); iv_main(); assert_true(poll_triggered, ASSERTION_ERROR("Poll event isn't triggered")); }