Hi there. I'm developing a tool, which uses non-blocking sockets on Linux.
When I'm sending something to socket with send(), the return value is -1, which means error. But it's not an error. <errno> indicates that this is EWOULDBLOCK, which means that my request will be async ;-)
I want to get number of bytes really written to socket, but not -1 as I get now.
When I'm sending something to socket with send(), the return value is -1, which means error. But it's not an error. <errno> indicates that this is EWOULDBLOCK, which means that my request will be async ;-)
I want to get number of bytes really written to socket, but not -1 as I get now.
Code:
switch (errno)
{
case EWOULDBLOCK:
while (1)
{
tv.tv_sec = timeout; /* my timeout */
tv.tv_usec = 0;
/* here - wait for socket is ready to write*/
FD_ZERO (&writefds);
FD_SET (priv->socket, &writefds);
rc = select (priv->socket+1, NULL, &writefds, NULL, &tv);
if (rc < 0)
{
/* error on select() */
return 1;
}
else if (rc==0)
{
/* time out */
continue;
}
else if (rc > 0)
{
/* data was sended */
/* HERE I want to get number of bytes really written */
break;
}
}
break;
Comment