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

4
    This file is part of libzmq, the ZeroMQ core engine in C++.
Martin Sustrik's avatar
Martin Sustrik committed
5

6 7 8
    libzmq is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License (LGPL) as published
    by the Free Software Foundation; either version 3 of the License, or
Martin Sustrik's avatar
Martin Sustrik committed
9 10
    (at your option) any later version.

11 12 13 14 15 16 17 18 19 20 21 22 23 24
    As a special exception, the Contributors give you permission to link
    this library with independent modules to produce an executable,
    regardless of the license terms of these independent modules, and to
    copy and distribute the resulting executable under terms of your choice,
    provided that you also meet, for each linked independent module, the
    terms and conditions of the license of that module. An independent
    module is a module which is not derived from or based on this library.
    If you modify this library, you must extend this exception to your
    version of the library.

    libzmq 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 GNU Lesser General Public
    License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
25

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

30
#include "precompiled.hpp"
31
#include "io_object.hpp"
32
#include "io_thread.hpp"
33
#include "err.hpp"
Martin Sustrik's avatar
Martin Sustrik committed
34

35 36
zmq::io_object_t::io_object_t (io_thread_t *io_thread_) :
    poller (NULL)
Martin Sustrik's avatar
Martin Sustrik committed
37
{
38 39
    if (io_thread_)
        plug (io_thread_);
40
}
41

42 43 44
zmq::io_object_t::~io_object_t ()
{
}
45

46
void zmq::io_object_t::plug (io_thread_t *io_thread_)
47
{
48 49 50 51
    zmq_assert (io_thread_);
    zmq_assert (!poller);

    //  Retrieve the poller from the thread we are running in.
52
    poller = io_thread_->get_poller ();
53 54
}

55 56 57 58 59 60 61 62 63
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;
}

64
zmq::io_object_t::handle_t zmq::io_object_t::add_fd (fd_t fd_)
65
{
66
    return poller->add_fd (fd_, this);
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
}

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

94
void zmq::io_object_t::add_timer (int timeout_, int id_)
95
{
96
    poller->add_timer (timeout_, this, id_);
97 98
}

99
void zmq::io_object_t::cancel_timer (int id_)
100
{
101
    poller->cancel_timer (this, id_);
102 103
}

104 105 106 107 108 109 110 111 112 113
void zmq::io_object_t::in_event ()
{
    zmq_assert (false);
}

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

114
void zmq::io_object_t::timer_event (int)
115 116 117
{
    zmq_assert (false);
}