multi-process model: Improve

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
main^2
Jianhui Zhao 2021-01-03 18:15:06 +08:00
parent c11052e302
commit d6868b6ab3
3 changed files with 8 additions and 2 deletions

View File

@ -196,8 +196,6 @@ int main(int argc, char **argv)
goto err; goto err;
#endif #endif
srv->start_worker(srv, -1); /* -1 means automatically to available CPUs */
srv->set_docroot(srv, docroot); srv->set_docroot(srv, docroot);
srv->set_index_page(srv, index_page); srv->set_index_page(srv, index_page);
@ -208,6 +206,12 @@ int main(int argc, char **argv)
if (plugin_path) if (plugin_path)
srv->load_plugin(srv, plugin_path); srv->load_plugin(srv, plugin_path);
/*
** -1 means automatically to available CPUs
** This function must be called after the Server has been initialized
*/
srv->start_worker(srv, -1);
ev_signal_init(&signal_watcher, signal_cb, SIGINT); ev_signal_init(&signal_watcher, signal_cb, SIGINT);
ev_signal_start(loop, &signal_watcher); ev_signal_start(loop, &signal_watcher);

View File

@ -159,6 +159,7 @@ static void uh_start_worker(struct uh_server *srv, int n)
case 0: case 0:
ev_loop_fork(srvi->loop); ev_loop_fork(srvi->loop);
uh_start_accept(srvi); uh_start_accept(srvi);
ev_run(srvi->loop, 0);
return; return;
} }
} }

View File

@ -81,6 +81,7 @@ struct uh_server {
void (*free)(struct uh_server *srv); void (*free)(struct uh_server *srv);
/* /*
** Start n worker processes to process the requests ** Start n worker processes to process the requests
** Must be called after the Server has been initialized
** If n is -1, automatically to available CPUs ** If n is -1, automatically to available CPUs
*/ */
void (*start_worker)(struct uh_server *srv, int n); void (*start_worker)(struct uh_server *srv, int n);