diff --git a/src/communication.c b/src/communication.c index caa29eb..04131a6 100644 --- a/src/communication.c +++ b/src/communication.c @@ -279,6 +279,7 @@ struct ipc_error ipc_write (struct ipc_ctx *ctx, const struct ipc_message *m) T_R ((found == 0), IPC_ERROR_WRITE__FD_NOT_FOUND); + // Performs a deep copy of the structure. return ipc_messages_add (&ctx->tx, m); } @@ -388,34 +389,17 @@ struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index) { - // struct ipc_message { - // char type; - // char user_type; - // uint32_t length; - // char *payload; - // int fd; // File descriptor concerned about this message. - // }; - - // TODO int txfd = ctx->pollfd[index].fd; int mfd; struct ipc_message *m; for (size_t i = 0; ctx->tx.size ; i++) { m = &ctx->tx.messages[i]; mfd = m->fd; - printf ("Something to send on fd %d\n", mfd); if (txfd == mfd) { - if (m->payload == NULL) { - printf ("message payload is NULL\n"); - } - else { - printf ("The fd %d is available! Writing %d characters: [%d%d%d%d]\n" - , txfd, m->length - , m->payload[0], m->payload[1], m->payload[2], m->payload[3]); - - TEST_IPC_RR (ipc_write_fd (txfd, m), "cannot send a message to the client"); - } + TEST_IPC_RR (ipc_write_fd (txfd, m), "cannot send a message to the client"); + printf ("Freeing the message\n"); + ipc_message_empty (m); printf ("Removing the message\n"); ipc_messages_del (&ctx->tx, i); // remove the message indexed by i } @@ -522,14 +506,15 @@ struct ipc_error handle_new_message (struct ipc_event *event, struct ipc_ctx *ct // disconnection: close the client then delete it from ctx if (ret.error_code == IPC_ERROR_CLOSED_RECIPIENT) { + + IPC_EVENT_SET (event, IPC_EVENT_TYPE_DISCONNECTION, index, ctx->pollfd[index].fd, NULL); + TEST_IPC_P (ipc_close (ctx, index), "cannot close a connection on closed recipient in handle_message"); TEST_IPC_P (ipc_del (ctx, index), "cannot delete a connection on closed recipient in handle_message"); ipc_message_empty (m); free (m); - IPC_EVENT_SET (event, IPC_EVENT_TYPE_DISCONNECTION, index, ctx->pollfd[index].fd, NULL); - // warning: do not forget to free the ipc_client structure IPC_RETURN_NO_ERROR; } diff --git a/src/ipc.h b/src/ipc.h index 1d91211..6cd6185 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -234,7 +234,6 @@ struct ipc_messages { }; struct ipc_error ipc_messages_del (struct ipc_messages *messages, uint32_t index); -struct ipc_error ipc_message_free (struct ipc_message *message); /** * Context of the whole networking state. diff --git a/src/message.c b/src/message.c index 8614a6f..b29ec07 100644 --- a/src/message.c +++ b/src/message.c @@ -175,15 +175,6 @@ struct ipc_error ipc_messages_add (struct ipc_messages *messages, const struct IPC_RETURN_NO_ERROR; } -struct ipc_error ipc_message_free (struct ipc_message *message) -{ - if (message->payload != NULL) { - free (message->payload); - message->payload = NULL; - } - IPC_RETURN_NO_ERROR; -} - // Remove only pointers on allocated structures. struct ipc_error ipc_messages_del (struct ipc_messages *messages, uint32_t index) {