Parent

Kgio::TCPServer

Kgio::TCPServer should be used in place of the plain TCPServer when kgio_accept and kgio_tryaccept methods are needed.

Public Instance Methods

server = Kgio::TCPServer.new('0.0.0.0', 80) click to toggle source
kgio_accept → Kgio::Socket or nil

Initiates a blocking accept and returns a generic Kgio::Socket object with the kgio_addr attribute set to the IP address of the client on success.

On Ruby implementations using native threads, this can use a blocking accept(2) (or accept4(2)) system call to avoid thundering herds.

An optional class argument may be specified to override the Kgio::Socket-class return value:

server.kgio_accept(MySocket) -> MySocket
static VALUE tcp_accept(int argc, VALUE *argv, VALUE io)
{
        struct sockaddr_storage addr;
        socklen_t addrlen = sizeof(struct sockaddr_storage);
        VALUE klass = acceptor(argc, argv);
        VALUE rv = my_accept(io, klass, (struct sockaddr *)&addr, &addrlen, 0);

        in_addr_set(rv, &addr, addrlen);
        return rv;
}
server = Kgio::TCPServer.new('0.0.0.0', 80) click to toggle source
kgio_tryaccept → Kgio::Socket or nil

Initiates a non-blocking accept and returns a generic Kgio::Socket object with the kgio_addr attribute set to the IP address of the connected client on success.

Returns nil on EAGAIN, and raises on other errors.

An optional class argument may be specified to override the Kgio::Socket-class return value:

server.kgio_tryaccept(MySocket) -> MySocket
static VALUE tcp_tryaccept(int argc, VALUE *argv, VALUE io)
{
        struct sockaddr_storage addr;
        socklen_t addrlen = sizeof(struct sockaddr_storage);
        VALUE klass = acceptor(argc, argv);
        VALUE rv = my_accept(io, klass, (struct sockaddr *)&addr, &addrlen, 1);

        if (!NIL_P(rv))
                in_addr_set(rv, &addr, addrlen);
        return rv;
}

[Validate]

Generated with the Darkfish Rdoc Generator 2.