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

poller_kqueue.h

00001 /************************************************************************
00002  *
00003  * $Id: poller_kqueue.h,v 1.13 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 #ifndef POLLER_KQUEUE_H
00027 #define POLLER_KQUEUE_H
00028 
00029 #include <sys/types.h>
00030 #include <sys/event.h>
00031 #include <vector>
00032 #include <hash_map>
00033 
00034 #include "poller_util.h"
00035 
00036 namespace fpoller {
00043   class poller_kqueue {
00044   private:
00045     int kq_fd_;
00046     std::vector<struct kevent> poll_queue_,change_queue_;
00047     typedef std::hash_map<int, callback_wrapper> fd_map;
00048     struct fd_maps {
00049       fd_map reader,writer; 
00050       inline int size(){return reader.size()+writer.size();}
00051       inline fd_map &get_map(short interest){return (interest & WRITE) ? writer : reader;}
00052     };
00053     fd_maps fd_maps_;
00054     inline static short poll_to_kq(short filter){return filter==WRITE ? EVFILT_WRITE : EVFILT_READ;}
00055     inline static short kq_to_poll(short filter){return filter==EVFILT_WRITE ? WRITE : READ;}
00056   public:
00058     poller_kqueue(){if ((kq_fd_ = kqueue()) <0 ) throw exception("could not open kqueue",errno);}
00060     ~poller_kqueue(){close(kq_fd_);}
00061     void add(int fd, short events, callback *cb);
00062     void remove(int fd,short interest);
00063     int poll(int timeout);
00064   };
00065 }
00066 
00067 #endif

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