static void *sendKeepalives(void *parm) { KeepaliveThreadParms *parms = (KeepaliveThreadParms *) parm; int count = KEEPALIVE_PERIOD; int bytesSent; iblock(SIGTERM); while (*(parms->cloRunning)) { snooze(1); count++; if (count < KEEPALIVE_PERIOD) { continue; } /* Time to send a keepalive. Note that the * interval between keepalive attempts will be * KEEPALIVE_PERIOD plus (if the remote induct * is not reachable) the length of time taken * by TCP to determine that the connection * attempt will not succeed (e.g., 3 seconds). */ count = 0; pthread_mutex_lock(parms->mutex); bytesSent = sendBundleByTCP(parms->socketName, parms->ductSocket, 0, 0, NULL); pthread_mutex_unlock(parms->mutex); if (bytesSent < 0) { shutDownClo(); break; } } return NULL; }
static void *sendKeepalives(void *parm) { KeepaliveThreadParms *parms = (KeepaliveThreadParms *) parm; int keepaliveTimer = 0; int bytesSent; int backoffTimer = BACKOFF_TIMER_START; int backoffTimerCount = 0; unsigned char *buffer; buffer = MTAKE(TCPCLA_BUFSZ); //To send keepalive bundle if (buffer == NULL) { putErrmsg("No memory for TCP buffer in tcpclo.", NULL); return NULL; } iblock(SIGTERM); while (*(parms->cloRunning)) { snooze(1); keepaliveTimer++; if (keepaliveTimer < *(parms->keepalivePeriod)) { continue; } // If the negotiated keep alive interval is 0, then // keep alives will not be sent. if(*(parms->keepalivePeriod) == 0) { continue; } /* Time to send a keepalive. Note that the * interval between keepalive attempts will be * KEEPALIVE_PERIOD plus (if the remote induct * is not reachable) the length of time taken * by TCP to determine that the connection * attempt will not succeed (e.g., 3 seconds). */ keepaliveTimer = 0; pthread_mutex_lock(parms->mutex); bytesSent = sendBundleByTCPCL(parms->socketName, parms->ductSocket, 0, 0, buffer, parms->keepalivePeriod); pthread_mutex_unlock(parms->mutex); /* if the node is unable to establish a TCP connection, * the connection should be tried only after some delay. * */ if(bytesSent == 0) { while((backoffTimerCount < backoffTimer) && (*(parms->ductSocket) < 0)) { snooze(1); backoffTimerCount++; if(!(*(parms->cloRunning))) { break; } } backoffTimerCount = 0; /* keepaliveTimer keeps track of when the keepalive needs * to be sent. This value is set to keepalive period. * That way at the end of backoff period a * keepalive is sent * */ keepaliveTimer = *(parms->keepalivePeriod); if(backoffTimer < BACKOFF_TIMER_LIMIT) { backoffTimer *= 2; } continue; } backoffTimer = BACKOFF_TIMER_START; if (bytesSent < 0) { shutDownClo(); break; } } MRELEASE(buffer); return NULL; }