Obsolete
/
libipc-old
Archived
3
0
Fork 0

Correction examples.

pollfd
Karchnu 2020-07-06 14:38:06 +02:00
parent 47408ef653
commit ff9d6ed2b8
2 changed files with 16 additions and 22 deletions

View File

@ -6,30 +6,27 @@
int main (int argc, char *argv[])
{
(void)argc;
(void)argv;
SECURE_DECLARATION (struct ipc_error, ret);
SECURE_DECLARATION (struct ipc_connection_info, srv);
if (argc != 2) {
fprintf (stderr, "usage: %s service_name\n", argv[0]);
exit (1);
}
SECURE_DECLARATION (struct ipc_error, ret);
int fd = 0;
char *service_name = argv[1];
ret = ipc_contact_networkd (&srv, service_name);
ret = ipc_contact_ipcd (&fd, service_name);
printf ("ret = %d\n", ret.error_code);
if (ret.error_code == IPC_ERROR_NONE && srv.fd != 0) {
if (ret.error_code == IPC_ERROR_NONE && fd > 0) {
printf ("Success\n");
} else {
printf ("Ow. :(\n");
}
usock_close (srv.fd);
usock_close (&fd);
return EXIT_SUCCESS;
}

View File

@ -4,35 +4,32 @@
#include "../src/ipc.h"
int main (int argc, char *argv[], char *env[])
int main (void)
{
(void)argc;
(void)argv;
SECURE_DECLARATION (struct ipc_error, ret);
SECURE_DECLARATION (struct ipc_connection_info, srv);
SECURE_DECLARATION (struct ipc_connection_info, client);
SECURE_DECLARATION (struct ipc_connection_info, contacted_service);
SECURE_DECLARATION (struct ipc_ctx, ctx);
SECURE_DECLARATION (struct ipc_event, event);
// service start
TEST_IPC_Q (ipc_server_init (env, &srv, "network"), EXIT_FAILURE);
TEST_IPC_Q (ipc_server_init (&ctx, "ipcd"), EXIT_FAILURE);
printf ("service initialized, waiting for a client\n");
// accept a new client
TEST_IPC_Q (ipc_accept (&srv, &client), EXIT_FAILURE);
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;
// TODO: read a message to know the requested service
SECURE_DECLARATION (struct ipc_message, msg);
TEST_IPC_Q (ipc_read (&client, &msg), EXIT_FAILURE);
TEST_IPC_Q (ipc_read (&ctx, 1 /* 1 = our client */, &msg), EXIT_FAILURE);
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);
TEST_IPC_Q (ipc_connection (env, &contacted_service, "pong"), EXIT_FAILURE);
TEST_IPC_Q (ipc_connection (&ctx, "pong"), EXIT_FAILURE);
ipc_provide_fd (client.fd, contacted_service.fd);
ipc_provide_fd (client_fd, ctx.pollfd[ctx.size-1].fd);
TEST_IPC_Q (ipc_server_close (&srv), EXIT_FAILURE);
TEST_IPC_Q (ipc_close_all (&ctx), EXIT_FAILURE);
return EXIT_SUCCESS;
}