Module: Kgio::SocketMethods
- Includes:
- Waiters
- Defined in:
- ext/kgio/read_write.c,
ext/kgio/autopush.c,
ext/kgio/read_write.c
Overview
This method behaves like Kgio::PipeMethods, but contains optimizations for sockets on certain operating systems (e.g. GNU/Linux).
Instance Attribute Summary collapse
-
#kgio_addr ⇒ Object
Returns the client IP address of the socket as a string (e.g. “127.0.0.1” or “::1”).
Instance Method Summary collapse
-
#kgio_autopush=(vbool) ⇒ Object
io.kgio_autopush = true io.kgio_autopush = false.
-
#kgio_autopush? ⇒ Boolean
io.kgio_autopush? -> true or false.
-
#kgio_peek(*args) ⇒ Object
socket.kgio_peek(maxlen) -> buffer socket.kgio_peek(maxlen, buffer) -> buffer.
-
#kgio_read(*args) ⇒ Object
This method may be optimized on some systems (e.g. GNU/Linux) to use MSG_DONTWAIT to avoid explicitly setting the O_NONBLOCK flag via fcntl.
-
#kgio_read!(*args) ⇒ Object
Same as Kgio::SocketMethods#kgio_read, except EOFError is raised on EOF without a backtrace.
-
#kgio_trypeek(*args) ⇒ Object
socket.kgio_trypeek(maxlen) -> buffer socket.kgio_trypeek(maxlen, buffer) -> buffer.
-
#kgio_tryread(*args) ⇒ Object
This method may be optimized on some systems (e.g. GNU/Linux) to use MSG_DONTWAIT to avoid explicitly setting the O_NONBLOCK flag via fcntl.
-
#kgio_trywrite(str) ⇒ Object
This method may be optimized on some systems (e.g. GNU/Linux) to use MSG_DONTWAIT to avoid explicitly setting the O_NONBLOCK flag via fcntl.
-
#kgio_trywritev(ary) ⇒ Object
io.kgio_trywritev(array) -> nil, Array or :wait_writable.
-
#kgio_write(str) ⇒ Object
This method may be optimized on some systems (e.g. GNU/Linux) to use MSG_DONTWAIT to avoid explicitly setting the O_NONBLOCK flag via fcntl.
-
#kgio_writev(ary) ⇒ Object
io.kgio_writev(array) -> nil.
Instance Attribute Details
#kgio_addr ⇒ Object
Returns the client IP address of the socket as a string (e.g. “127.0.0.1” or “::1”). This is always the value of the Kgio::LOCALHOST constant for UNIX domain sockets.
Instance Method Details
#kgio_autopush=(vbool) ⇒ Object
io.kgio_autopush = true io.kgio_autopush = false
Enables or disables autopush on any given Kgio::SocketMethods-capable IO object. This does NOT enable or disable TCP_NOPUSH/TCP_CORK right away, that must be done with IO.setsockopt
Only available on systems with TCP_CORK (Linux) or TCP_NOPUSH (FreeBSD, and maybe other *BSDs).
144 145 146 147 148 149 150 151 |
# File 'ext/kgio/autopush.c', line 144
static VALUE autopush_set(VALUE io, VALUE vbool)
{
if (RTEST(vbool))
state_set(io, AUTOPUSH_STATE_WRITER);
else
state_set(io, AUTOPUSH_STATE_IGNORE);
return vbool;
}
|
#kgio_autopush? ⇒ Boolean
io.kgio_autopush? -> true or false
Returns the current autopush state of the Kgio::SocketMethods-enabled socket.
Only available on systems with TCP_CORK (Linux) or TCP_NOPUSH (FreeBSD, and maybe other *BSDs).
126 127 128 129 |
# File 'ext/kgio/autopush.c', line 126
static VALUE autopush_get(VALUE io)
{
return state_get(io) <= 0 ? Qfalse : Qtrue;
}
|
#kgio_peek(*args) ⇒ Object
socket.kgio_peek(maxlen) -> buffer socket.kgio_peek(maxlen, buffer) -> buffer
Like kgio_read, except it uses MSG_PEEK so it does not drain the socket buffer. A subsequent read of any type (including another peek) will return the same data.
311 312 313 314 |
# File 'ext/kgio/read_write.c', line 311
static VALUE kgio_peek(int argc, VALUE *argv, VALUE io)
{
return my_peek(1, argc, argv, io);
}
|
#kgio_read(*args) ⇒ Object
This method may be optimized on some systems (e.g. GNU/Linux) to use MSG_DONTWAIT to avoid explicitly setting the O_NONBLOCK flag via fcntl. Otherwise this is the same as Kgio::PipeMethods#kgio_read
235 236 237 238 |
# File 'ext/kgio/read_write.c', line 235
static VALUE kgio_recv(int argc, VALUE *argv, VALUE io)
{
return my_recv(1, argc, argv, io);
}
|
#kgio_read!(*args) ⇒ Object
Same as Kgio::SocketMethods#kgio_read, except EOFError is raised on EOF without a backtrace
244 245 246 247 248 249 250 |
# File 'ext/kgio/read_write.c', line 244
static VALUE kgio_recv_bang(int argc, VALUE *argv, VALUE io)
{
VALUE rv = my_recv(1, argc, argv, io);
if (NIL_P(rv)) my_eof_error();
return rv;
}
|
#kgio_trypeek(*args) ⇒ Object
socket.kgio_trypeek(maxlen) -> buffer socket.kgio_trypeek(maxlen, buffer) -> buffer
Like kgio_tryread, except it uses MSG_PEEK so it does not drain the socket buffer. A subsequent read of any type (including another peek) will return the same data.
296 297 298 299 |
# File 'ext/kgio/read_write.c', line 296
static VALUE kgio_trypeek(int argc, VALUE *argv, VALUE io)
{
return my_peek(0, argc, argv, io);
}
|
#kgio_tryread(*args) ⇒ Object
This method may be optimized on some systems (e.g. GNU/Linux) to use MSG_DONTWAIT to avoid explicitly setting the O_NONBLOCK flag via fcntl. Otherwise this is the same as Kgio::PipeMethods#kgio_tryread
257 258 259 260 |
# File 'ext/kgio/read_write.c', line 257
static VALUE kgio_tryrecv(int argc, VALUE *argv, VALUE io)
{
return my_recv(0, argc, argv, io);
}
|
#kgio_trywrite(str) ⇒ Object
This method may be optimized on some systems (e.g. GNU/Linux) to use MSG_DONTWAIT to avoid explicitly setting the O_NONBLOCK flag via fcntl. Otherwise this is the same as Kgio::PipeMethods#kgio_trywrite
713 714 715 716 |
# File 'ext/kgio/read_write.c', line 713
static VALUE kgio_trysend(VALUE io, VALUE str)
{
return my_send(io, str, 0);
}
|
#kgio_trywritev(ary) ⇒ Object
io.kgio_trywritev(array) -> nil, Array or :wait_writable
Returns nil if the write was completed in full.
Returns an Array of strings containing the unwritten portion if EAGAIN was encountered, but some portion was successfully written.
Returns :wait_writable if EAGAIN is encountered and nothing was written.
Note: it uses Array() semantic for converting argument, so that it will succeed if you pass something else.
672 673 674 675 |
# File 'ext/kgio/read_write.c', line 672
static VALUE kgio_trywritev(VALUE io, VALUE ary)
{
return my_writev(io, ary, 0);
}
|
#kgio_write(str) ⇒ Object
This method may be optimized on some systems (e.g. GNU/Linux) to use MSG_DONTWAIT to avoid explicitly setting the O_NONBLOCK flag via fcntl. Otherwise this is the same as Kgio::PipeMethods#kgio_write
703 704 705 706 |
# File 'ext/kgio/read_write.c', line 703
static VALUE kgio_send(VALUE io, VALUE str)
{
return my_send(io, str, 1);
}
|
#kgio_writev(ary) ⇒ Object
io.kgio_writev(array) -> nil
Returns nil when the write completes.
This may block and call any method defined to kgio_wait_writable
for the class.
Note: it uses Array() semantic for converting argument, so that it will succeed if you pass something else.
651 652 653 654 |
# File 'ext/kgio/read_write.c', line 651
static VALUE kgio_writev(VALUE io, VALUE ary)
{
return my_writev(io, ary, 1);
}
|