Note that there are some explanatory texts on larger screens.

plurals
  1. POCompute data from multiple clients simultaneously
    primarykey
    data
    text
    <p>I'm trying to write a server able to handle multiple (more than a thousand) client connections concurrently in C language. Every connection is meant to accomplish three things: </p> <ol> <li>Send data to the server</li> <li>The server processes the data</li> <li>The server returns data to the client</li> </ol> <p>I am using non-blocking sockets and epoll() for handling all the connections, but my problem is right in the moment after the server receives the data from one client and has to call a function which spends several seconds in processing the data before it returns the result that has to be sent back to the client before closing the connection.</p> <p>My <strong>question</strong> is, what paradigm can I use in order to be able to keep handling more connections while the data of one client "is cooking"?</p> <p>I've been researching a bit about the possibilities of doing it by <strong>creating a thread or a process every time</strong> I need to call the computing function, but I'm not sure if this would be possible given the number of possible concurrent connections, that's why I came here expecting that someone more experienced that me in the matter could shed some light on my ignorance.</p> <hr> <p><strong>Code snippet:</strong></p> <pre><code>while (1) { ssize_t count; char buf[512]; count = read (events[i].data.fd, buf, sizeof buf); // read the data if (count == -1) { /* If errno == EAGAIN, that means we have read all data. So go back to the main loop. */ if (errno != EAGAIN) { perror ("read"); done = 1; } /* Here is where I should call the processing function before exiting the loop and closing the actual connection */ answer = proc_function(buf); count = write (events[i].data.fd, answer, sizeof answer); // send the answer to the client break; } ... </code></pre> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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. 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