Module: Kgio::DefaultWaiters

Defined in:
ext/kgio/wait.c,
ext/kgio/wait.c

Overview

This module contains default kgio_wait_readable and kgio_wait_writable methods that block indefinitely (in a thread-safe manner) until an IO object is read or writable. This module is included in the Kgio::PipeMethods and Kgio::SocketMethods modules used by all bundled IO-derived objects.

Instance Method Summary collapse

Instance Method Details

#kgio_wait_readable(*args) ⇒ Object

io.kgio_wait_readable -> IO io.kgio_wait_readable(timeout) -> IO or nil

Blocks the running Thread indefinitely until the IO object is readable or if timeout expires. If timeout is specified and expires, nil is returned.

This method is automatically called (without timeout argument) by default whenever kgio_read needs to block on input.

Users of alternative threading/fiber libraries are encouraged to override this method in their subclasses or modules to work with their threading/blocking methods.



60
61
62
63
64
65
66
# File 'ext/kgio/wait.c', line 60

static VALUE kgio_wait_readable(int argc, VALUE *argv, VALUE self)
{
	int r = kgio_wait(argc, argv, self, 0);

	if (r < 0) rb_sys_fail("kgio_wait_readable");
	return r == 0 ? Qnil : self;
}

#kgio_wait_writable(*args) ⇒ Object

io.kgio_wait_writable -> IO io.kgio_wait_writable(timeout) -> IO or nil

Blocks the running Thread indefinitely until the IO object is writable or if timeout expires. If timeout is specified and expires, nil is returned.

This method is automatically called (without timeout argument) by default whenever kgio_write needs to block on output.

Users of alternative threading/fiber libraries are encouraged to override this method in their subclasses or modules to work with their threading/blocking methods.



85
86
87
88
89
90
91
# File 'ext/kgio/wait.c', line 85

static VALUE kgio_wait_writable(int argc, VALUE *argv, VALUE self)
{
	int r = kgio_wait(argc, argv, self, 1);

	if (r < 0) rb_sys_fail("kgio_wait_writable");
	return r == 0 ? Qnil : self;
}