static void poll_fd_events_stop_watches(PollEvents *s) { PollFdEvents *self = (PollFdEvents *) s; if (iv_fd_registered(&self->fd_watch)) iv_fd_unregister(&self->fd_watch); }
static gboolean afsocket_dd_connected(AFSocketDestDriver *self) { gchar buf1[256], buf2[256]; int error = 0; socklen_t errorlen = sizeof(error); LogTransport *transport; LogProtoClient *proto; main_loop_assert_main_thread(); if (iv_fd_registered(&self->connect_fd)) iv_fd_unregister(&self->connect_fd); if (self->transport_mapper->sock_type == SOCK_STREAM) { if (getsockopt(self->fd, SOL_SOCKET, SO_ERROR, &error, &errorlen) == -1) { msg_error("getsockopt(SOL_SOCKET, SO_ERROR) failed for connecting socket", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, errno), evt_tag_int("time_reopen", self->time_reopen), NULL); goto error_reconnect; } if (error) { msg_error("Syslog connection failed", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, error), evt_tag_int("time_reopen", self->time_reopen), NULL); goto error_reconnect; } } msg_notice("Syslog connection established", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_str("local", g_sockaddr_format(self->bind_addr, buf1, sizeof(buf1), GSA_FULL)), NULL); transport = afsocket_dd_construct_transport(self, self->fd); if (!transport) goto error_reconnect; proto = log_proto_client_factory_construct(self->proto_factory, transport, &self->writer_options.proto_options.super); log_writer_reopen(self->writer, proto); return TRUE; error_reconnect: close(self->fd); self->fd = -1; afsocket_dd_start_reconnect_timer(self); return FALSE; }
static void log_reader_stop_watches(LogReader *self) { if (iv_fd_registered(&self->fd_watch)) iv_fd_unregister(&self->fd_watch); if (iv_timer_registered(&self->follow_timer)) iv_timer_unregister(&self->follow_timer); if (iv_task_registered(&self->restart_task)) iv_task_unregister(&self->restart_task); }
static void done(struct req *req, int timeout) { iv_popen_request_close(&req->popen_req); iv_fd_unregister(&req->popen_fd); close(req->popen_fd.fd); if (!timeout) iv_timer_unregister(&req->closeit); }
void control_server_unix_free(ControlServer *s) { ControlServerUnix *self = (ControlServerUnix *)s; if (iv_fd_registered(&self->control_listen)) { iv_fd_unregister(&self->control_listen); } if (self->control_socket != -1) { close(self->control_socket); } }
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; }
static void afsocket_dd_stop_watches(AFSocketDestDriver *self) { main_loop_assert_main_thread(); if (iv_fd_registered(&self->connect_fd)) { iv_fd_unregister(&self->connect_fd); /* need to close the fd in this case as it wasn't established yet */ msg_verbose("Closing connecting fd", evt_tag_int("fd", self->fd)); close(self->fd); } if (iv_timer_registered(&self->reconnect_timer)) iv_timer_unregister(&self->reconnect_timer); }
static void log_writer_stop_watches(LogWriter *self) { if (self->watches_running) { if (iv_timer_registered(&self->suspend_timer)) iv_timer_unregister(&self->suspend_timer); if (iv_fd_registered(&self->fd_watch)) iv_fd_unregister(&self->fd_watch); if (iv_task_registered(&self->immed_io_task)) iv_task_unregister(&self->immed_io_task); log_queue_reset_parallel_push(self->queue); self->watches_running = FALSE; } }
static void abort_me(struct http_client_request *req, int close_fd, int callback) { // @@@ cancel hostname lookup if (req->hostname_lookup_callback_scheduled) iv_task_unregister(&req->hostname_lookup); free(req->redirect); free(req->redirect_last); if (req->fd.fd != -1) { iv_fd_unregister(&req->fd); if (close_fd) { close(req->fd.fd); req->fd.fd = -1; } } if (callback) req->handler(req->cookie); }
static void afsocket_sd_stop_watches(AFSocketSourceDriver *self) { if (iv_fd_registered (&self->listen_fd)) iv_fd_unregister(&self->listen_fd); }
static void got_data(void *_req) { struct http_client_request *req = (struct http_client_request *)_req; int bytes_left; char *ptr; int size; ptr = req->rcvbuf + req->read_ptr; size = sizeof(req->rcvbuf) - req->read_ptr; bytes_left = recv(req->fd.fd, ptr, size, MSG_PEEK); if (bytes_left == 0) { req->state = ECONNABORTED; abort_me(req, 1, 1); return; } if (bytes_left < 0) { if (errno != EAGAIN) { req->state = errno; abort_me(req, 1, 1); } return; } req->read_ptr += bytes_left; process_data(req); if (req->state == EINPROGRESS) return; // @@@ check http status code too? if (req->state == 0 && req->redirect != NULL) { char *host; int port; char *url; if (!req->recursion_limit--) { req->state = ELOOP; abort_me(req, 1, 1); return; } if (split_url(req->redirect, &host, &port, &url) < 0) { req->state = EINVAL; abort_me(req, 1, 1); return; } req->redirect_hostname = host; req->redirect_port = port; req->redirect_url = url; free(req->redirect_last); req->redirect_last = req->redirect; req->redirect = NULL; iv_fd_unregister(&req->fd); close(req->fd.fd); req->fd.fd = -1; req->state = EINPROGRESS; start_hostname_lookup(req); return; } abort_me(req, !!req->state, 1); }
static void control_connection_stop_watches(ControlConnection *self) { iv_fd_unregister(&self->control_io); }
static gboolean afsocket_dd_connected(AFSocketDestDriver *self) { gchar buf1[256], buf2[256]; int error = 0; socklen_t errorlen = sizeof(error); LogTransport *transport; LogProto *proto; guint32 transport_flags = 0; main_loop_assert_main_thread(); if (iv_fd_registered(&self->connect_fd)) iv_fd_unregister(&self->connect_fd); if (self->flags & AFSOCKET_STREAM) { transport_flags |= LTF_SHUTDOWN; if (getsockopt(self->fd, SOL_SOCKET, SO_ERROR, &error, &errorlen) == -1) { msg_error("getsockopt(SOL_SOCKET, SO_ERROR) failed for connecting socket", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, errno), evt_tag_int("time_reopen", self->time_reopen), NULL); goto error_reconnect; } if (error) { msg_error("Syslog connection failed", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_errno(EVT_TAG_OSERROR, error), evt_tag_int("time_reopen", self->time_reopen), NULL); goto error_reconnect; } } msg_notice("Syslog connection established", evt_tag_int("fd", self->fd), evt_tag_str("server", g_sockaddr_format(self->dest_addr, buf2, sizeof(buf2), GSA_FULL)), evt_tag_str("local", g_sockaddr_format(self->bind_addr, buf1, sizeof(buf1), GSA_FULL)), NULL); #if ENABLE_SSL if (self->tls_context) { TLSSession *tls_session; tls_session = tls_context_setup_session(self->tls_context); if (!tls_session) { goto error_reconnect; } tls_session_set_verify(tls_session, afsocket_dd_tls_verify_callback, self, NULL); transport = log_transport_tls_new(tls_session, self->fd, transport_flags); } else #endif transport = log_transport_plain_new(self->fd, transport_flags); if (self->flags & AFSOCKET_SYSLOG_PROTOCOL) { if (self->flags & AFSOCKET_STREAM) proto = log_proto_framed_client_new(transport); else proto = log_proto_text_client_new(transport); } else { proto = log_proto_text_client_new(transport); } log_writer_reopen(self->writer, proto); return TRUE; error_reconnect: close(self->fd); self->fd = -1; afsocket_dd_start_reconnect_timer(self); return FALSE; }
void control_connection_stop_watches(ControlConnection *s) { ControlConnectionUnix *self = (ControlConnectionUnix *)s; iv_fd_unregister(&self->control_io); }