Module: Kgio::SocketMethods

### Home Classes Methods

### In Files

- ext/kgio/accept.c

### Methods

- #kgio_autopush=
- #kgio_autopush?
- #kgio_peek
- #kgio_read
- #kgio_read!
- #kgio_trypeek
- #kgio_tryread
- #kgio_trywrite
- #kgio_trywritev
- #kgio_write
- #kgio_writev

### Included Modules

- mWaiters

### Files

- HACKING
- ISSUES
- LATEST
- LICENSE
- NEWS
- README
- TODO

### Class/Module Index

Quicksearch

- Kgio
- Kgio::DefaultWaiters
- Kgio::File
- Kgio::Pipe
- Kgio::PipeMethods
- Kgio::Socket
- Kgio::SocketMethods
- Kgio::TCPServer
- Kgio::TCPSocket
- Kgio::UNIXServer
- Kgio::UNIXSocket

No matching classes.

# Kgio::SocketMethods

This method behaves like Kgio::PipeMethods, but contains optimizations for sockets on certain operating systems (e.g. GNU/Linux).

### Attributes

kgio_addr[RW]

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.

### Public Instance Methods

kgio_autopush = true click to toggle source
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).

    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? → true or false click to toggle source

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).

    static VALUE autopush_get(VALUE io)
    {
            return state_get(io) <= 0 ? Qfalse : Qtrue;
    }

kgio_peek(maxlen) → buffer click to toggle source
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.

    static VALUE kgio_peek(int argc, VALUE *argv, VALUE io)
    {
            return my_peek(1, argc, argv, io);
    }

kgio_read(*args) click to toggle source

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

    static VALUE kgio_recv(int argc, VALUE *argv, VALUE io)
    {
            return my_recv(1, argc, argv, io);
    }

kgio_read!(*args) click to toggle source

Same as Kgio::SocketMethods#kgio_read, except EOFError is raised on EOF without a backtrace

    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(maxlen) → buffer click to toggle source
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.

    static VALUE kgio_trypeek(int argc, VALUE *argv, VALUE io)
    {
            return my_peek(0, argc, argv, io);
    }

kgio_tryread(*args) click to toggle source

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

    static VALUE kgio_tryrecv(int argc, VALUE *argv, VALUE io)
    {
            return my_recv(0, argc, argv, io);
    }

kgio_trywrite(p1) click to toggle source

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

    static VALUE kgio_trysend(VALUE io, VALUE str)
    {
            return my_send(io, str, 0);
    }

kgio_trywritev(array) → nil, Array or :wait_writable click to toggle source

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.

    static VALUE kgio_trywritev(VALUE io, VALUE ary)
    {
            return my_writev(io, ary, 0);
    }

kgio_write(p1) click to toggle source

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

    static VALUE kgio_send(VALUE io, VALUE str)
    {
            return my_send(io, str, 1);
    }

kgio_writev(array) → nil click to toggle source

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.

    static VALUE kgio_writev(VALUE io, VALUE ary)
    {
            return my_writev(io, ary, 1);
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.