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