I am implementing a web server where I need to make the parent process do the following:
fork()
new worker processes (a pool) at the beginning.- Looping forever, listening for incoming requests (via socket communication).
- Putting the socket descriptor (returned by
accept()
function) into a queue.
and the worker process will do the following:
- Once created, loops forever watching the queue for any passed socket descriptors.
- If he takes the socket descriptor, he handles the request and serves the client accordingly.
After looking around and searching the internet, I found that I can send a file descriptor between different processes via UNIX Domain Socket
or Pipes
. But unfortunately, I can do this synchronously only! (I can send one fd
at a time, and I cannot put it in a waiting queue)
So, my question is:
- How can I make the parent process puts the socket descriptor into a waiting queue, so that, the request is pending until one of the worker processes finishes a previous request?