I am trying to access the syslog messages on the router from the remote GUI application. Basically WEB server on the router openes syslog file(/var/log/messages), read all the log messages and try to send it over this WEB socket to client GUI application on user request. Its a non blocking socket. So I observed that when the number of messages are huge(size of send buffer is big), upon calling send() call, it is always returning -1 with error EWOULDBLOCK. I tried to reissue the call many time and the same result followed. Is this implies that send buffer is full on TCP/IP stack ? So how to avoid it ? I even observed that when the send buffer is less, send() is successfully sending data. Thanks for your replies in advance ?
1 Answers
2
votes
You can set the sender buffer to a large size:
int sendbuf = -1; /* -1 will give a maximum allowed buffer size you can use any larger number */
rc = setsockopt(sd, SOL_SOCKET, SO_SNDBUF,(char *)&sendbuf, sizeof(sendbuf));
if(rc < 0){
printf(("Setting SO_SNDBUF error, %s",strerror(errno)));
return -1;
}
To avoid EWOULDBLOCK (this errno happens when send buffer is full) you should use iomux (epoll, poll or select) also, this errno happens when receive buffer is empty when trying to receive.
send()messages that are larger that the send buffer,send()will always return EWOULDBLOCK. Perhaps trying splitting the log messages into chunks guaranteed not to exceed the TCP/UDP send buffer. You can adjust the size of the buffer (within limits withsetsockopt()). - isedev