method

__write_nonblock

Importance_0
v2_5_5 - Show latest stable - 0 notes - Class: IO
__write_nonblock(p1, p2) private

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
static VALUE
io_write_nonblock(VALUE io, VALUE str, VALUE ex)
{
    rb_io_t *fptr;
    long n;

    if (!RB_TYPE_P(str, T_STRING))
        str = rb_obj_as_string(str);

    io = GetWriteIO(io);
    GetOpenFile(io, fptr);
    rb_io_check_writable(fptr);

    if (io_fflush(fptr) < 0)
        rb_sys_fail(0);

    rb_io_set_nonblock(fptr);
    n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
    RB_GC_GUARD(str);

    if (n == -1) {
        int e = errno;
        if (e == EWOULDBLOCK || e == EAGAIN) {
            if (ex == Qfalse) {
                return sym_wait_writable;
            }
            else {
                rb_readwrite_syserr_fail(RB_IO_WAIT_WRITABLE, e, "write would block");
            }
        }
        rb_syserr_fail_path(e, fptr->pathv);
    }

    return LONG2FIX(n);
}
Register or log in to add new notes.