c++ - boost::asio server multi-process -


i make simple multi process (not thread) server. i've seen iterative example in handles 1 request @ time. instead need handle more requests(more on less 10) @ same time. in classic c , c++ examples, i've seen server designed following:

int listensd, connsd; // listening socket , 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 listen socket         do_it(connsd);    //serve request         close(connsd);    //close connection socket         exit(0);     } close(connsd);     //the parent closes connection socket } 

is possible boost? don't know how obtain 2 different socket, because in boost function (listen, bind, accept, etc.) return void.

yes, it's possible use boost.asio fork process each connection. see bsd socket api boost.asio documentation mappings bind, listen, accept relevant boost.asio types.

though, pointed out in comment, don't feel design scales @ all. you're better off learning asynchronous design patterns , using real strengths of boost.asio library. more information, see c10k problem.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -