summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/daemon/net.c24
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();