diff options
author | 2019-03-27 14:22:23 +0200 | |
---|---|---|
committer | 2019-03-29 14:44:42 +0200 | |
commit | 743425af52310be9333c90c46314f7dd9f8e20ed (patch) | |
tree | 879c177deb279fe4cb714711a84948aeb04d141e /src | |
parent | 25e5d3356c2836d51b0bace40dec7805f2c430b8 (diff) | |
download | usurpation-743425af52310be9333c90c46314f7dd9f8e20ed.tar.gz usurpation-743425af52310be9333c90c46314f7dd9f8e20ed.tar.bz2 usurpation-743425af52310be9333c90c46314f7dd9f8e20ed.zip |
daemon: Make debug output more informative.
Reduced the spam output and made it show state changes
This commit is part of ticket 3.
Signed-off-by: Paulius Ratkevičius <pauliuz95@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/net.c | 24 |
1 files 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(); |