From 743425af52310be9333c90c46314f7dd9f8e20ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulius=20Ratkevi=C4=8Dius?= Date: Wed, 27 Mar 2019 14:22:23 +0200 Subject: daemon: Make debug output more informative. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduced the spam output and made it show state changes This commit is part of ticket 3. Signed-off-by: Paulius Ratkevičius --- src/daemon/net.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/daemon/net.c b/src/daemon/net.c index 98dd154..cf6650a 100644 --- a/src/daemon/net.c +++ b/src/daemon/net.c @@ -158,6 +158,7 @@ static void *dolisten(void * state) struct netstate *st; ssize_t recvbufsize; int cancelstate; + int oldstatus = NONEWDATA; st = state; @@ -172,25 +173,26 @@ static void *dolisten(void * state) if (st->data[0] == 'I' && !(strcmp(st->data, servermagic))) { sendto(st->sock, clientmagic, sizeof(clientmagic), MSG_DONTWAIT, (struct sockaddr *) &clientaddr, sizeof(clientaddr)); - st->status = NONEWDATA; /* consume packet and lie about it */ - fprintf(stderr, "Sending DATA, timestap: %li \n", st->lastreply.tv_sec); + //fprintf(stderr, "Sending DATA, timestap: %li \n", st->lastreply.tv_sec); } } /* no packets in five seconds */ if ((now.tv_sec - st->lastreply.tv_sec) >= 5) { st->status = DEAD; - fprintf(stderr, "Connection with the client has been lost. Last reply since: %li", st->lastreply.tv_sec); - } else if (st->data[0] != 'I') { - /* we don't actually want to have NONEWDATA set from this loop, - * barring the one exeption that is after arrival of the beacon - * packet, as it'd keep the value at NONEWDATA almost constantly - * due to polling being generally much more frequent than the - * actual packet rate. - */ + } else { st->status = A_OK; } - + + if (oldstatus != st->status) + { + oldstatus = st->status; + if(oldstatus == DEAD) + fprintf(stderr, "Connection with the client has been lost. Last reply since: %li \n", st->lastreply.tv_sec); + else{ + fprintf(stderr,"Connected \n"); + } + } pthread_mutex_unlock(&st->datamutex); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &cancelstate); pthread_testcancel(); -- cgit v1.2.3