Class: IO

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Constant Summary collapse

IOV_MAX =
rb_IOV_MAX

Instance Method Summary collapse

Instance Method Details

#writev(list) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'ext/writev/writev.c', line 15

static VALUE rb_writev(VALUE io, VALUE list)
{
    rb_io_t * fptr;
    struct iovec * iov;
    long i;
    ssize_t written;
    VALUE tmp;

#ifdef IOV_MAX
    if(RARRAY_LEN(list) > IOV_MAX)
#else
    if(RARRAY_LEN(list) > NUM2INT(rb_IOV_MAX))
#endif
  rb_raise(rb_eArgError, "list is too long");

    tmp = rb_io_check_io(io);
    GetOpenFile(tmp, fptr);
    rb_io_check_writable(fptr);

    iov = xcalloc(RARRAY_LEN(list), sizeof(struct iovec));

    for(i = 0; i < RARRAY_LEN(list); i++) {
  VALUE string = rb_ary_entry(list, i);
  iov[i].iov_base = StringValuePtr(string);
  iov[i].iov_len = RSTRING_LEN(string);
    }

    if((written = writev(fptr->fd, iov, (int)RARRAY_LEN(list))) == -1)
  rb_sys_fail_path(fptr->pathv);

    xfree(iov);

    return LONG2FIX(written);
}