Hard
SO_RXQ_OVFL and sequence gaps on a UDP feed
A market-data receiver consumes a UDP multicast feed whose every payload carries a monotonic sequence number. To tell drops that happened inside this host apart from loss upstream, the operator enables SO_RXQ_OVFL and reads the ancillary counter attached to every recvmsg(). During one burst the receiver logs the values below: eight sequence numbers are missing. What does that log establish about the eight?
main.cpp
int one = 1;
setsockopt(fd, SOL_SOCKET, SO_RXQ_OVFL, &one, sizeof(one));
char buf[1500], cbuf[CMSG_SPACE(sizeof(uint32_t))];
struct iovec iov = { buf, sizeof(buf) };
struct msghdr msg = {};
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = cbuf;
for (;;) {
msg.msg_controllen = sizeof(cbuf);
recvmsg(fd, &msg, 0);
uint32_t ovfl = 0;
for (struct cmsghdr* c = CMSG_FIRSTHDR(&msg); c; c = CMSG_NXTHDR(&msg, c))
if (c->cmsg_level == SOL_SOCKET && c->cmsg_type == SO_RXQ_OVFL)
memcpy(&ovfl, CMSG_DATA(c), sizeof(ovfl));
log(seq_of(buf), ovfl);
}
// Logged during the burst:
// seq=1001 ovfl=0
// seq=1005 ovfl=3 <- 1002..1004 missing
// seq=1010 ovfl=7 <- 1006..1009 missing
// seq=1012 ovfl=7 <- 1011 missing16 of 45 in Networking