libzmq master
The Intelligent Transport Layer

poll.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_POLL_HPP_INCLUDED__
00023 #define __ZMQ_POLL_HPP_INCLUDED__
00024 
00025 //  poller.hpp decides which polling mechanism to use.
00026 #include "poller.hpp"
00027 #if defined ZMQ_USE_POLL
00028 
00029 #include <poll.h>
00030 #include <stddef.h>
00031 #include <vector>
00032 
00033 #include "fd.hpp"
00034 #include "thread.hpp"
00035 #include "poller_base.hpp"
00036 
00037 namespace zmq
00038 {
00039 
00040     //  Implements socket polling mechanism using the POSIX.1-2001
00041     //  poll() system call.
00042 
00043     class poll_t : public poller_base_t
00044     {
00045     public:
00046 
00047         typedef fd_t handle_t;
00048 
00049         poll_t ();
00050         ~poll_t ();
00051 
00052         //  "poller" concept.
00053         handle_t add_fd (fd_t fd_, struct i_poll_events *events_);
00054         void rm_fd (handle_t handle_);
00055         void set_pollin (handle_t handle_);
00056         void reset_pollin (handle_t handle_);
00057         void set_pollout (handle_t handle_);
00058         void reset_pollout (handle_t handle_);
00059         void start ();
00060         void stop ();
00061 
00062     private:
00063 
00064         //  Main worker thread routine.
00065         static void worker_routine (void *arg_);
00066 
00067         //  Main event loop.
00068         void loop ();
00069 
00070         struct fd_entry_t
00071         {
00072             fd_t index;
00073             struct i_poll_events *events;
00074         };
00075 
00076         //  This table stores data for registered descriptors.
00077         typedef std::vector <fd_entry_t> fd_table_t;
00078         fd_table_t fd_table;
00079 
00080         //  Pollset to pass to the poll function.
00081         typedef std::vector <pollfd> pollset_t;
00082         pollset_t pollset;
00083 
00084         //  If true, there's at least one retired event source.
00085         bool retired;
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         poll_t (const poll_t&);
00094         const poll_t &operator = (const poll_t&);
00095     };
00096 
00097     typedef poll_t poller_t;
00098 
00099 }
00100 
00101 #endif
00102 
00103 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines