Obsolete
/
libipc-old
Archived
3
0
Fork 0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
libipc-old/examples/test-networkd-provide-fd.c

36 lines
1.1 KiB
C
Raw Normal View History

2019-07-27 15:48:10 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../src/ipc.h"
2020-07-06 14:38:06 +02:00
int main (void)
2019-07-27 15:48:10 +02:00
{
SECURE_DECLARATION (struct ipc_error, ret);
2020-07-06 14:38:06 +02:00
SECURE_DECLARATION (struct ipc_ctx, ctx);
SECURE_DECLARATION (struct ipc_event, event);
2019-07-27 15:48:10 +02:00
// service start
2020-07-06 14:38:06 +02:00
TEST_IPC_Q (ipc_server_init (&ctx, "ipcd"), EXIT_FAILURE);
2019-07-27 15:48:10 +02:00
printf ("service initialized, waiting for a client\n");
// accept a new client
2020-07-06 14:38:06 +02:00
TEST_IPC_Q (ipc_accept_add (&event, &ctx, 0 /* the only valid index right now */), EXIT_FAILURE);
int client_fd = ctx.pollfd[ctx.size-1].fd;
2019-07-27 15:48:10 +02:00
// TODO: read a message to know the requested service
SECURE_DECLARATION (struct ipc_message, msg);
2020-07-06 14:38:06 +02:00
TEST_IPC_Q (ipc_read (&ctx, 1 /* 1 = our client */, &msg), EXIT_FAILURE);
2019-07-27 15:48:10 +02:00
printf ("received message: %s\n", msg.payload);
/** TODO: contact the service */
printf ("WARNING: currently this program only ask for pong service %d\n", ret.error_code);
2020-07-06 14:38:06 +02:00
TEST_IPC_Q (ipc_connection (&ctx, "pong"), EXIT_FAILURE);
2019-07-27 15:48:10 +02:00
2020-07-06 14:38:06 +02:00
ipc_provide_fd (client_fd, ctx.pollfd[ctx.size-1].fd);
2019-07-27 15:48:10 +02:00
2020-07-06 14:38:06 +02:00
TEST_IPC_Q (ipc_close_all (&ctx), EXIT_FAILURE);
return EXIT_SUCCESS;
2019-07-27 15:48:10 +02:00
}