I had simple web server that fork()
and use accept()
inside child process.
Here is pseudo-code:
void server_child_process(int server_socket){
// ...
while (true){
if ( ( client = accept(server_socket, addr, addrlen) ) == false ){
server_debug("Can not socket_accept()...");
}
//...
}
}
accept()
seems to have no problem and no need for any synchronization.
With fork()
model you can have several accept()
at the same time. Single connection is always accepted once from single random child process.
(e.g. no connection is accepted from two children)
This model is often called pre-fork, because theoretically after initial fork()
no new fork()
are made.
Can I do the same in a thread?