diff --git a/src/communication.c b/src/communication.c index 0230ef0..1cc6485 100644 --- a/src/communication.c +++ b/src/communication.c @@ -40,13 +40,6 @@ struct ipc_error ipc_server_init (struct ipc_ctx *ctx, const char *sname) // ipc_add allocate memory then copy the data of srv and pollfd in ctx. TEST_IPC_RR (ipc_add (ctx, &srv, &pollfd), "cannot add the server in the context"); -#if 0 - printf ("server init, listen on %ld fd: ", ctx->size); - for (size_t i = 0; i < ctx->size; i++) - printf (" %d", ctx->pollfd[i].fd); - printf ("\n"); -#endif - IPC_RETURN_NO_ERROR; } @@ -66,14 +59,11 @@ struct ipc_error ipc_contact_networkd (int *pfd, const char *sname) // in order to route requests over any chosen protocol stack // ex: IPC_NETWORK="audio tor://some.example.com/audio ;pong tls://pong.example.com/pong" - // printf ("IPC_NETWORK: %s\n", networkvar); - SECURE_BUFFER_DECLARATION (char, columnthensname, BUFSIZ); columnthensname[0] = ';'; memcpy (columnthensname + 1, sname, strlen (sname)); if (strncmp (networkvar, sname, strlen (sname)) != 0 && strstr (networkvar, columnthensname) == NULL) { - // printf ("sname %s not found\n", sname); *pfd = 0; IPC_RETURN_NO_ERROR; } @@ -189,8 +179,6 @@ struct ipc_error ipc_read (const struct ipc_ctx *ctx, uint32_t index, struct ipc char *buf = NULL; size_t msize = IPC_MAX_MESSAGE_SIZE; - printf ("reading on the fd %d\n", ctx->pollfd[index].fd); - // On error or closed recipient, the buffer already freed. TEST_IPC_RETURN_ON_ERROR (usock_recv (ctx->pollfd[index].fd, &buf, &msize)); TEST_IPC_RETURN_ON_ERROR_FREE (ipc_message_format_read (m, buf, msize), buf); @@ -244,15 +232,10 @@ struct ipc_error ipc_add ( struct ipc_ctx *ctx, struct ipc_connection_info *p, s T_R ((p == NULL), IPC_ERROR_ADD__NO_PARAM_CLIENT); T_R ((pollfd == NULL), IPC_ERROR_ADD__NO_PARAM_POLLFD); - printf ("ipc add: add fd %d\n", pollfd[0].fd); - // Memory reallocation. ipc_ctx_new_alloc (ctx); - if (ctx->size <= 0) { - printf ("ERROR: new alloc <= 0\n"); - exit(1); - } + T_R ((ctx->size <= 0), IPC_ERROR_ADD__NOT_ENOUGH_MEMORY); ctx->cinfos[ctx->size - 1] = *p; ctx->pollfd[ctx->size - 1] = *pollfd; @@ -336,9 +319,9 @@ struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx if (txfd == mfd) { TEST_IPC_RR (ipc_write_fd (txfd, m), "cannot send a message to the client"); - printf ("Freeing the message\n"); + // Freeing the message structure. ipc_message_empty (m); - printf ("Removing the message\n"); + // Removing the message from the context. ipc_messages_del (&ctx->tx, i); // remove the message indexed by i break; // The message has been sent @@ -475,20 +458,6 @@ struct ipc_error ipc_events_loop (struct ipc_ctx *ctx, struct ipc_event *event, int32_t n; -#if 1 - printf ("%ld fd for the poll(2) syscall:", ctx->size); - for (size_t i = 0; i < ctx->size; i++) { - printf (" %d(%d)", ctx->pollfd[i].fd, ctx->pollfd[i].events); - } - printf ("\n"); - - printf ("%ld messages still to write, for fd:", ctx->tx.size); - for (size_t i = 0; i < ctx->tx.size; i++) { - printf (" %d", ctx->tx.messages[i].fd); - } - printf ("\n"); -#endif - for (size_t i = 0; i < ctx->tx.size; i++) { for (size_t y = 0; y < ctx->size; y++) { if (ctx->pollfd[y].fd == ctx->tx.messages[i].fd) { @@ -499,8 +468,7 @@ struct ipc_error ipc_events_loop (struct ipc_ctx *ctx, struct ipc_event *event, } if ((n = poll(ctx->pollfd, ctx->size, *timer)) < 0) { - printf("select error\n"); - exit(1); // TODO FIXME + IPC_RETURN_ERROR (IPC_ERROR_WAIT_EVENT__POLL); } // Timeout. diff --git a/src/ipc.h b/src/ipc.h index 6dd5dc6..c8763d9 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -190,8 +190,10 @@ enum ipc_error_code { , IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES = 100 , IPC_ERROR_MESSAGE_DEL__INDEX_ERROR = 101 , IPC_ERROR_MESSAGE_DEL__EMPTY_LIST = 102 - , IPC_ERROR_ADD__NO_PARAM_POLLFD = 103 - , IPC_ERROR_WRITE__FD_NOT_FOUND = 104 + , IPC_ERROR_ADD__NO_PARAM_POLLFD = 103 + , IPC_ERROR_WRITE__FD_NOT_FOUND = 104 + , IPC_ERROR_ADD__NOT_ENOUGH_MEMORY = 105 + , IPC_ERROR_WAIT_EVENT__POLL = 106 }; struct ipc_error { diff --git a/src/message.c b/src/message.c index 00aa4bd..b2c3892 100644 --- a/src/message.c +++ b/src/message.c @@ -173,12 +173,6 @@ struct ipc_error ipc_messages_add (struct ipc_messages *messages, const struct messages->messages[messages->size -1].payload = NULL; } - if (message->length > 0 && message->payload != NULL) { - printf ("first message payload (%d): %s\n", message->length, message->payload); - printf ("second message payload (%d): %s\n" - , messages->messages[messages->size - 1].length - , messages->messages[messages->size - 1].payload); - } IPC_RETURN_NO_ERROR; } diff --git a/tests/func_02_pongd.c b/tests/func_02_pongd.c index 6d2e697..4271539 100644 --- a/tests/func_02_pongd.c +++ b/tests/func_02_pongd.c @@ -44,22 +44,20 @@ void main_loop () break; case IPC_EVENT_TYPE_CONNECTION: { cpt++; - printf ("connection: %d ctx connected\n", cpt); - printf ("new client has the fd %d\n", event.origin); + // printf ("new connection (fd %d): %d ctx connected\n", event.origin, cpt); }; break; case IPC_EVENT_TYPE_DISCONNECTION: { cpt--; - printf ("disconnection: %d clients remaining\n", cpt); - // TODO: something? + // printf ("disconnection (fd %d): %d clients remaining\n", event.origin, cpt); }; break; case IPC_EVENT_TYPE_MESSAGE: { struct ipc_message *m = event.m; if (m->length > 0) { - printf ("message received (type %d): %.*s\n", m->type, m->length, m->payload); + // printf ("message received (type %d): %.*s\n", m->type, m->length, m->payload); } m->fd = event.origin; @@ -71,7 +69,7 @@ void main_loop () break; case IPC_EVENT_TYPE_TX: { - printf ("a message was sent\n"); + // printf ("a message was sent\n"); } break; case IPC_EVENT_TYPE_ERROR: