Beispiel #1
0
/* Internal implementation of select with the selector lock held */
static VALUE NIO_Selector_select_synchronized(VALUE *args)
{
    int ready;
    VALUE ready_array;
    struct NIO_Selector *selector;

    Data_Get_Struct(args[0], struct NIO_Selector, selector);
    if(!rb_block_given_p()) {
        selector->ready_array = rb_ary_new();
    }

    ready = NIO_Selector_run(selector, args[1]);
    if(ready > 0) {
        if(rb_block_given_p()) {
            return INT2NUM(ready);
        } else {
            ready_array = selector->ready_array;
            selector->ready_array = Qnil;
            return ready_array;
        }
    } else {
        selector->ready_array = Qnil;
        return Qnil;
    }
}
Beispiel #2
0
/* Internal implementation of select with the selector lock held */
static VALUE NIO_Selector_select_synchronized(VALUE *args)
{
    int ready;
    VALUE ready_array;
    struct NIO_Selector *selector;

    Data_Get_Struct(args[0], struct NIO_Selector, selector);

    if(selector->closed) {
        rb_raise(rb_eIOError, "selector is closed");
    }

    if(!rb_block_given_p()) {
        selector->ready_array = rb_ary_new();
    }

    ready = NIO_Selector_run(selector, args[1]);

    /* Timeout */
    if(ready < 0) {
        if(!rb_block_given_p()) {
            selector->ready_array = Qnil;
        }

        return Qnil;
    }

    if(rb_block_given_p()) {
        return INT2NUM(ready);
    } else {
        ready_array = selector->ready_array;
        selector->ready_array = Qnil;
        return ready_array;
    }
}