Hi All
I am using a non blocking Socket for sending messages.We were getting EGAIN error occassioanally .So I have decided to use Flush(socket) to flush the buffer and make space for new space so that i can avoid EGAIN error .But the problem is Flush(socket) is stuck for indefinite time .
Here is the code
int res = send(socket, buffer, size+lengthSize,0);
delete buffer;
if ( res== -1 )
{
int error = errno;
cout("ERROR on SendOnPortString, errno = " << error);
return 0 ;
}
else
{
cout<<"Send SucessFul = " << res << "Total Message size"<< size+lengthSize;
if(res==size+lengthSize)
flush((ostream&)socket);
//flush(socket);
return 1 ;
}
This code printing
Send SucessFul = 11Total Message size 11
But after that its getting stuck in flush(socket) method .Any Idea why its behaving like that
You cast a socket handle of type
intto a reference to astd::ostreamin order to avoid compiler warnings/errors when you tried to hand it toflush. I’m surprised it’s not crashing.You can’t make more space. The problem isn’t you: the problem is that the system’s internal buffers are full, and they will drain at their own pace in their own time. You can either poll by trying to
sendover and over till it works (in which case, why are you using non-blocking sockets?), or you useselect,poll,kqueue,epoll,libevent, etc. to sleep till the socket is able to accept more data.