From 0f46858e78c2cc3adb34dc6d682aca9e208be5e9 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Thu, 2 Jul 2020 21:33:59 +0200 Subject: [PATCH] print context --- src/ipc.h | 7 +++---- src/print.c | 31 ++++++++++++++++++------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/ipc.h b/src/ipc.h index 27da563..52fe0d6 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -185,7 +185,7 @@ enum ipc_error_code { , IPC_ERROR_CONNECTION__NO_CTX = 95 , IPC_ERROR_CTX_INIT__MALLOC_CTX = 96 , IPC_ERROR_CTX_INIT__MALLOC_POLLFD = 97 - , IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM = 98 + , IPC_ERROR_CONTACT_IPCD__NO_FD_PARAM = 98 , IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX = 99 , IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES = 100 , IPC_ERROR_MESSAGE_DEL__INDEX_ERROR = 101 @@ -356,8 +356,7 @@ struct ipc_error ipc_ctx_new_alloc (struct ipc_ctx *ctx); struct ipc_error service_path (char *path, const char *sname); struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index); -void ipc_connection_print (struct ipc_connection_info *cinfo); -void ipc_connections_print (struct ipc_ctx *cinfos); +void ipc_ctx_print (struct ipc_ctx *ctx); // Last parameter is the index for the server fd in the context structure. struct ipc_error ipc_accept_add (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index); @@ -376,7 +375,7 @@ struct ipcd { }; struct ipc_error -ipc_wait_event_ipcd (struct ipc_ctx *cinfos +ipc_wait_event_ipcd (struct ipc_ctx *ctx , struct ipc_connection_info *cinfo // cinfo is NULL for clients , struct ipc_event *event, struct ipc_switchings *switchdb, int *timer); diff --git a/src/print.c b/src/print.c index 92b0580..f838322 100644 --- a/src/print.c +++ b/src/print.c @@ -1,20 +1,25 @@ #include "ipc.h" -void ipc_connection_print (struct ipc_connection_info *cinfo) +void ipc_ctx_print (struct ipc_ctx *ctx) { - T_R_NOTHING ((cinfo == NULL)); + printf ("Context contains:\n"); + for (size_t i = 0; i < ctx->size; i++) { + printf ("- fd %d\t", ctx->pollfd[i].fd); -#if 0 - LOG_DEBUG ("fd %d: index %d, version %d, type %c, path %s" - , cinfo->fd , cinfo->index, cinfo->version, cinfo->type - , (cinfo->spath == NULL) ? "-" : cinfo->spath); -#endif -} - -void ipc_connections_print (struct ipc_ctx *cinfos) -{ - for (size_t i = 0; i < cinfos->size; i++) { - ipc_connection_print (&cinfos->cinfos[i]); + switch (ctx->cinfos[i].type) { + case IPC_CONNECTION_TYPE_IPC: { + printf ("- ipc\n"); + break; + } + case IPC_CONNECTION_TYPE_EXTERNAL: { + printf ("- external\n"); + break; + } + case IPC_CONNECTION_TYPE_SERVER: { + printf ("- external\n"); + break; + } + } } }