void io_zcluster_status_test_t::run() { int c = 0; while(true) { string_t status = string_t::ctor_t(16).print(c++); cluster_status_.update(status); interval_t to_sleep = (random_U() % 10) * interval_second; if(bq_sleep(&to_sleep) < 0) { throw exception_sys_t(log::error, errno, "bq_sleep: %m"); } } }
void io_logger_file_t::run() const { while(true) { interval_t t = check_interval; log_debug("tick"); if(bq_sleep(&t) < 0) throw exception_sys_t(log::error, errno, "bq_sleep: %m"); check(); } }
void link_t::loop() { timeval_t last_conn = timeval_long_ago; while(true) { try { { timeval_t now = timeval_current(); interval_t to_sleep = conn_timeout - (timeval_current() - last_conn); if(to_sleep > interval_zero && bq_sleep(&to_sleep) < 0) throw exception_sys_t(log::error, errno, "bq_sleep: %m"); } last_conn = timeval_current(); netaddr_t const &netaddr = remote_netaddr(); int fd = socket(netaddr.sa->sa_family, SOCK_STREAM, 0); if(fd < 0) throw exception_sys_t(remote_errors, errno, "socket: %m"); fd_guard_t fd_guard(fd); bq_fd_setup(fd); interval_t timeout = conn_timeout; if(bq_connect(fd, netaddr.sa, netaddr.sa_len, &timeout) < 0) throw exception_sys_t(remote_errors, errno, "connect: %m"); log_debug("connected"); bq_conn_fd_t conn(fd, ctl(), remote_errors, /* dup = */ true); proto_instance->proc(conn); } catch(exception_sys_t const &ex) { if(ex.errno_val == ECANCELED) throw; ex.log(); } catch(exception_t const &ex) { ex.log(); } } }