Skip to content

SocketPoll

Description

Wait until any item is ready. Backed by poll() for now; the signature is intentionally event-driven so an epoll/kqueue implementation can swap in later without breaking callers.

Parameters

Name Direction Description
items in,out Array of items. Caller fills fd + events_requested; events_ready is the output.
count in Number of items in items.
timeout_ms in -1 = block forever, 0 = poll once, >0 = milliseconds.

Success

returns number of items with non-zero events_ready.

Failure

returns -1; logs the failing syscall. EINTR is transparently retried.

Usage example (Cross-references)

Usage examples (Cross-references)
    // ---------------------------------------------------------------------------
    
    i32 SocketPoll(SocketPollItem *items, u32 count, i32 timeout_ms) {
        if (!items && count > 0) {
            LOG_ERROR("SocketPoll: items is NULL but count > 0");
    i32 SocketPoll(SocketPollItem *items, u32 count, i32 timeout_ms) {
        if (!items && count > 0) {
            LOG_ERROR("SocketPoll: items is NULL but count > 0");
            return -1;
        }
            if (!pfds) {
                HeapAllocatorDeinit(&halloc);
                LOG_ERROR("SocketPoll: heap allocation for pollfd array failed");
                return -1;
            }
    
        if (ret < 0) {
            LOG_SYS_ERROR("SocketPoll: poll() failed");
        } else {
            for (u32 i = 0; i < count; ++i) {
            items[1] = (SocketPollItem) {.fd = b->fd, .events_requested = SOCKET_POLL_READ};
    
            i32 ready = SocketPoll(items, 2, 1000);
            if (ready < 0) {
                return;
                // log noise when it does).
                SocketPollItem listen_item = {.fd = listener.fd, .events_requested = SOCKET_POLL_READ};
                i32            ready       = SocketPoll(&listen_item, 1, 1000);
                if (ready <= 0) {
                    continue;
Last updated on