Obsolete
/
libipc-old
Archived
3
0
Fork 0

No leaks, no error whatsoever so far.

pollfd
Karchnu 2020-06-30 13:49:21 +02:00
parent 292cca45e0
commit f4ffd7386f
3 changed files with 7 additions and 32 deletions

View File

@ -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); T_R ((found == 0), IPC_ERROR_WRITE__FD_NOT_FOUND);
// Performs a deep copy of the structure.
return ipc_messages_add (&ctx->tx, m); 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_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 txfd = ctx->pollfd[index].fd;
int mfd; int mfd;
struct ipc_message *m; struct ipc_message *m;
for (size_t i = 0; ctx->tx.size ; i++) { for (size_t i = 0; ctx->tx.size ; i++) {
m = &ctx->tx.messages[i]; m = &ctx->tx.messages[i];
mfd = m->fd; mfd = m->fd;
printf ("Something to send on fd %d\n", mfd);
if (txfd == 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"); printf ("Removing the message\n");
ipc_messages_del (&ctx->tx, i); // remove the message indexed by i 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 // disconnection: close the client then delete it from ctx
if (ret.error_code == IPC_ERROR_CLOSED_RECIPIENT) { 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_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"); TEST_IPC_P (ipc_del (ctx, index), "cannot delete a connection on closed recipient in handle_message");
ipc_message_empty (m); ipc_message_empty (m);
free (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 // warning: do not forget to free the ipc_client structure
IPC_RETURN_NO_ERROR; IPC_RETURN_NO_ERROR;
} }

View File

@ -234,7 +234,6 @@ struct ipc_messages {
}; };
struct ipc_error ipc_messages_del (struct ipc_messages *messages, uint32_t index); 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. * Context of the whole networking state.

View File

@ -175,15 +175,6 @@ struct ipc_error ipc_messages_add (struct ipc_messages *messages, const struct
IPC_RETURN_NO_ERROR; 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. // Remove only pointers on allocated structures.
struct ipc_error ipc_messages_del (struct ipc_messages *messages, uint32_t index) struct ipc_error ipc_messages_del (struct ipc_messages *messages, uint32_t index)
{ {