void io_stream_t::loop(int afd, bool conswitch) const { fd_guard_t fd_guard(afd); timeval_t last_poll = timeval::current(); while(true) { bool poll_before = false; if(force_poll.is_real()) { timeval_t now = timeval::current(); if(now - last_poll > force_poll) { poll_before = true; last_poll = now; } } netaddr_t *netaddr = new_netaddr(); int nfd = bq_accept(afd, netaddr->sa, &netaddr->sa_len, NULL, poll_before); if(nfd < 0) { delete netaddr; throw exception_sys_t(log::error, errno, "accept: %m"); } try { string_t _name = string_t::ctor_t(netaddr->print_len()).print(*netaddr); ++stat.conns(); bq_thr_t *thr = aux_scheduler ? aux_scheduler->bq_thr() : (conswitch ? scheduler.bq_thr() : bq_thr_get()) ; log::handler_t handler(_name); bq_job(&io_stream_t::conn_proc)(*this, nfd, netaddr)->run(thr); } catch(exception_t const &ex) { ::close(nfd); delete netaddr; } catch(...) { ::close(nfd); delete netaddr; throw; } } }
void link_t::do_run() { bq_job_t<typeof(&link_t::loop)>::create( name, bq_thr_get(), *this, &link_t::loop ); }