I want to use non-blocking API of recv but it doesn't work after 64KB data and give error: Resource temporarily unavailable. So I use if(error == EAGAIN) but it stuck on receive because no data is available.
while(true) {
ret = recv(csd, buf, size, MSG_DONTWAIT);
if(errno == EAGAIN) {
continue;
}
if (ret < 0) {
perror("Error in receive\n");
close(csd);
exit(EXIT_FAILURE);
} else if (ret == 0) {
fprintf(stderr, "client disconnected\n");
close(csd);
} else {
return buf;
}
}
select()
instead of spin looping, or indeed use blocking mode, as you don't have anything else to do in between. Try a smaller receive buffer. – user207421