Fixing some test functions: no leaks when ending these programs.

master
Philippe Pittoli 2022-02-04 00:53:22 +01:00
parent 513348652e
commit e6edfd0e43
4 changed files with 28 additions and 9 deletions

View File

@ -32,6 +32,7 @@ int main(int argc, char * argv[])
printf ("error: %s\n", ipc_errors_get(ret.error_code));
return EXIT_FAILURE;
}
ipc_ctx_free (&ctx);
return EXIT_SUCCESS;
}

View File

@ -11,6 +11,7 @@ int main(int argc, char * argv[])
argc = (int) argc;
argv = (char **) argv;
SECURE_DECLARATION(struct ipc_ctx, ctx);
int timer = 10000; // 10 seconds timer

View File

@ -58,7 +58,7 @@ void read_message (struct ipc_ctx *ctx)
SECURE_DECLARATION (struct ipc_message, m);
TEST_IPC_Q(ipc_read (ctx, 0 /* only one server here */, &m), EXIT_FAILURE);
printf ("received message: %*.s\n", m.length, m.payload);
printf ("received message: %.*s\n", m.length, m.payload);
free (m.payload);
#endif
}
@ -76,11 +76,13 @@ int main(void)
read_message (&ctx1);
TEST_IPC_Q (ipc_close_all (&ctx1), EXIT_FAILURE);
ipc_ctx_free (&ctx1);
send_message (&ctx2);
read_message (&ctx2);
TEST_IPC_Q (ipc_close_all (&ctx2), EXIT_FAILURE);
ipc_ctx_free (&ctx2);
return EXIT_SUCCESS;
}

View File

@ -6,6 +6,20 @@
#include <string.h>
#define SERVICE_NAME "pong"
struct ipc_ctx *pctx = NULL;
void exit_program(int signal)
{
printf("Quitting, signal: %d\n", signal);
// the application will shut down, and close the service
TEST_IPC_Q(ipc_close_all (pctx), EXIT_FAILURE);
// free remaining ctx
ipc_ctx_free (pctx);
exit(EXIT_SUCCESS);
}
int main_loop(int argc, char * argv[])
{
@ -13,6 +27,7 @@ int main_loop(int argc, char * argv[])
argv = argv;
SECURE_DECLARATION (struct ipc_ctx, ctx);
pctx = &ctx;
int timer = 10000; // in ms
printf ("func 03 - server init...\n");
@ -41,8 +56,12 @@ int main_loop(int argc, char * argv[])
};
break;
case IPC_EVENT_TYPE_MESSAGE : {
printf ("received message: %s\n", ((struct ipc_message*) event.m)->payload);
ipc_write (&ctx, (struct ipc_message*) event.m);
struct ipc_message *m = (struct ipc_message*) event.m;
printf ("received message (%d bytes): %.*s\n"
, m->length
, m->length
, m->payload);
ipc_write (&ctx, m);
}
break;
case IPC_EVENT_TYPE_TX : {
@ -68,21 +87,17 @@ int main_loop(int argc, char * argv[])
return 0;
}
void exit_program(int signal)
{
printf("Quitting, signal: %d\n", signal);
exit(EXIT_SUCCESS);
}
int main(int argc, char * argv[])
{
// In case we want to quit the program, do it cleanly.
signal (SIGHUP, exit_program);
signal (SIGALRM, exit_program);
signal (SIGUSR1, exit_program);
signal (SIGUSR2, exit_program);
signal (SIGTERM, exit_program);
signal (SIGINT, exit_program);
main_loop (argc, argv);
return EXIT_SUCCESS;
}