2019-07-27 15:48:10 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "../src/ipc.h"
|
|
|
|
|
2020-01-01 12:11:34 +01:00
|
|
|
int main (int argc, char *argv[], char *env[])
|
2019-07-27 15:48:10 +02:00
|
|
|
{
|
2020-01-01 12:11:34 +01:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
2019-07-27 15:48:10 +02:00
|
|
|
|
2020-01-01 12:11:34 +01:00
|
|
|
SECURE_DECLARATION (struct ipc_error, ret);
|
2019-07-27 15:48:10 +02:00
|
|
|
SECURE_DECLARATION (struct ipc_connection_info, srv);
|
|
|
|
SECURE_DECLARATION (struct ipc_connection_info, client);
|
|
|
|
SECURE_DECLARATION (struct ipc_connection_info, contacted_service);
|
|
|
|
|
|
|
|
// service start
|
2020-01-01 12:11:34 +01:00
|
|
|
TEST_IPC_Q (ipc_server_init (env, &srv, "network"), EXIT_FAILURE);
|
2019-07-27 15:48:10 +02:00
|
|
|
|
|
|
|
printf ("service initialized, waiting for a client\n");
|
|
|
|
|
|
|
|
// accept a new client
|
2020-01-01 12:11:34 +01:00
|
|
|
TEST_IPC_Q (ipc_accept (&srv, &client), EXIT_FAILURE);
|
2019-07-27 15:48:10 +02:00
|
|
|
|
|
|
|
// TODO: read a message to know the requested service
|
|
|
|
SECURE_DECLARATION (struct ipc_message, msg);
|
2020-01-01 12:11:34 +01:00
|
|
|
TEST_IPC_Q (ipc_read (&client, &msg), EXIT_FAILURE);
|
2019-07-27 15:48:10 +02:00
|
|
|
printf ("received message: %s\n", msg.payload);
|
|
|
|
|
|
|
|
/** TODO: contact the service */
|
2020-01-01 12:11:34 +01:00
|
|
|
printf ("WARNING: currently this program only ask for pong service %d\n", ret.error_code);
|
|
|
|
TEST_IPC_Q (ipc_connection (env, &contacted_service, "pong"), EXIT_FAILURE);
|
2019-07-27 15:48:10 +02:00
|
|
|
|
|
|
|
ipc_provide_fd (client.fd, contacted_service.fd);
|
|
|
|
|
2020-01-01 12:11:34 +01:00
|
|
|
TEST_IPC_Q (ipc_server_close (&srv), EXIT_FAILURE);
|
|
|
|
return EXIT_SUCCESS;
|
2019-07-27 15:48:10 +02:00
|
|
|
}
|