Obsolete
/
libipc-old
Archived
3
0
Fork 0

suppression message debug

more_to_read
Philippe PITTOLI 2018-10-10 23:18:15 +02:00
parent 6074fad02b
commit c295fd7f46
4 changed files with 25 additions and 9 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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);

View File

@ -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);