Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing accept() and select() at the same time?
    primarykey
    data
    text
    <p>I've got an event-driven network server program. This program accepts connections from other processes on other hosts. There may be many short-lived connections from different ports on the same remote IP.</p> <p>Currently, I've got a <code>while(1)</code> loop which calls <code>accept()</code> and then spawns a thread to process the new connection. Each connection is closed after the message is read. On the remote end, the connection is closed after a message is sent.</p> <p>I want to eliminate the overhead of setting up and tearing down connections by caching the open socket FDs. On the sender side, this is easy - I just don't close the connections, and keep them around.</p> <p>On the receiver side, it's a bit harder. I know I can store the FD returned by <code>accept()</code> in a structure and listen for messages across all such sockets using <code>poll()</code> or <code>select()</code>, but I want to simultaneously both listen for new connections via <code>accept()</code> <strong>and</strong> listen on all the cached connections.</p> <p>If I use two threads, one on <code>poll()</code> and one on <code>accept()</code>, then when the <code>accept()</code> call returns (a new connection is opened), I have to wake up the other thread waiting on the old set of connections. I know I can do this with a signal and <code>pselect()</code>, but this whole mess seems like way too much work for something so simple.</p> <p>Is there a call or superior methodology that will let me simultaneously handle new connections being opened and data being sent on old connections?</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.
 

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