2019-07-27 15:48:56 +02:00
|
|
|
#include "../src/ipc.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define SERVICE_NAME "pong"
|
|
|
|
|
2020-07-13 14:12:08 +02:00
|
|
|
int main(int argc, char * argv[])
|
2019-07-27 15:48:56 +02:00
|
|
|
{
|
2020-01-01 12:11:34 +01:00
|
|
|
argc = (int) argc;
|
|
|
|
argv = (char **) argv;
|
|
|
|
|
2022-02-04 00:53:22 +01:00
|
|
|
|
2020-07-13 14:12:08 +02:00
|
|
|
SECURE_DECLARATION(struct ipc_ctx, ctx);
|
|
|
|
int timer = 10000; // 10 seconds timer
|
2019-07-27 15:48:56 +02:00
|
|
|
|
|
|
|
printf ("func 01 - server init...\n");
|
2020-07-13 14:12:08 +02:00
|
|
|
TEST_IPC_Q(ipc_server_init (&ctx, SERVICE_NAME), EXIT_FAILURE);
|
|
|
|
|
2019-07-27 15:48:56 +02:00
|
|
|
printf ("func 01 - server init ok\n");
|
2020-07-13 14:12:08 +02:00
|
|
|
SECURE_DECLARATION(struct ipc_event, event);
|
2019-07-27 15:48:56 +02:00
|
|
|
|
|
|
|
printf ("func 01 - service polling...\n");
|
2020-01-01 12:11:34 +01:00
|
|
|
|
2019-07-27 15:48:56 +02:00
|
|
|
// listen only for a single client
|
2020-07-13 14:12:08 +02:00
|
|
|
TEST_IPC_Q(ipc_wait_event (&ctx, &event, &timer), EXIT_FAILURE);
|
2019-07-27 15:48:56 +02:00
|
|
|
|
|
|
|
switch (event.type) {
|
2020-01-01 12:11:34 +01:00
|
|
|
case IPC_EVENT_TYPE_TIMER : {
|
|
|
|
fprintf(stderr, "time up!\n");
|
|
|
|
|
2020-07-13 14:12:08 +02:00
|
|
|
timer = 10000;
|
2020-01-01 12:11:34 +01:00
|
|
|
};
|
|
|
|
break;
|
2019-07-27 15:48:56 +02:00
|
|
|
case IPC_EVENT_TYPE_CONNECTION :
|
|
|
|
{
|
|
|
|
printf ("ok - connection establishment\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IPC_EVENT_TYPE_NOT_SET :
|
|
|
|
case IPC_EVENT_TYPE_ERROR :
|
|
|
|
case IPC_EVENT_TYPE_EXTRA_SOCKET :
|
|
|
|
case IPC_EVENT_TYPE_DISCONNECTION :
|
|
|
|
case IPC_EVENT_TYPE_MESSAGE :
|
|
|
|
default :
|
|
|
|
printf ("not ok - should not happen\n");
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("func 01 - closing server...\n");
|
2020-07-13 14:12:08 +02:00
|
|
|
TEST_IPC_Q(ipc_close_all(&ctx), EXIT_FAILURE);
|
|
|
|
|
|
|
|
printf ("func 01 - closing ctx...\n");
|
|
|
|
ipc_ctx_free (&ctx);
|
2019-07-27 15:48:56 +02:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|