Exemplo n.º 1
0
void selector::add_channel(const channel & ch,
                           bool allow_outgoing_traffic, bool allow_incoming_traffic)
{
    io_descriptor_type fd;
    io_direction direction;

    ch.get_io_descriptor(fd, direction);

    if (fd > num_of_descriptors_to_test_ - 1)
    {
        num_of_descriptors_to_test_ = fd + 1;
    }

    if ((direction == input || direction == inout) && allow_incoming_traffic)
    {
        FD_SET(fd, &read_set_);
    }

    if ((direction == output || direction == inout) && allow_outgoing_traffic)
    {
        FD_SET(fd, &write_set_);
    }

    ++num_of_channels_used_;
}
Exemplo n.º 2
0
bool selector::is_channel_ready(
    const channel & ch, io_direction & direction) const
{
    io_descriptor_type fd;
    io_direction dir;

    ch.get_io_descriptor(fd, dir);

    bool ready_for_reading = false;
    bool ready_for_writing = false;

    if (fd < num_of_descriptors_to_test_)
    {
        if (dir == input || dir == inout)
        {
            if (FD_ISSET(fd, &read_set_) != 0)
            {
                ready_for_reading = true;
            }
        }

        if (dir == output || dir == inout)
        {
            if (FD_ISSET(fd, &write_set_) != 0)
            {
                ready_for_writing = true;
            }
        }
    }

    if (ready_for_reading && ready_for_writing)
    {
        direction = inout;
    }
    else if (ready_for_reading)
    {
        direction = input;
    }
    else if (ready_for_writing)
    {
        direction = output;
    }

    return ready_for_reading || ready_for_writing;
}