static void pushLoopToClients(LOOP_PKT* loopData) { WVIEW_ALARM_CLIENT *client, *oldClient; LOOP_PKT networkLoop; datafeedConvertLOOP_HTON(&networkLoop, loopData); // Push to each socket client: for (client = (WVIEW_ALARM_CLIENT *) radListGetFirst (&alarmsWork.clientList); client != NULL; client = (WVIEW_ALARM_CLIENT *) radListGetNext (&alarmsWork.clientList, (NODE_PTR)client)) { // write the frame start so clients may sync to the beginning of each // data update if (radSocketWriteExact (client->client, (void *)DF_LOOP_START_FRAME, DF_START_FRAME_LENGTH) != DF_START_FRAME_LENGTH) { // write error, bail on this guy radMsgLog (PRI_HIGH, "LOOP: write error to client %s:%d - closing socket...", radSocketGetHost (client->client), radSocketGetPort (client->client)); statusDecrementStat(ALARM_STATS_CLIENTS); radProcessIODeRegisterDescriptorByFd(radSocketGetDescriptor(client->client)); radSocketDestroy (client->client); oldClient = client; client = (WVIEW_ALARM_CLIENT *) radListGetPrevious (&alarmsWork.clientList, (NODE_PTR)client); radListRemove (&alarmsWork.clientList, (NODE_PTR)oldClient); free (oldClient); continue; } // write out the loop data in network byte order: if (radSocketWriteExact(client->client, &networkLoop, sizeof(networkLoop)) != sizeof(networkLoop)) { // write error, bail on this guy radMsgLog (PRI_HIGH, "LOOP: write error to client %s:%d - closing socket...", radSocketGetHost (client->client), radSocketGetPort (client->client)); statusDecrementStat(ALARM_STATS_CLIENTS); radProcessIODeRegisterDescriptorByFd(radSocketGetDescriptor(client->client)); radSocketDestroy (client->client); oldClient = client; client = (WVIEW_ALARM_CLIENT *) radListGetPrevious (&alarmsWork.clientList, (NODE_PTR)client); radListRemove (&alarmsWork.clientList, (NODE_PTR)oldClient); free (oldClient); continue; } statusIncrementStat(ALARM_STATS_PKTS_SENT); } return; }
static void pushArchiveToClients(ARCHIVE_PKT* archive) { WVIEW_ALARM_CLIENT *client, *oldClient; ARCHIVE_PKT networkArchive; datafeedConvertArchive_HTON(&networkArchive, archive); // Push to each socket client: for (client = (WVIEW_ALARM_CLIENT *) radListGetFirst (&alarmsWork.clientList); client != NULL; client = (WVIEW_ALARM_CLIENT *) radListGetNext (&alarmsWork.clientList, (NODE_PTR)client)) { // Check for archive sync in progress: if (client->syncInProgress) { continue; } // Write start frame and archive packet on the socket: if (WriteArchiveToClient(client->client, &networkArchive) == ERROR) { // write error, bail on this guy radMsgLog (PRI_HIGH, "ARCHIVE: write error to client %s:%d - closing socket...", radSocketGetHost (client->client), radSocketGetPort (client->client)); statusDecrementStat(ALARM_STATS_CLIENTS); radProcessIODeRegisterDescriptorByFd(radSocketGetDescriptor(client->client)); radSocketDestroy (client->client); oldClient = client; client = (WVIEW_ALARM_CLIENT *) radListGetPrevious (&alarmsWork.clientList, (NODE_PTR)client); radListRemove (&alarmsWork.clientList, (NODE_PTR)oldClient); free (oldClient); continue; } } return; }
// ... process expired timers static void processExpiredTimers (void) { register TIMER_ID timer, prevTimer; SYS_CALLBACK_MSG cbMsg; int retVal; for (timer = (TIMER_ID) radListGetFirst (&timerList->pendingList); timer != NULL; timer = (TIMER_ID) radListGetNext (&timerList->pendingList, (NODE_PTR)timer)) { if (timer->deltaTime == 0) { // remove from pending list prevTimer = (TIMER_ID) radListGetPrevious (&timerList->pendingList, (NODE_PTR)timer); radListRemove (&timerList->pendingList, (NODE_PTR)timer); timer->pending = FALSE; // send expiry notification if (timer->routine != NULL) { cbMsg.length = sizeof (cbMsg) - sizeof (cbMsg.length); cbMsg.msgType = 0; cbMsg.callback = timer->routine; cbMsg.parm = timer->parm; retVal = write (timerList->notifyFD, &cbMsg, sizeof (cbMsg)); if (retVal != sizeof (cbMsg)) { radMsgLog(PRI_HIGH, "processExpiredTimers: write to notify fd failed: %s", strerror (errno)); } } timer = prevTimer; } } return; }
ROW_ID raddatabaseResultsGetPrev (RESULT_SET_ID id) { id->current = (ROW_ID)radListGetPrevious (&id->rows, (NODE_PTR)id->current); return id->current; }