From: <mik...@us...> - 2003-12-30 10:45:16
|
Update of /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http/manager In directory sc8-pr-cvs1:/tmp/cvs-serv7723/src/server/http/manager Modified Files: HttpManager.h Added Files: HttpProcessor.cpp HttpProcessor.h Log Message: 30/12/2003 Mikael Barbeaux * Implemented a Http processor thread object. * Implemented a Http connections manager object. * Modified configure script for pthread library. --- NEW FILE: HttpProcessor.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 "HttpProcessor.h" #include "HttpManager.h" #include "../TextWriter.h" /** * Creates a HttpProcessor with the given id. */ HttpProcessor::HttpProcessor(int id_proc) : Thread() { id =id_proc; } /** * Destructor for HttpProcessor. * Does nothing. */ HttpProcessor::~HttpProcessor() throw (ThreadException) { wait(); } /** * Runs the processor. */ void HttpProcessor::run() throw (ThreadException) { while(true) { // Wait for a job into the manager. theManager->conn_notEmpty->wait(); // Set the cancellation point setCancelPoint(); // Retrieve the connection HttpSocket *socket = theManager->getNextConnection(); // No connection ? if(socket == 0) continue; // Processes the connection. HttpRequest request; socket->receiveHttpRequest(request); TextWriter *writer = new TextWriter; *writer << "<html><body>Your request has been "; *writer << "processed by HttpProcessor nb "; *writer << (int)id; *writer << "</body></html>\n"; writer->close(); HttpResponse resp(writer); resp.setContentType("text/html"); // send response socket->sendHttpResponse(resp); socket->close(); delete socket; } } --- NEW FILE: HttpProcessor.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_PROCESSOR_H_ #define _HTTP_PROCESSOR_H_ #include "../../../thread/Thread.h" #include "../../../exceptions/ThreadException.h" /** * Defines a processor for HttpConnection. * It is a thread than process the request and * build the response to be sent to the client. */ class HttpProcessor : public Thread { private: // identifiant for this thread unsigned int id; public: /** * Creates a HttpProcessor object with the given * identifiant. * * @param id_proc */ HttpProcessor(int id_proc); /** * Destructor for HttpProcessor */ ~HttpProcessor() throw (ThreadException); /** * Runs the processor. */ virtual void run() throw (ThreadException); }; #endif Index: HttpManager.h =================================================================== RCS file: /cvsroot/sharedaemon/sharedaemon-ui-web/src/server/http/manager/HttpManager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- HttpManager.h 30 Dec 2003 09:19:29 -0000 1.1 +++ HttpManager.h 30 Dec 2003 10:45:10 -0000 1.2 @@ -23,9 +23,12 @@ #include "../HttpSocket.h" #include "../../../thread/Semaphore.h" #include "../../../thread/Mutex.h" +#include "HttpProcessor.h" #include <deque> using namespace std; +#define theManager HttpManager::getInstance() + /** * Defines a manager for HTTP connections. * Formely, it's a thread pool where connections @@ -33,6 +36,9 @@ */ class HttpManager{ + // processors are friends :) + friend class HttpProcessor; + private: // pool of connections @@ -81,6 +87,13 @@ * @return HttpManager* */ static HttpManager *getInstance(); + + /** + * Releases the processors. + */ + void release() { + conn_notEmpty->sendBroadcastSignal(); + } }; #endif |