| 1 | /* |
| 2 | Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file |
| 3 | |
| 4 | This file is part of libzmq, the ZeroMQ core engine in C++. |
| 5 | |
| 6 | libzmq is free software; you can redistribute it and/or modify it under |
| 7 | the terms of the GNU Lesser General Public License (LGPL) as published |
| 8 | by the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | As a special exception, the Contributors give you permission to link |
| 12 | this library with independent modules to produce an executable, |
| 13 | regardless of the license terms of these independent modules, and to |
| 14 | copy and distribute the resulting executable under terms of your choice, |
| 15 | provided that you also meet, for each linked independent module, the |
| 16 | terms and conditions of the license of that module. An independent |
| 17 | module is a module which is not derived from or based on this library. |
| 18 | If you modify this library, you must extend this exception to your |
| 19 | version of the library. |
| 20 | |
| 21 | libzmq is distributed in the hope that it will be useful, but WITHOUT |
| 22 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 24 | License for more details. |
| 25 | |
| 26 | You should have received a copy of the GNU Lesser General Public License |
| 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 | */ |
| 29 | |
| 30 | #include "precompiled.hpp" |
| 31 | #include "io_object.hpp" |
| 32 | #include "io_thread.hpp" |
| 33 | #include "err.hpp" |
| 34 | |
| 35 | zmq::io_object_t::io_object_t (io_thread_t *io_thread_) : _poller (NULL) |
| 36 | { |
| 37 | if (io_thread_) |
| 38 | plug (io_thread_); |
| 39 | } |
| 40 | |
| 41 | zmq::io_object_t::~io_object_t () |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | void zmq::io_object_t::plug (io_thread_t *io_thread_) |
| 46 | { |
| 47 | zmq_assert (io_thread_); |
| 48 | zmq_assert (!_poller); |
| 49 | |
| 50 | // Retrieve the poller from the thread we are running in. |
| 51 | _poller = io_thread_->get_poller (); |
| 52 | } |
| 53 | |
| 54 | void zmq::io_object_t::unplug () |
| 55 | { |
| 56 | zmq_assert (_poller); |
| 57 | |
| 58 | // Forget about old poller in preparation to be migrated |
| 59 | // to a different I/O thread. |
| 60 | _poller = NULL; |
| 61 | } |
| 62 | |
| 63 | zmq::io_object_t::handle_t zmq::io_object_t::add_fd (fd_t fd_) |
| 64 | { |
| 65 | return _poller->add_fd (fd_, this); |
| 66 | } |
| 67 | |
| 68 | void zmq::io_object_t::rm_fd (handle_t handle_) |
| 69 | { |
| 70 | _poller->rm_fd (handle_); |
| 71 | } |
| 72 | |
| 73 | void zmq::io_object_t::set_pollin (handle_t handle_) |
| 74 | { |
| 75 | _poller->set_pollin (handle_); |
| 76 | } |
| 77 | |
| 78 | void zmq::io_object_t::reset_pollin (handle_t handle_) |
| 79 | { |
| 80 | _poller->reset_pollin (handle_); |
| 81 | } |
| 82 | |
| 83 | void zmq::io_object_t::set_pollout (handle_t handle_) |
| 84 | { |
| 85 | _poller->set_pollout (handle_); |
| 86 | } |
| 87 | |
| 88 | void zmq::io_object_t::reset_pollout (handle_t handle_) |
| 89 | { |
| 90 | _poller->reset_pollout (handle_); |
| 91 | } |
| 92 | |
| 93 | void zmq::io_object_t::add_timer (int timeout_, int id_) |
| 94 | { |
| 95 | _poller->add_timer (timeout_, this, id_); |
| 96 | } |
| 97 | |
| 98 | void zmq::io_object_t::cancel_timer (int id_) |
| 99 | { |
| 100 | _poller->cancel_timer (this, id_); |
| 101 | } |
| 102 | |
| 103 | void zmq::io_object_t::in_event () |
| 104 | { |
| 105 | zmq_assert (false); |
| 106 | } |
| 107 | |
| 108 | void zmq::io_object_t::out_event () |
| 109 | { |
| 110 | zmq_assert (false); |
| 111 | } |
| 112 | |
| 113 | void zmq::io_object_t::timer_event (int) |
| 114 | { |
| 115 | zmq_assert (false); |
| 116 | } |
| 117 | |