EAGAIN/EWOULDBLOCK can also be returned (for TCP sockets) when the number of unacknowledged packets has reached the congestion window.
To check the status of the socket w.r.t. the congestion window, then try this:
#include <netinet/tcp.h>
static void print_tcp_cwnd(int socket)
{
struct tcp_info tcp_info;
uint tcp_info_length = sizeof(tcp_info);
if ( getsockopt( socket, SOL_TCP, TCP_INFO, (void *)&tcp_info, &tcp_info_length ) == 0 )
{
printf("tcpi_snd_cwnd: %u, tcpi_unacked: %u\n",
tcp_info.tcpi_snd_cwnd,
tcp_info.tcpi_unacked
);
}
}
If tcpi_unacked == tcpi_snd_cwnd then send() will return EAGAIN/EWOULDBLOCK for a non-blocking socket.