Рейтинг@Mail.ru

Module coio

Module coio

enum COIO_EVENT
enumerator COIO_READ

READ event

enumerator COIO_WRITE

WRITE event

int coio_wait(int fd, int event, double timeout)

Wait until READ or WRITE event on socket (fd). Yields.

Parameters:
  • fd (int) – non-blocking socket file description
  • event (int) – requested events to wait. Combination of COIO_READ | COIO_WRITE bit flags.
  • timeout (double) – timeout in seconds.
Returns:

0 - timeout

Returns:

>0 - returned events. Combination of TNT_IO_READ | TNT_IO_WRITE bit flags.

ssize_t coio_call(ssize_t (*func)(va_list), ...)

Create new eio task with specified function and arguments. Yield and wait until the task is complete or a timeout occurs. This function may use the worker_pool_threads configuration parameter.

To avoid double error checking, this function does not throw exceptions. In most cases it is also necessary to check the return value of the called function and perform necessary actions. If func sets errno, the errno is preserved across the call.

Returns:-1 and errno = ENOMEM if failed to create a task
Returns:the function return (errno is preserved).

Example:

static ssize_t openfile_cb(va_list ap)
{
        const char* filename = va_arg(ap);
        int flags = va_arg(ap);
        return open(filename, flags);
}

if (coio_call(openfile_cb, 0.10, "/tmp/file", 0) == -1)
    // handle errors.
...
int coio_getaddrinfo(const char *host, const char *port, const struct addrinfo *hints, struct addrinfo **res, double timeout)

Fiber-friendly version of getaddrinfo(3).

int coio_close(int fd)

Close the fd and wake any fiber blocked in coio_wait() call on this fd.

Parameters:
  • fd (int) – non-blocking socket file description
Returns:

the result of close(fd), see close(2)