Half A Message Left

A server registers each connected socket with EPOLLIN | EPOLLET and runs this loop. All sockets are non-blocking.

for (;;) {
    int n = epoll_wait(ep, evs, MAX, -1);
    for (int i = 0; i < n; i++) {
        char buf[1024];
        ssize_t r = read(evs[i].data.fd, buf, sizeof buf);
        if (r > 0) handle(buf, r);
    }
}

A client sends 2048 bytes in one write and then waits for the reply. What happens?

A

The kernel splits the 2048-byte arrival into two EPOLLIN events, so the second half is handled on the next iteration

B

The first 1024 bytes are handled; the rest sits unread in the socket buffer and no further event is reported, so the connection stalls until the client happens to send more

C

epoll_wait returns the same fd again on the next call, because 1024 bytes are still readable

D

The second read returns EAGAIN, so the loop correctly waits for the next event