From c295fd7f46b716daea1e9d84329a92eaca018111 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Wed, 10 Oct 2018 23:18:15 +0200 Subject: [PATCH] suppression message debug --- core/error.h | 7 +++++++ core/message.c | 6 ++++++ core/usocket.c | 4 ++-- pong/app/pongd.c | 17 ++++++++++------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/core/error.h b/core/error.h index 38d8383..c4bf76e 100644 --- a/core/error.h +++ b/core/error.h @@ -6,10 +6,17 @@ #define IPC_ERROR_NOT_ENOUGH_MEMORY 100 #define IPC_ERROR_WRONG_PARAMETERS 101 +// #define IPC_WITH_ERRORS 2 + +#ifdef IPC_WITH_ERRORS #define handle_error(msg) \ do { log_error (msg); exit(EXIT_FAILURE); } while (0) #define handle_err(fun,msg)\ do { log_error ("%s: file %s line %d %s", fun, __FILE__, __LINE__, msg); } while (0) +#else +#define handle_error(msg) +#define handle_err(fun,msg) +#endif #endif diff --git a/core/message.c b/core/message.c index e823ccb..06f096d 100644 --- a/core/message.c +++ b/core/message.c @@ -7,7 +7,9 @@ void ipc_message_print (const struct ipc_message *m) { assert (m != NULL); +#if defined(IPC_WITH_ERRORS) && IPC_WITH_ERRORS > 2 printf ("msg: type %d len %d\n", m->type, m->length); +#endif } int ipc_message_format_read (struct ipc_message *m, const char *buf, ssize_t msize) @@ -23,7 +25,9 @@ int ipc_message_format_read (struct ipc_message *m, const char *buf, ssize_t msi memcpy (&m->length, buf+1, 2); assert (m->length <= BUFSIZ - 3); +#if defined(IPC_WITH_ERRORS) && IPC_WITH_ERRORS > 2 printf ("type %d : msize = %ld, length = %d\n", m->type, msize, m->length); +#endif assert (m->length == msize - 3 || m->length == 0); if (m->payload != NULL) @@ -68,7 +72,9 @@ int ipc_message_format_write (const struct ipc_message *m, char **buf, ssize_t * *msize = 3 + m->length; +#if defined(IPC_WITH_ERRORS) && IPC_WITH_ERRORS > 2 printf ("sending msg: type %u, size %d, msize %ld\n", m->type, m->length, *msize); +#endif return 0; } diff --git a/core/usocket.c b/core/usocket.c index 2d61714..8b7bc65 100644 --- a/core/usocket.c +++ b/core/usocket.c @@ -11,7 +11,6 @@ int usock_send (const int fd, const char *buf, ssize_t len, ssize_t *sent) { ssize_t ret = 0; - //printf ("%ld bytes to write\n", len); ret = send (fd, buf, len, MSG_NOSIGNAL); if (ret <= 0) { handle_err ("usock_send", "send ret <= 0"); @@ -40,8 +39,9 @@ int usock_recv (const int fd, char **buf, ssize_t *len) if (*buf == NULL) { // do not allocate too much memory - if (*len > BUFSIZ) + if (*len > BUFSIZ) { handle_err ("usock_recv", "len > BUFSIZ"); + } if (*len == 0) *len = BUFSIZ; *buf = malloc ((*len < BUFSIZ) ? *len : BUFSIZ); diff --git a/pong/app/pongd.c b/pong/app/pongd.c index 613ea99..b03d46d 100644 --- a/pong/app/pongd.c +++ b/pong/app/pongd.c @@ -53,13 +53,16 @@ void handle_new_msg (struct ipc_clients *clients, struct ipc_clients *clients_ta cpt--; printf ("disconnection => %d client(s) remaining\n", cpt); - if (ipc_server_close_client (pc) < 0) - handle_err( "handle_new_msg", "server_close_client < 0"); - if (ipc_client_del (clients, pc) < 0) - handle_err( "handle_new_msg", "ipc_client_del < 0"); - if (ipc_client_del (clients_talking, pc) < 0) - handle_err( "handle_new_msg", "ipc_client_del < 0"); - i--; + if (ipc_server_close_client (pc) < 0) { + handle_err( "handle_new_msg", "server_close_client < 0"); + } + if (ipc_client_del (clients, pc) < 0) { + handle_err( "handle_new_msg", "ipc_client_del < 0"); + } + if (ipc_client_del (clients_talking, pc) < 0) { + handle_err( "handle_new_msg", "ipc_client_del < 0"); + } + i--; // free the ipc_client structure free (pc);