Skip to content
Snippets Groups Projects
Commit 0d446ddf authored by Marek Vavrusa's avatar Marek Vavrusa
Browse files

Made cute_start() non-blocking, blocking moved to cute_wait().

parent fe1d7558
No related branches found
No related tags found
No related merge requests found
......@@ -54,11 +54,15 @@ int main( int argc, char **argv )
sa.sa_flags = 0;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGCLOSE, &sa, NULL); // Interrupt
sigaction(SIGREADY, &sa, NULL); // Notification - server is ready
// Run server
if ((res = cute_start(s_server, argv + 1, argc - 1)) != 0) {
fprintf (stderr, "Problem starting the server, exiting..\n");
if ((res = cute_start(s_server, argv + 1, argc - 1)) == 0) {
if((res = cute_wait(s_server)) != 0) {
log_error("There was an error while waiting for server to finish.");
}
}
else {
log_error("There was an error while starting the server, exiting...\n");
}
// Stop server and close log
......
......@@ -108,19 +108,21 @@ int cute_start( cute_server *server, char **filenames, uint zones )
if(ret < 0)
return ret;
// Server is ready
raise(SIGREADY);
// Wait for dispatchers to finish
ret = sm_wait(server->manager[TCP]);
return ret;
}
debug_server("TCP handler finished.\n");
/*----------------------------------------------------------------------------*/
ret += sm_wait(server->manager[UDP]);
int cute_wait(cute_server *server)
{
// Wait for dispatchers to finish
int ret = sm_wait(server->manager[TCP]);
debug_server("TCP handler finished.\n");
debug_server("UDP handler finished.\n");
ret += sm_wait(server->manager[UDP]);
debug_server("UDP handler finished.\n");
return ret;
return ret;
}
/*----------------------------------------------------------------------------*/
......
......@@ -57,6 +57,17 @@ cute_server *cute_create();
*/
int cute_start( cute_server *server, char **filenames, uint zones );
/*!
* @brief Waits for the server to finish.
*
* @param server Server structure to be used for operation.
*
* @retval 0 On success.
* @retval -1 If an error occured.
*
*/
int cute_wait(cute_server *server);
/*!
* @brief Requests server to stop.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment