summaryrefslogtreecommitdiffstats
path: root/src/Core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core')
-rw-r--r--src/Core/ConnectionManager.cpp45
-rw-r--r--src/Core/ConnectionManager.h10
2 files changed, 7 insertions, 48 deletions
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index a41b024..c0edd61 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -30,6 +30,7 @@
#include "RequestHandlers/GSSAPIAuthRequestHandler.h"
#include "RequestHandlers/IdentifyRequestHandler.h"
#include "RequestHandlers/LogRequestHandler.h"
+#include <Net/FdManager.h>
#include <Net/ServerConnection.h>
#include <Net/Packet.h>
#include <Net/Listener.h>
@@ -43,30 +44,6 @@ namespace Core {
std::auto_ptr<ConnectionManager> ConnectionManager::connectionManager;
-void ConnectionManager::refreshPollfds() {
- pollfds.clear();
- pollfdMap.clear();
-
- for(std::list<Net::Listener*>::iterator listener = listeners.begin(); listener != listeners.end(); ++listener) {
- std::vector<struct pollfd> fds = (*listener)->getPollfds();
-
- for(std::vector<struct pollfd>::iterator fd = fds.begin(); fd != fds.end(); ++fd) {
- pollfds.push_back(*fd);
- pollfdMap.insert(std::make_pair(fd->fd, &pollfds.back().revents));
- }
- }
-
- for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end(); ++con) {
- pollfds.push_back((*con)->getPollfd());
- pollfdMap.insert(std::make_pair(pollfds.back().fd, &pollfds.back().revents));
- }
-
- for(std::list<Net::ServerConnection*>::iterator con = clientConnections.begin(); con != clientConnections.end(); ++con) {
- pollfds.push_back((*con)->getPollfd());
- pollfdMap.insert(std::make_pair(pollfds.back().fd, &pollfds.back().revents));
- }
-}
-
void ConnectionManager::updateState(const std::string &name, Common::HostInfo::State state) {
daemonInfo[name].setState(state);
@@ -116,8 +93,6 @@ ConnectionManager::ConnectionManager() {
}
}
- refreshPollfds();
-
const std::vector<Common::HostInfo>& daemons = configManager->getDaemonList();
for(std::vector<Common::HostInfo>::const_iterator daemon = daemons.begin(); daemon != daemons.end(); ++daemon) {
@@ -138,15 +113,7 @@ ConnectionManager::~ConnectionManager() {
void ConnectionManager::handleConnections(std::list<Net::ServerConnection*>& connections) {
for(std::list<Net::ServerConnection*>::iterator con = connections.begin(); con != connections.end();) {
- if((*con)->isConnected()) {
- std::map<int,const short*>::iterator events = pollfdMap.find((*con)->getSocket());
-
- if(events != pollfdMap.end() && *events->second)
- (*con)->sendReceive(*events->second);
-
- ++con;
- }
- else {
+ if(!(*con)->isConnected()) {
if((*con)->isIdentified()) {
for(std::map<std::string,Net::ServerConnection*>::iterator idCon = identifiedDaemonConnections.begin(); idCon != identifiedDaemonConnections.end(); ++idCon) {
if(idCon->second == *con) {
@@ -162,25 +129,27 @@ void ConnectionManager::handleConnections(std::list<Net::ServerConnection*>& con
delete *con;
connections.erase(con++);
}
+ else
+ ++con;
}
}
void ConnectionManager::run() {
// TODO Logging
+ Net::FdManager::getFdManager()->run();
+
handleConnections(daemonConnections);
handleConnections(clientConnections);
for(std::list<Net::Listener*>::iterator listener = listeners.begin(); listener != listeners.end(); ++listener) {
Net::ServerConnection *con;
- while((con = (*listener)->getConnection(pollfdMap)) != 0) {
+ while((con = (*listener)->getConnection()) != 0) {
(con->isDaemonConnection() ? daemonConnections : clientConnections).push_back(con);
Common::RequestManager::getRequestManager()->registerConnection(con);
}
}
-
- refreshPollfds();
}
Net::Connection* ConnectionManager::getDaemonConnection(const std::string &name) const throw (Common::Exception&) {
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index 4f3ff67..6bbd66a 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -24,7 +24,6 @@
#include <vector>
#include <map>
#include <memory>
-#include <poll.h>
#include <Common/Exception.h>
#include <Common/HostInfo.h>
@@ -53,17 +52,12 @@ class ConnectionManager {
std::map<std::string,Common::HostInfo> daemonInfo;
std::map<std::string,Net::ServerConnection*> identifiedDaemonConnections;
- std::vector<struct pollfd> pollfds;
- std::map<int,const short*> pollfdMap;
-
// Prevent shallow copy
ConnectionManager(const ConnectionManager &o);
ConnectionManager& operator=(const ConnectionManager &o);
ConnectionManager();
- void refreshPollfds();
-
void handleConnections(std::list<Net::ServerConnection*> &connections);
void updateState(const std::string &name, Common::HostInfo::State state);
@@ -79,10 +73,6 @@ class ConnectionManager {
~ConnectionManager();
- bool wait(int timeout) {
- return (poll(pollfds.data(), pollfds.size(), timeout) > 0);
- }
-
void run();
Net::Connection* getDaemonConnection(const std::string &name) const throw (Common::Exception&);