-void RADIUS::runImpl()
-{
- m_running = true;
-
- while (m_running) {
- fd_set fds;
-
- buildFDSet(fds);
-
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 500000;
-
- int res = select(maxFD() + 1, &fds, NULL, NULL, &tv);
- if (res < 0)
- {
- m_error = std::string("'select' is failed: '") + strerror(errno) + "'.";
- m_logger(m_error);
- break;
- }
-
- if (!m_running)
- break;
-
- if (res > 0)
- handleEvents(fds);
-
- cleanupConns();
- }
-
- m_stopped = true;
-}
-
-int RADIUS::maxFD() const
-{
- int maxFD = m_listenSocket;
- std::deque<STG::Conn *>::const_iterator it;
- for (it = m_conns.begin(); it != m_conns.end(); ++it)
- if (maxFD < (*it)->sock())
- maxFD = (*it)->sock();
- return maxFD;
-}
-
-void RADIUS::buildFDSet(fd_set & fds) const
-{
- FD_ZERO(&fds);
- FD_SET(m_listenSocket, &fds);
- std::deque<STG::Conn *>::const_iterator it;
- for (it = m_conns.begin(); it != m_conns.end(); ++it)
- FD_SET((*it)->sock(), &fds);
-}
-
-void RADIUS::cleanupConns()
-{
- std::deque<STG::Conn *>::iterator pos;
- for (pos = m_conns.begin(); pos != m_conns.end(); ++pos)
- if (((*pos)->isDone() && !(*pos)->isKeepAlive()) || !(*pos)->isOk()) {
- delete *pos;
- *pos = NULL;
- }
-
- pos = std::remove(m_conns.begin(), m_conns.end(), static_cast<STG::Conn *>(NULL));
- m_conns.erase(pos, m_conns.end());
-}
-
-void RADIUS::handleEvents(const fd_set & fds)
-{
- if (FD_ISSET(m_listenSocket, &fds))
- acceptConnection();
- else
- {
- std::deque<STG::Conn *>::iterator it;
- for (it = m_conns.begin(); it != m_conns.end(); ++it)
- if (FD_ISSET((*it)->sock(), &fds))
- (*it)->read();
- }
-}