diff --git a/examples/pongd.c b/examples/pongd.c index 7b657ba..be6d170 100644 --- a/examples/pongd.c +++ b/examples/pongd.c @@ -23,7 +23,7 @@ ****************************************************************************** * Overview of the main loop: * 1. "ctx" pointer declaration (struct ipc_ctx). - * 1. ipc_server_init (env, ctx, SERVICE_NAME) + * 1. ipc_server_init (ctx, SERVICE_NAME) ****************************************************************************** */ @@ -35,8 +35,8 @@ struct ipc_ctx *ctx = NULL; void main_loop () { - double base_timer = 0; - double timer = base_timer; + int base_timer = 10000; + int timer = base_timer; SECURE_DECLARATION (struct ipc_error, ret); SECURE_DECLARATION (struct ipc_event, event); @@ -45,14 +45,14 @@ void main_loop () while (1) { // ipc_wait_event provides one event at a time // warning: event->m is free'ed if not NULL - TEST_IPC_WAIT_EVENT_Q (ipc_wait_event (ctx, srv, &event, &timer), EXIT_FAILURE); + TEST_IPC_WAIT_EVENT_Q (ipc_events_loop (ctx, &event, &timer), EXIT_FAILURE); switch (event.type) { case IPC_EVENT_TYPE_CONNECTION: { cpt++; if (verbosity > 1) { - printf ("connection: %d ctx connected, new client is %d\n", cpt, (event.origin)->fd); + printf ("connection: %d ctx connected, new client is %d\n", cpt, event.origin); } }; break; @@ -62,9 +62,6 @@ void main_loop () if (verbosity > 1) { printf ("disconnection: %d ctx remaining\n", cpt); } - - // free the ipc_client structure - free (event.origin); }; break; case IPC_EVENT_TYPE_MESSAGE: @@ -79,7 +76,7 @@ void main_loop () } } - ret = ipc_write (event.origin, m); + ret = ipc_write (ctx, m); if (ret.error_code != IPC_ERROR_NONE) { PRINTERR (ret, "server write"); } @@ -97,11 +94,8 @@ void main_loop () case IPC_EVENT_TYPE_ERROR: { cpt--; - fprintf (stderr, "a problem happened with client %d (now disconnected)", (event.origin)->fd); + fprintf (stderr, "a problem happened with client %d (now disconnected)", event.origin); fprintf (stderr, ", %d ctx remaining\n", cpt); - - // free the ipc_client structure - free (event.origin); }; break; default: @@ -119,24 +113,14 @@ void exit_program (int signal) { printf ("Quitting, signal: %d\n", signal); - // free remaining ctx - for (size_t i = 0; i < ctx->size; i++) { - struct ipc_connection_info *cli = ctx->cinfos[i]; - if (cli != NULL) { - free (cli); - } - ctx->cinfos[i] = NULL; - } - - ipc_connections_free (ctx); - free (ctx); - // the application will shut down, and close the service - struct ipc_error ret = ipc_server_close (srv); + struct ipc_error ret = ipc_close_all (ctx); if (ret.error_code != IPC_ERROR_NONE) { PRINTERR (ret, "server close"); } - free (srv); + + ipc_ctx_free (ctx); + free (ctx); exit (EXIT_SUCCESS); } @@ -146,7 +130,7 @@ void exit_program (int signal) * stop the program on SIG{TERM,INT,ALRM,USR{1,2},HUP} signals */ -int main (int argc, char *argv[], char **env) +int main (int argc, char *argv[]) { argc = argc; // warnings argv = argv; // warnings @@ -157,7 +141,7 @@ int main (int argc, char *argv[], char **env) printf ("pid = %d\n", getpid ()); - struct ipc_error ret = ipc_server_init (env, &ctx, PONGD_SERVICE_NAME); + struct ipc_error ret = ipc_server_init (ctx, PONGD_SERVICE_NAME); if (ret.error_code != IPC_ERROR_NONE) { PRINTERR (ret, "server init"); return EXIT_FAILURE;