Archived
3
0

Add and remove printf.

This commit is contained in:
Karchnu 2020-11-08 06:07:28 +01:00
parent d32e26b848
commit 62db8ff7fd
4 changed files with 33 additions and 11 deletions

View File

@ -474,9 +474,17 @@ struct ipc_error handle_new_message (struct ipc_event *event, struct ipc_ctx *ct
ret = ipc_read (ctx, index, m);
if (ret.error_code != IPC_ERROR_NONE && ret.error_code != IPC_ERROR_CLOSED_RECIPIENT) {
struct ipc_error rvalue = ret; // store the final return value
ipc_message_empty (m);
free (m);
#ifdef DEBUG
printf ("error when ipc_read: index %d fd %d error num %d, message: %s\n"
, index, ctx->pollfd[index].fd
, ret.error_code
, ret.error_message);
#endif
// if there is a problem, just remove the client
TEST_IPC_P (ipc_close (ctx, index), "cannot close a connection in handle_message");
TEST_IPC_P (ipc_del (ctx, index), "cannot delete a connection in handle_message");
@ -534,6 +542,9 @@ struct ipc_error ipc_wait_event (struct ipc_ctx *ctx, struct ipc_event *event, i
for (size_t i = 0; i < ctx->size; i++) {
// We assume that any fd in the list has to be listen to.
#ifdef DEBUG
printf ("reading fd: %d index %lu\n", ctx->pollfd[i].fd, i);
#endif
ctx->pollfd[i].events = POLLIN;
}
@ -542,6 +553,9 @@ struct ipc_error ipc_wait_event (struct ipc_ctx *ctx, struct ipc_event *event, i
// … verify that its destination is available for message exchange.
for (size_t y = 0; y < ctx->size; y++) {
if (ctx->pollfd[y].fd == ctx->tx.messages[i].fd) {
#ifdef DEBUG
printf ("writing fd: %d\n", ctx->pollfd[y].fd);
#endif
ctx->pollfd[y].events |= POLLOUT;
}
}
@ -648,13 +662,17 @@ struct ipc_error ipc_wait_event (struct ipc_ctx *ctx, struct ipc_event *event, i
}
if (ctx->pollfd[i].revents & POLLERR) {
printf ("POLLERR: PROBLEM WITH fd %d\n", ctx->pollfd[i].fd);
#ifdef DEBUG
printf ("pollerr: problem with fd %d\n", ctx->pollfd[i].fd);
#endif
IPC_EVENT_SET (event, IPC_EVENT_TYPE_ERROR, i, ctx->pollfd[i].fd, NULL);
goto wait_event_exit;
}
if (ctx->pollfd[i].revents & POLLNVAL) {
printf ("POLLNVAL: INVALID fd %d\n", ctx->pollfd[i].fd);
#ifdef DEBUG
printf ("pollnval: invalid fd %d\n", ctx->pollfd[i].fd);
#endif
IPC_EVENT_SET (event, IPC_EVENT_TYPE_ERROR, i, ctx->pollfd[i].fd, NULL);
goto wait_event_exit;
}

View File

@ -18,6 +18,7 @@
#define RUNDIR "/run/ipc/"
#define PATH_MAX 4096
#define IPC_HEADER_SIZE 6
// #define __IPC_BASE_SIZE 500000 // 500 KB
#define __IPC_BASE_SIZE 2000000 // 2 MB, plenty enough space for messages
#define IPC_MAX_MESSAGE_SIZE __IPC_BASE_SIZE-IPC_HEADER_SIZE

View File

@ -88,14 +88,10 @@ void ipc_ctx_switching_add (struct ipc_ctx *ctx, int orig, int dest)
void ipc_switching_add (struct ipc_switchings *is, int orig, int dest)
{
// printf ("ipc_switching_add START: switchdb has %ld entries\n", is->size);
if (is->collection == NULL) {
// printf ("switchdb collection is null\n");
is->collection = malloc (sizeof (struct ipc_switching) * (is->size + 1));
}
else {
// printf ("switchdb collection isn't null\n");
is->collection = realloc (is->collection, sizeof (struct ipc_switching) * (is->size + 1));
}
@ -114,8 +110,6 @@ void ipc_switching_add (struct ipc_switchings *is, int orig, int dest)
is->collection[is->size - 1].dest_in = NULL;
is->collection[is->size - 1].orig_out = NULL;
is->collection[is->size - 1].dest_out = NULL;
// printf ("ipc_switching_add END: switchdb has %ld entries\n", is->size);
}
int ipc_ctx_switching_del (struct ipc_ctx *ctx, int fd)
@ -293,6 +287,7 @@ struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx
// If the socket is associated to another one for ipcd:
// read and write automatically and provide a new IPC_EVENT_TYPE indicating the switch.
T_R ((ctx->switchdb.size == 0), IPC_ERROR_FD_SWITCHING__NO_FD_RECORD);
int talkingfd = ctx->pollfd[index].fd;
@ -387,8 +382,6 @@ struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx
*/
struct ipc_error fd_switching_write (struct ipc_event *event, struct ipc_ctx *ctx, int index)
{
// printf ("fd_switching_write\n");
// If the socket is associated to another one for ipcd:
// read and write automatically and provide a new IPC_EVENT_TYPE indicating the switch.
T_R ((ctx->switchdb.size == 0), IPC_ERROR_FD_SWITCHING__NO_FD_RECORD);

View File

@ -23,10 +23,14 @@
struct ipc_error usock_send (const int32_t fd, const char *buf, size_t len, size_t * sent)
{
ssize_t ret = 0;
#ifdef __PRINT_MSG_SIZES
fprintf (stderr, "a %10lu-byte message should be sent to %d\n", len, fd);
#endif
ret = send (fd, buf, len, MSG_NOSIGNAL);
if (ret == -1)
{
// TODO: Check for errno.
// Some choice could be made.
switch (errno) {
@ -125,6 +129,12 @@ struct ipc_error usock_recv (const int32_t fd, char **buf, size_t * len)
if (msize == 0) {
memcpy (&msize, *buf + 1, sizeof msize);
msize = ntohl (msize);
#ifdef __PRINT_MSG_SIZES
fprintf (stderr, "a %10u-byte message should be received on %d\n"
, msize + IPC_HEADER_SIZE
, fd);
#endif
}
// else {
// printf ("USOCKET: We received a message in (at least) two packets (receveid %u bytes).\n", msize_read);