libzmq master
The Intelligent Transport Layer

devpoll.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2009-2011 250bpm s.r.o.
00003     Copyright (c) 2007-2009 iMatix Corporation
00004     Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
00005 
00006     This file is part of 0MQ.
00007 
00008     0MQ is free software; you can redistribute it and/or modify it under
00009     the terms of the GNU Lesser General Public License as published by
00010     the Free Software Foundation; either version 3 of the License, or
00011     (at your option) any later version.
00012 
00013     0MQ is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public License
00019     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #ifndef __ZMQ_DEVPOLL_HPP_INCLUDED__
00023 #define __ZMQ_DEVPOLL_HPP_INCLUDED__
00024 
00025 //  poller.hpp decides which polling mechanism to use.
00026 #include "poller.hpp"
00027 #if defined ZMQ_USE_DEVPOLL
00028 
00029 #include <vector>
00030 
00031 #include "fd.hpp"
00032 #include "thread.hpp"
00033 #include "poller_base.hpp"
00034 
00035 namespace zmq
00036 {
00037 
00038     //  Implements socket polling mechanism using the "/dev/poll" interface.
00039 
00040     class devpoll_t : public poller_base_t
00041     {
00042     public:
00043 
00044         typedef fd_t handle_t;
00045 
00046         devpoll_t ();
00047         ~devpoll_t ();
00048 
00049         //  "poller" concept.
00050         handle_t add_fd (fd_t fd_, struct i_poll_events *events_);
00051         void rm_fd (handle_t handle_);
00052         void set_pollin (handle_t handle_);
00053         void reset_pollin (handle_t handle_);
00054         void set_pollout (handle_t handle_);
00055         void reset_pollout (handle_t handle_);
00056         void start ();
00057         void stop ();
00058 
00059     private:
00060 
00061         //  Main worker thread routine.
00062         static void worker_routine (void *arg_);
00063 
00064         //  Main event loop.
00065         void loop ();
00066 
00067         //  File descriptor referring to "/dev/poll" pseudo-device.
00068         fd_t devpoll_fd;
00069 
00070         struct fd_entry_t
00071         {
00072             short events;
00073             struct i_poll_events *reactor;
00074             bool valid;
00075             bool accepted;
00076         };
00077 
00078         typedef std::vector <fd_entry_t> fd_table_t;
00079         fd_table_t fd_table;
00080 
00081         typedef std::vector <fd_t> pending_list_t;
00082         pending_list_t pending_list;
00083 
00084         //  Pollset manipulation function.
00085         void devpoll_ctl (fd_t fd_, short events_);
00086 
00087         //  If true, thread is in the process of shutting down.
00088         bool stopping;
00089 
00090         //  Handle of the physical thread doing the I/O work.
00091         thread_t worker;
00092 
00093         devpoll_t (const devpoll_t&);
00094         const devpoll_t &operator = (const devpoll_t&);
00095     };
00096 
00097     typedef devpoll_t poller_t;
00098 
00099 }
00100 
00101 #endif
00102 
00103 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines