static void log_writer_start_watches(LogWriter *self) { gint fd; GIOCondition cond; if (!self->watches_running) { log_proto_prepare(self->proto, &fd, &cond); if (self->pollable_state < 0) { if (is_file_regular(fd)) self->pollable_state = 0; else self->pollable_state = iv_fd_pollable(fd); } if (self->pollable_state) { self->fd_watch.fd = fd; iv_fd_register(&self->fd_watch); } log_writer_update_watches(self); self->watches_running = TRUE; } }
static void poll_fd_events_start_watches(PollEvents *s) { PollFdEvents *self = (PollFdEvents *) s; iv_fd_register(&self->fd_watch); }
static void log_writer_start_watches(LogWriter *self) { gint fd; GIOCondition cond; if (self->watches_running) return; log_proto_client_prepare(self->proto, &fd, &cond); self->fd_watch.fd = fd; if (self->pollable_state < 0) { if (is_file_regular(fd)) self->pollable_state = 0; else self->pollable_state = !iv_fd_register_try(&self->fd_watch); } else if (self->pollable_state > 0) iv_fd_register(&self->fd_watch); log_writer_update_watches(self); self->watches_running = TRUE; }
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_dd_start_watches(AFSocketDestDriver *self) { main_loop_assert_main_thread(); self->connect_fd.fd = self->fd; iv_fd_register(&self->connect_fd); }
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(&self->control_io); control_connection_update_watches(self); }
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); }
/* NOTE: the return value is only used during initialization, and it is not * expected that it'd change once it returns success */ static gboolean log_reader_start_watches(LogReader *self) { gint fd; GIOCondition cond; log_proto_prepare(self->proto, &fd, &cond); if (self->options->follow_freq > 0) { /* follow freq specified (only the file source does that, go into timed polling */ /* NOTE: the fd may not be set here, as it may not have been opened yet */ iv_timer_register(&self->follow_timer); } else if (fd < 0) { msg_error("In order to poll non-yet-existing files, follow_freq() must be set", NULL); return FALSE; } else { /* we have an FD, it is possible to poll it, register it */ self->fd_watch.fd = fd; if (self->pollable_state < 0) { if (iv_fd_register_try(&self->fd_watch) == 0) self->pollable_state = 1; else self->pollable_state = 0; } else if (self->pollable_state > 0) { iv_fd_register(&self->fd_watch); } else { msg_error("Unable to determine how to monitor this fd, follow_freq() not set and it is not possible to poll it with the current ivykis polling method, try changing IV_EXCLUDE_POLL_METHOD environment variable", evt_tag_int("fd", fd), NULL); return FALSE; } } log_reader_update_watches(self); return TRUE; }
void control_server_start(ControlServer *s) { ControlServerUnix *self = (ControlServerUnix *)s; GSockAddr *saddr; saddr = g_sockaddr_unix_new(self->super.control_socket_name); self->control_socket = socket(PF_UNIX, SOCK_STREAM, 0); if (self->control_socket == -1) { msg_error("Error opening control socket, external controls will not be available", evt_tag_str("socket", self->super.control_socket_name), NULL); return; } if (g_bind(self->control_socket, saddr) != G_IO_STATUS_NORMAL) { msg_error("Error opening control socket, bind() failed", evt_tag_str("socket", self->super.control_socket_name), evt_tag_errno("error", errno), NULL); goto error; } if (listen(self->control_socket, 255) < 0) { msg_error("Error opening control socket, listen() failed", evt_tag_str("socket", self->super.control_socket_name), evt_tag_errno("error", errno), NULL); goto error; } self->control_listen.fd = self->control_socket; self->control_listen.cookie = self; iv_fd_register(&self->control_listen); iv_fd_set_handler_in(&self->control_listen, control_socket_accept); g_sockaddr_unref(saddr); return; error: if (self->control_socket != -1) { close(self->control_socket); self->control_socket = -1; } g_sockaddr_unref(saddr); return; }
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); }
static void hostname_lookup_done(void *_req) { struct http_client_request *req = (struct http_client_request *)_req; struct sockaddr_in addr; int ret; int fd; req->hostname_lookup_callback_scheduled = 0; if (req->resolved_ip.s_addr == htonl(0xffffffff)) { req->state = ENOENT; abort_me(req, 1, 1); return; } fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { req->state = errno; abort_me(req, 0, 1); return; } req->fd.fd = fd; req->fd.cookie = (void *)req; req->fd.handler_in = connect_done; req->fd.handler_out = connect_done; iv_fd_register(&req->fd); addr.sin_family = AF_INET; addr.sin_port = htons(req->redirect_port); addr.sin_addr = req->resolved_ip; ret = connect(req->fd.fd, (struct sockaddr *)&addr, sizeof(addr)); if (ret == 0) { connect_successful(req); return; } if (errno != EINPROGRESS) { req->state = errno; abort_me(req, 1, 1); } }
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")); }