1
votes

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
If your socket is non-blocking, you need to poll it and respond to "ready to write" events. In the meantime, you need to queue up the data you want to send yourself. - Kerrek SB
@Kerrek Thanks for reply . I am doing the same thing. I am maintaining one fifo and waiting for FD_WRITE events. How much time/conditions will it take to signal this event to user space? - Gowtam
The TCP/UDP send buffer is of finite size. If you are trying to 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 with setsockopt()). - isedev

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.