libzmq master
The Intelligent Transport Layer

io_thread.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_IO_THREAD_HPP_INCLUDED__
00023 #define __ZMQ_IO_THREAD_HPP_INCLUDED__
00024 
00025 #include <vector>
00026 
00027 #include "stdint.hpp"
00028 #include "object.hpp"
00029 #include "poller.hpp"
00030 #include "i_poll_events.hpp"
00031 #include "mailbox.hpp"
00032 
00033 namespace zmq
00034 {
00035 
00036     //  Generic part of the I/O thread. Polling-mechanism-specific features
00037     //  are implemented in separate "polling objects".
00038 
00039     class io_thread_t : public object_t, public i_poll_events
00040     {
00041     public:
00042 
00043         io_thread_t (class ctx_t *ctx_, uint32_t tid_);
00044 
00045         //  Clean-up. If the thread was started, it's neccessary to call 'stop'
00046         //  before invoking destructor. Otherwise the destructor would hang up.
00047         ~io_thread_t ();
00048 
00049         //  Launch the physical thread.
00050         void start ();
00051 
00052         //  Ask underlying thread to stop.
00053         void stop ();
00054 
00055         //  Returns mailbox associated with this I/O thread.
00056         mailbox_t *get_mailbox ();
00057 
00058         //  i_poll_events implementation.
00059         void in_event ();
00060         void out_event ();
00061         void timer_event (int id_);
00062 
00063         //  Used by io_objects to retrieve the assciated poller object.
00064         poller_t *get_poller ();
00065 
00066         //  Command handlers.
00067         void process_stop ();
00068 
00069         //  Returns load experienced by the I/O thread.
00070         int get_load ();
00071 
00072     private:
00073 
00074         //  I/O thread accesses incoming commands via this mailbox.
00075         mailbox_t mailbox;
00076 
00077         //  Handle associated with mailbox' file descriptor.
00078         poller_t::handle_t mailbox_handle;
00079 
00080         //  I/O multiplexing is performed using a poller object.
00081         poller_t *poller;
00082 
00083         io_thread_t (const io_thread_t&);
00084         const io_thread_t &operator = (const io_thread_t&);
00085     };
00086 
00087 }
00088 
00089 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines