2016-12-19 18:16:38 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2016-12-21 02:56:52 +01:00
|
|
|
#include "../../core/error.h"
|
2016-12-19 18:16:38 +01:00
|
|
|
#include "../../core/communication.h"
|
|
|
|
|
|
|
|
#define MSG "coucou"
|
|
|
|
#define SERVICE_NAME "test"
|
|
|
|
|
|
|
|
int main (int argc, char *argv[], char *env[])
|
|
|
|
{
|
|
|
|
|
2016-12-21 02:56:52 +01:00
|
|
|
struct msg m;
|
|
|
|
memset (&m, 0, sizeof (struct msg));
|
2016-12-19 18:16:38 +01:00
|
|
|
struct service srv;
|
|
|
|
memset(&srv, 0, sizeof (struct service));
|
|
|
|
|
|
|
|
// index and version should be filled
|
|
|
|
srv.index = 0;
|
|
|
|
srv.version = 0;
|
|
|
|
|
|
|
|
struct process p;
|
2016-12-19 22:49:26 +01:00
|
|
|
memset (&p, 0, sizeof (struct process));
|
2016-12-19 18:16:38 +01:00
|
|
|
|
|
|
|
// init service
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_init (argc, argv, env, &srv, SERVICE_NAME) < 0) {
|
|
|
|
handle_err("main", "server_init < 0");
|
2016-12-19 18:16:38 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_accept (&srv, &p) < 0) {
|
|
|
|
handle_err("main", "server_accept < 0");
|
2016-12-19 18:16:38 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_read (&p, &m) < 0) {
|
|
|
|
handle_err("main", "server_read < 0");
|
2016-12-19 18:16:38 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-12-21 02:56:52 +01:00
|
|
|
printf ("msg recv: %s\n", m.val);
|
2016-12-19 18:16:38 +01:00
|
|
|
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_write (&p, &m) < 0) {
|
|
|
|
handle_err("main", "server_write < 0");
|
2016-12-19 18:16:38 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2018-10-03 21:52:11 +02:00
|
|
|
ipc_message_free (&m);
|
2016-12-21 02:56:52 +01:00
|
|
|
|
|
|
|
// client quits
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_read (&p, &m) < 0) {
|
|
|
|
handle_err("main", "server_read < 0");
|
2016-12-21 02:56:52 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2017-01-19 22:07:52 +01:00
|
|
|
if (m.type == MSG_TYPE_CLOSE) {
|
2016-12-21 02:56:52 +01:00
|
|
|
printf ("the client quits\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf (stderr, "err: should have received the client dis msg\n");
|
|
|
|
}
|
2018-10-03 21:52:11 +02:00
|
|
|
ipc_message_free (&m);
|
2016-12-19 18:16:38 +01:00
|
|
|
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_close_proc (&p) < 0) {
|
|
|
|
handle_err("main", "server_close_proc < 0");
|
2016-12-19 18:16:38 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-10-03 21:24:20 +02:00
|
|
|
if (server_close (&srv) < 0) {
|
|
|
|
handle_err("main", "server_close < 0");
|
2016-12-19 18:16:38 +01:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|