I have a parent process which creates 2 server sockets and calls select()
on them to wait for new connection. When the connection arrives, a message is sent to a child process (created with fork()
, after servers sockets creation, so they are shared).
In this child, calling accept()
on the server socket doesn't work. I got a EAGAIN
error (non-blocking socket). Whereas calling accept()
in the main process works perfectly.
Of course, I don't call accept()
in the main process at all, I just tested to check if it worked, and it does.
Why can't I call accept()
in a child process after a select()
in the parent?
EDIT: The goal here is to create a fixed number of workers (let's say 8) to handle clients connections, as in the prefork model. These connections will be long-connections, not like HTTP. The goal is to load-balance connections between workers.
To do this, I use a shared memory variable which contains for a worker the number of currently connected clients. I want to "ask" the worker with the lowest number of clients to handle a new connection.
That's why I do the select()
in the parent, and then send a message to a child process, because I want to "choose" which process will handle the new connection.
The server listen on more than one sockets (one for ssl, one without), that's why I use select()
and not directly accept()
in children processes, because I can't accept()
on multiple sockets in my children workers.
Aucun commentaire:
Enregistrer un commentaire