Note that there are some explanatory texts on larger screens.

plurals
  1. POC: Data forwarding server using epoll ET fills the send buffer
    text
    copied!<p>I have the following situation. My server receives data from remote server (fd_server) and forwards it to the client (fd_client). I'm using edge triggered epoll so I can handle multiple clients and multiple server conncetions.</p> <p>Procedure:</p> <ol> <li>client connects to the server.</li> <li>my server connects to the remote server and requests data.</li> <li>remote server responds and my server forwards data to the client.</li> </ol> <p>Details:</p> <p>After my server connects to the remote server the fd_server is added to epoll control with EPOLLIN flag. Server waits for events.</p> <p>When epoll_wait return the fd_server as readable I go in the following loop displayed bellow.</p> <p>After some read/writes my sctp_sendmsg return EAGAIN, which means sctp send buffer is full. How should I handle this situation without loosing the data I have already read from the fd_server socket?</p> <p>IS there a way of knowing before hand, how much data can I send, so I only read the right amount?</p> <pre><code>while(1){ N = recv(fd_server,buf, sizeof buf,0); if (N == -1){ /* If errno == EAGAIN, that means we have read all data. So go back to the main loop. */ if (errno != EAGAIN){ perror ("tcp_recv error"); } break; } if(N == 0){ /* End of file. The remote has closed the connection. */ close(fd_server); break; } pos = 0; while(pos &lt; N){ got = sctp_sendmsg(fd_client, &amp;buf[pos], N-pos, to, tolen, 0, 0, stream, 0, 0); if(got&lt;=0){ if (errno == EAGAIN){ //what to do? }else{ perror("tcp to sctp send error"); } } else{ pos += got;} } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload