Class: Kgio::TCPServer

### Home Classes Methods

### In Files

- ext/kgio/accept.c

### Parent

cTCPServer

### Methods

- #kgio_accept
- #kgio_tryaccept

### 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::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
kgio_tryaccept → Kgio::Socket or nil
kgio_tryaccept(klass = MySocket) → MySocket 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 `klass` argument may be specified to override the Kgio::Socket-class on a successful return value.

An optional `flags` argument may also be specified. `flags` is a bitmask that may contain any combination of:

- Kgio::SOCK_CLOEXEC - close-on-exec flag (enabled by default)

- Kgio::SOCK_NONBLOCK - non-blocking flag (unimportant)

    static VALUE tcp_accept(int argc, VALUE *argv, VALUE self)
    {
            struct sockaddr_storage addr;
            socklen_t addrlen = sizeof(struct sockaddr_storage);
            struct accept_args a;

            a.addr = (struct sockaddr *)&addr;
            a.addrlen = &addrlen;
            prepare_accept(&a, self, argc, argv);
            return my_accept(&a, 0);
    }

server = Kgio::TCPServer.new('0.0.0.0', 80) click to toggle source
kgio_tryaccept → Kgio::Socket or nil
kgio_tryaccept(klass = MySocket) → MySocket or nil
kgio_tryaccept(nil, flags) → 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 `klass` argument may be specified to override the Kgio::Socket-class on a successful return value.

An optional `flags` argument may also be specified. `flags` is a bitmask that may contain any combination of:

- Kgio::SOCK_CLOEXEC - close-on-exec flag (enabled by default)

- Kgio::SOCK_NONBLOCK - non-blocking flag (unimportant)

    static VALUE tcp_tryaccept(int argc, VALUE *argv, VALUE self)
    {
            struct sockaddr_storage addr;
            socklen_t addrlen = sizeof(struct sockaddr_storage);
            struct accept_args a;

            a.addr = (struct sockaddr *)&addr;
            a.addrlen = &addrlen;
            prepare_accept(&a, self, argc, argv);
            return my_accept(&a, 1);
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.