CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

requestlistener.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Ilya A. Volynets-Evenbakh                       *
00003  *   ilya@total-knowledge.com                                              *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef CSERVIMPLREQUESTLISTENER_H
00021 #define CSERVIMPLREQUESTLISTENER_H
00022 
00023 #include <map>
00024 #include <unistd.h>
00025 
00026 #include <connection.h>
00027 #include <servlet/IOError.h>
00028 #include <ResolverError.h>
00029 #include <sptk4/CThreadPool.h>
00030 
00031 namespace container {
00032 class RequestHandler;
00033 class AcceptConnection;
00034 
00040 class RequestListener{
00041 public:
00042     class Acceptor
00043     {
00044     protected:
00045         class FileDesc
00046         {
00047             int m_fd;
00048         public:
00049             FileDesc(int fd):m_fd(fd){}
00050             ~FileDesc();
00051             operator int(){return m_fd;}
00052             int operator=(int i){m_fd=i; return m_fd;}
00053         };
00054     protected:
00055         FileDesc m_sock;
00056         Acceptor(): m_sock(-1){}
00057     public:
00058         virtual ~Acceptor();
00059         void init(FileDesc& sock) throw(servlet::IOError);
00060         virtual Connection* accept();
00061         friend class RequestListener;
00062     };
00063     class TCPAcceptor:
00064         public Acceptor
00065     {
00066     public:
00067         TCPAcceptor(std::string host, unsigned short port)
00068             throw(servlet::IOError, container::ResolverError);
00069     };
00070     class UnixAcceptor:
00071         public Acceptor
00072     {
00073         // Need to save it, in order to remove the socket on shutdown
00074         std::string m_path;
00075         FileDesc m_socklock;
00076     public:
00077         UnixAcceptor(const std::string& path) throw(servlet::IOError);
00078         virtual ~UnixAcceptor();
00079     };
00080     friend class container::AcceptConnection;
00081 private:
00082     //int sock;
00083     //unsigned short port;
00084     //std::string listenOn;
00085     typedef std::map<int, Acceptor*> acceptormap_t;
00086     acceptormap_t m_listeners;
00087     sptk::CWaiter m_listenerLock;
00088     fd_set m_accept_fds;
00089     int m_maxfd;
00090     sptk::CThreadPool& m_pool;
00091 public:
00092     class UnknownProtocolError: public servlet::ServletException
00093     {
00094     };
00095     enum {
00096         MAX_BACKLOG=512,
00097         PORT=9004
00098     };
00099     RequestListener(sptk::CThreadPool&);
00100     ~RequestListener();
00101     void acceptRequests();
00102     void addAcceptor(container::RequestListener::Acceptor*);
00103 private:
00104     friend class Connection;
00105 };
00106 
00107 }
00108 
00109 #endif

SourceForge.net Logo