Hard
Aggressive keepalive settings and a peer that dies mid-transfer
A Linux drop-copy publisher sets the options below and expects a dead subscriber to be detected in about 8 seconds. The subscriber's host loses power while the publisher is mid-stream, with unacknowledged data in flight. The publisher's send() calls succeed until the send buffer fills, then block, and the connection is not declared dead for roughly 15 minutes. Why?
main.cpp
int on = 1, idle = 5, intvl = 1, cnt = 3;
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on));
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl));
setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
for (;;) send(fd, &report, sizeof(report), 0); // continuous stream44 of 45 in Networking