问题
I've been trying to implement a web server gateway (for fun and educational purposes) and I have some questions about the core architecture behind FastCGI/SCGI with respect to the pre-fork model.
How do FastCGI/SCGI implementations handle communication in pre-fork scenarios? AFAIK, the gateway only has one socket to connect to the FastCGI server. Normally, there is a parent process that accepts connections from the gateway and hands off the work to one of the pre-forked workers.
Since the connections are established after the children are forked, how are you supposed to have the children use these sockets to communicate with the gateway?
回答1:
I hope I understood the question.
The server socket should be created by the parent process; when it forks, children inherit that socket making it a shared resource. Then, I suppose, each child tries to accept() connections concurrently.
As a reference I found this document (see "accept serialization") discussing starvation issue when listening on multiple sockets, and this SO discussion on sharing sockets
回答2:
One options is file descriptor passing over UNIX domain socket. Stevens UNP has basic example.
来源:https://stackoverflow.com/questions/6797222/fastcgi-scgi-pre-fork