本文整理汇总了C++中ConnectionManager::dispatch_command方法的典型用法代码示例。如果您正苦于以下问题:C++ ConnectionManager::dispatch_command方法的具体用法?C++ ConnectionManager::dispatch_command怎么用?C++ ConnectionManager::dispatch_command使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager::dispatch_command方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run_worker
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void ConnectionManager::run_worker (ConnectionManager& cm)
{
cm.fds_size = 8;
cm.fds = new struct pollfd[cm.fds_size];
cm.fds_rx_more = new bool[cm.fds_size];
cm.fds_tx_more = new bool[cm.fds_size];
int nfds;
bool done = false;
DEBUG_TRACE (THIS_FILE, "Worker thread started");
// Setup the command pipe in the poller
//
cm.fds[0].fd = cm.cmd_pipe[pipe_rx];
cm.fds[0].events = POLLIN;
cm.fds[0].revents = 0;
cm.fds_rx_more[0] = false;
cm.fds_tx_more[0] = false;
nfds = 1;
int poll_timeout = WHILE_HELL_BURNS;
while (!done) {
// Poll file descriptors
//
DEBUG_TRACE (THIS_FILE, "Poll ", nfds, " file descriptors, timeout: ", poll_timeout);
auto result = poll (cm.fds, nfds, poll_timeout);
if (result <= 0) {
// Check for errors or timeout
//
if (result<0 || poll_timeout!=FASTER_THAN_LIGHT) {
if (result==0 || errno==EINTR)
continue;
uxmpp_log_error (THIS_FILE, "poll failed");
continue;
}
}
// Check the command pipe first
//
if (cm.fds[0].revents & POLLIN)
done = cm.dispatch_command (nfds);
// Check file descriptors
//
int new_timeout = WHILE_HELL_BURNS;
for (auto i=1; i<nfds; ++i) {
bool have_tx = cm.fds_tx_more[i] || ((cm.fds[i].revents & POLLOUT) != 0);
bool have_rx = cm.fds_rx_more[i] || ((cm.fds[i].revents & POLLIN) != 0);
if (have_tx && cm.handle_poll_io(cm.fds[i], nfds, false) == FASTER_THAN_LIGHT) {
cm.fds_tx_more[i] = true;
new_timeout = FASTER_THAN_LIGHT;
}else{
cm.fds_tx_more[i] = false;
}
if (have_rx && cm.handle_poll_io(cm.fds[i], nfds, true) == FASTER_THAN_LIGHT) {
cm.fds_rx_more[i] = true;
new_timeout = FASTER_THAN_LIGHT;
}else{
cm.fds_rx_more[i] = false;
}
}
poll_timeout = new_timeout;
}
delete[] cm.fds;
delete[] cm.fds_rx_more;
delete[] cm.fds_tx_more;
cm.fds = nullptr;
cm.fds_rx_more = cm.fds_tx_more = nullptr;
cm.fds_size = 0;
DEBUG_TRACE (THIS_FILE, "Worker thread ending");
}