From: <mik...@us...> - 2003-12-30 09:19:33
|
Update of /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http/manager In directory sc8-pr-cvs1:/tmp/cvs-serv27523/src/server/http/manager Added Files: HttpManager.h HttpManager.cpp Log Message: 30/12/2003 Mikael Barbeaux * Implemented a Http connection manager. --- NEW FILE: HttpManager.h --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _HTTP_MANAGER_H_ #define _HTTP_MANAGER_H_ #include "../HttpSocket.h" #include "../../../thread/Semaphore.h" #include "../../../thread/Mutex.h" #include <deque> using namespace std; /** * Defines a manager for HTTP connections. * Formely, it's a thread pool where connections * are stocked and treated. */ class HttpManager{ private: // pool of connections deque<HttpSocket*> connections; // unique instance of HttpManager static HttpManager *instance; /* semaphore for signaling processors than a connection is waiting to be processed */ Semaphore *conn_notEmpty; /* mutex for accessing datas */ Mutex mutex; protected: /** * Creates a HttpManager object. * As this class implements the Singleton * design pattern, the constructor is protected. */ HttpManager(); public: /** * Destructor for HttpManager. */ ~HttpManager(); /** * Add a connection into the manager * * @param connection */ void addConnection(HttpSocket *connection); /** * Returns the next connection to be processed. * * @return HttpSocket* */ HttpSocket *getNextConnection(); /** * Returns the unique instance of HttpManager. * * @return HttpManager* */ static HttpManager *getInstance(); }; #endif --- NEW FILE: HttpManager.cpp --- /* * This file is part of webInterface. * Copyright (C) 2003 Mikael Barbeaux <mik...@us...> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "HttpManager.h" HttpManager *HttpManager::instance = 0; /** * Constructor for HttpManager. * Inits the semaphore. */ HttpManager::HttpManager() { conn_notEmpty = new Semaphore(0); } /** * HttpManager destructor. * Deletes the semaphore. */ HttpManager::~HttpManager() { delete conn_notEmpty; } /** * Returns the unique instance of HttpManager */ HttpManager *HttpManager::getInstance() { // init instance if not yet done if(instance == 0) instance = new HttpManager; return instance; } /** * Add a connection into the manager */ void HttpManager::addConnection(HttpSocket *connection) { // add the connection into the pool mutex.lock(); connections.push_back(connection); mutex.unlock(); // Signals the processors that a connection is pending conn_notEmpty->post(); } /** * Returns the next connection to be processed. */ HttpSocket *HttpManager::getNextConnection() { HttpSocket *socket = 0; mutex.lock(); if(connections.size() > 0) { socket = connections.front(); connections.pop_front(); } mutex.unlock(); return socket; } |