Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages   Examples  

poller_generic.h

00001 /************************************************************************
00002  *
00003  * $Id: poller_generic.h,v 1.12 2002/10/16 19:36:38 crooney Exp $
00004  *
00005  ***********************************************************************/
00006 
00007 /**************************************************************************
00008 Copyright 2001, Christopher Rooney crooney@crooney.com
00009 
00010 This file is part of fpoller.
00011 
00012 fpoller is free software; you can redistribute it and/or modify
00013 it under the terms of the GNU General Public License as published by
00014 the Free Software Foundation; either version 2 of the License, or
00015 (at your option) any later version.
00016 
00017 fpoller is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 GNU General Public License for more details.
00021 
00022 You should have received a copy of the GNU General Public License
00023 along with fpoller; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 
00027 #ifndef POLLER_GENERIC_H
00028 #define POLLER_GENERIC_H
00029 
00030 #include <unistd.h>
00031 #include <poll.h>
00032 #include <vector>
00033 #include <hash_map>
00034 #include <queue>
00035 
00036 #include "poller_util.h"
00037 
00038 namespace fpoller {
00043   class poller_generic {
00044   private:
00045     struct fd_info {
00046       callback_wrapper reader,writer;
00047       int pollfds_index;
00048     };
00049     typedef std::hash_map<int,fd_info> fd_map;
00050     fd_map fd_map_;
00051     int num_fds_;
00052     std::vector<pollfd> pollfds_;
00053     std::priority_queue<int,std::vector<int>,std::greater<int> > available_;
00054     inline void try_callback(int fd, callback_wrapper &cb, int interest){if (cb.operator->() && cb(fd) == REMOVE) remove(fd,interest);}    
00055   public:
00056     poller_generic();
00057     void add(int fd, short interest, callback* cb);
00058     void remove(int fd, short interest);
00059     int poll(int timeout);
00060   };
00061 
00062 }
00063 
00064 #endif //GENERIC_POLLER_H

Generated at Wed Oct 16 16:02:39 2002 for fpoller by doxygen1.2.9.1 written by Dimitri van Heesch, © 1997-2001