我想做一个简单的多进程(不是线程)服务器。我已经看到了它一次处理一个请求的迭代示例。相反,我需要同时处理更多请求(更少 10 个请求更多)。在经典的 c 和 c++ 示例中,我看到服务器的设计如下:
int listensd, connsd; // listening socket and conection socket
pid_t pid; //process id
listensd=socket(....);
bind(listensd,...);
listen(listensd,...);
for(;;)
{
connsd=accept(listensd,...);
if((pid=fork())==0) //child process
{
close(listensd); //close the listen socket
do_it(connsd); //serve the request
close(connsd); //close the connection socket
exit(0);
}
close(connsd); //the parent closes the connection socket
}
是否可以通过 boost 做类似的事情?我真的不知道如何获得这两个不同的套接字,因为在 boost 中所有的函数(listen
、、、bind
等accept
)都返回 void。