![]() |
libzmq master
The Intelligent Transport Layer
|
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_EPOLL_HPP_INCLUDED__ 00023 #define __ZMQ_EPOLL_HPP_INCLUDED__ 00024 00025 // poller.hpp decides which polling mechanism to use. 00026 #include "poller.hpp" 00027 #if defined ZMQ_USE_EPOLL 00028 00029 #include <vector> 00030 #include <sys/epoll.h> 00031 00032 #include "fd.hpp" 00033 #include "thread.hpp" 00034 #include "poller_base.hpp" 00035 00036 namespace zmq 00037 { 00038 00039 // This class implements socket polling mechanism using the Linux-specific 00040 // epoll mechanism. 00041 00042 class epoll_t : public poller_base_t 00043 { 00044 public: 00045 00046 typedef void* handle_t; 00047 00048 epoll_t (); 00049 ~epoll_t (); 00050 00051 // "poller" concept. 00052 handle_t add_fd (fd_t fd_, struct i_poll_events *events_); 00053 void rm_fd (handle_t handle_); 00054 void set_pollin (handle_t handle_); 00055 void reset_pollin (handle_t handle_); 00056 void set_pollout (handle_t handle_); 00057 void reset_pollout (handle_t handle_); 00058 void start (); 00059 void stop (); 00060 00061 private: 00062 00063 // Main worker thread routine. 00064 static void worker_routine (void *arg_); 00065 00066 // Main event loop. 00067 void loop (); 00068 00069 // Main epoll file descriptor 00070 fd_t epoll_fd; 00071 00072 struct poll_entry_t 00073 { 00074 fd_t fd; 00075 epoll_event ev; 00076 struct i_poll_events *events; 00077 }; 00078 00079 // List of retired event sources. 00080 typedef std::vector <poll_entry_t*> retired_t; 00081 retired_t retired; 00082 00083 // If true, thread is in the process of shutting down. 00084 bool stopping; 00085 00086 // Handle of the physical thread doing the I/O work. 00087 thread_t worker; 00088 00089 epoll_t (const epoll_t&); 00090 const epoll_t &operator = (const epoll_t&); 00091 }; 00092 00093 typedef epoll_t poller_t; 00094 00095 } 00096 00097 #endif 00098 00099 #endif