io_object.cpp 2.31 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
2
    Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
Martin Sustrik's avatar
Martin Sustrik committed
3 4 5 6

    This file is part of 0MQ.

    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
Martin Sustrik's avatar
Martin Sustrik committed
8 9 10 11 12 13
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU Lesser General Public License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
15

16
    You should have received a copy of the GNU Lesser General Public License
Martin Sustrik's avatar
Martin Sustrik committed
17 18 19
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

20
#include "io_object.hpp"
21
#include "io_thread.hpp"
22
#include "err.hpp"
Martin Sustrik's avatar
Martin Sustrik committed
23

24 25
zmq::io_object_t::io_object_t (io_thread_t *io_thread_) :
    poller (NULL)
Martin Sustrik's avatar
Martin Sustrik committed
26
{
27 28
    if (io_thread_)
        plug (io_thread_);
29
}
30

31 32 33
zmq::io_object_t::~io_object_t ()
{
}
34

35
void zmq::io_object_t::plug (io_thread_t *io_thread_)
36
{
37 38 39 40
    zmq_assert (io_thread_);
    zmq_assert (!poller);

    //  Retrieve the poller from the thread we are running in.
41
    poller = io_thread_->get_poller ();
42 43
}

44 45 46 47 48 49 50 51 52
void zmq::io_object_t::unplug ()
{
    zmq_assert (poller);

    //  Forget about old poller in preparation to be migrated
    //  to a different I/O thread.
    poller = NULL;
}

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
}

void zmq::io_object_t::rm_fd (handle_t handle_)
{
    poller->rm_fd (handle_);
}

void zmq::io_object_t::set_pollin (handle_t handle_)
{
    poller->set_pollin (handle_);
}

void zmq::io_object_t::reset_pollin (handle_t handle_)
{
    poller->reset_pollin (handle_);
}

void zmq::io_object_t::set_pollout (handle_t handle_)
{
    poller->set_pollout (handle_);
}

void zmq::io_object_t::reset_pollout (handle_t handle_)
{
    poller->reset_pollout (handle_);
}

83
void zmq::io_object_t::add_timer (int timeout_, int id_)
84
{
85
    poller->add_timer (timeout_, this, id_);
86 87
}

88
void zmq::io_object_t::cancel_timer (int id_)
89
{
90
    poller->cancel_timer (this, id_);
91 92
}

93 94 95 96 97 98 99 100 101 102
void zmq::io_object_t::in_event ()
{
    zmq_assert (false);
}

void zmq::io_object_t::out_event ()
{
    zmq_assert (false);
}

103
void zmq::io_object_t::timer_event (int)
104 105 106
{
    zmq_assert (false);
}