io_object.cpp 2.36 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
2 3
    Copyright (c) 2007-2011 iMatix Corporation
    Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
Martin Sustrik's avatar
Martin Sustrik committed
4 5 6 7

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
8
    the terms of the GNU Lesser General Public License as published by
Martin Sustrik's avatar
Martin Sustrik committed
9 10 11 12 13 14
    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
15
    GNU Lesser General Public License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
16

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

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

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

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

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

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

45 46 47 48 49 50 51 52 53
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;
}

54
zmq::io_object_t::handle_t zmq::io_object_t::add_fd (fd_t fd_)
55
{
56
    return poller->add_fd (fd_, this);
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 83
}

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_);
}

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

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

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

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

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