Short Write Long Night
This length-prefixed framing helper has passed every test with small frames. In production it starts returning -1 for large frames even though the socket is healthy and the peer is alive. The socket is blocking and carries SO_SNDTIMEO of five seconds.
/* returns len on success, -1 on failure */
ssize_t send_frame(int fd, const uint8_t *buf, size_t len)
{
uint32_t n = htonl((uint32_t)len);
if (send(fd, &n, 4, 0) != 4)
return -1;
if (send(fd, buf, len, 0) != (ssize_t)len)
return -1;
return (ssize_t)len;
}
A 2 MB frame is sent over a slow link. What actually happened, and what breaks next?
Sign in to answer questions and track your progress
Sign In