Three bugs in the overflow test caused intermittent failures:
- The send buffer accepts exactly sendspace bytes before returning EAGAIN. The assertion sizeof(hdr) * cnt > sendspace was too strict; change it to >=.
- The fullsocket() loop exited when recvavail > recvspace - rsize, but the kernel's taskqueue only stops when the receive buffer is at or past its hiwat (recvavail >= recvspace). Exiting the loop too early meant the taskqueue was still running and could drain a send buffer slot between fullsocket() returning and the blocking send(), causing the send to succeed when it should block. Wait until recvavail >= recvspace.
- The kernel uses ignore_limit=true when writing replies, so the receive buffer can overflow its hiwat by up to one full reply's worth of bytes. A single recv(buf, BUFLEN=1000) call may not consume enough data to bring the buffer below hiwat, leaving the taskqueue stuck. Replace the single recv() with a drain loop that reads until FIONREAD < SO_RCVBUF, guaranteeing the taskqueue can proceed and drain the send buffer for the subsequent blocking send().