Exemple #1
0
static VALUE my_writev(VALUE io, VALUE ary, int io_wait)
{
	struct wrv_args a;
	ssize_t n;

	prepare_writev(&a, io, ary);
	set_nonblocking(a.fd);

	do {
		fill_iovec(&a);
		if (a.iov_cnt == 0)
			n = 0;
		else if (a.iov_cnt == 1)
			n = write(a.fd, a.vec[0].iov_base, a.vec[0].iov_len);
		/* for big strings use library function */
		else if (USE_WRITEV &&
		        ((long)(a.batch_len/WRITEV_IMPL_THRESHOLD) > a.iov_cnt))
			n = writev(a.fd, a.vec, a.iov_cnt);
		else
			n = custom_writev(a.fd, a.vec, a.iov_cnt, a.batch_len);
	} while (writev_check(&a, n, "writev", io_wait) != 0);
	rb_str_resize(a.vec_buf, 0);

	if (TYPE(a.buf) != T_SYMBOL)
		kgio_autopush_write(io);
	return a.buf;
}
Exemple #2
0
static VALUE my_write(VALUE io, VALUE str, int io_wait)
{
	struct wr_args a;
	long n;

	prepare_write(&a, io, str);
	set_nonblocking(a.fd);
retry:
	n = (long)write(a.fd, a.ptr, a.len);
	if (write_check(&a, n, "write", io_wait) != 0)
		goto retry;
	if (TYPE(a.buf) != T_SYMBOL)
		kgio_autopush_write(io);
	return a.buf;
}