Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wanted to post this in a comment above but it got much longer than it would allow:</p> <p>Try implementing a simple epoll based server that is entirely asynchronous (steps)</p> <ol> <li>Set up your accept socket ...</li> <li>Add to epoll.</li> <li>enter wait loop: <ol> <li>Check whether event is on accept socket, or normal socket</li> <li>If accept socket, accept connection, add to epoll, go back to 3</li> <li>If event on normal socket for reading, read X bytes, save to write buffer, and enable write event on epoll for socket, go back to 3</li> <li>If event on normal socket for writing, write bytes from buffer to network, disable write event if write buffer is empty, go back to 3.</li> <li>If an error occurs remove the socket from epoll </li> </ol></li> <li>There is no fourth step ... the program should loop forever.</li> </ol> <p>This should remove any complexity you've added from having threading that could cause issues. This moves epoll back into the same sort of domain as <code>select()</code> except that it is generally much faster. The whole idea of using an event library is to know when you can read/write instead of setting a socket to non-blocking, and trying to read from it/write to it.</p> <p>You also never seem to check the return value from <code>write()</code> which may have failed due to receiving a SIGPIPE (I know you ignored the signal, but you will still get an EAGAIN/EINTR errno).</p> <p>The other thing I see is that you are doing a busy loop inside of your thread that is waiting for sockets to be ready. When you use <code>select()</code> or <code>epoll</code> in this case it is so that you are notified that there is something new, so you don't have to do a busy loop...</p> <p>I am not exactly sure what you are attempting to accomplish, but your code is extremely inefficient.</p> <p>What you could do, after implementing just a simple asynchronous example using the steps above is start up multiple worker threads that all listen (using epoll) for <code>read</code> events on the <code>listener</code>/<code>accept</code> socket and have each of the threads handle various connections (still using what I posted above).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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