/* Looks like server code */ static void HandleNewRequest(RPC2_PacketBuffer *pb, struct CEntry *ce) { struct SL_Entry *sl; say(1, RPC2_DebugLevel, "HandleNewRequest()\n"); pb = ShrinkPacket(pb); ce->TimeStampEcho = pb->Header.TimeStamp; TVTOTS(&pb->Prefix.RecvStamp, ce->RequestTime); say(15, RPC2_DebugLevel, "handlenewrequest TS %u RQ %u\n", ce->TimeStampEcho, ce->RequestTime); rpc2_Recvd.Requests++; rpc2_Recvd.GoodRequests++; sl = ce->MySl; /* Free held packet and SL entry */ if (sl != NULL) { rpc2_DeactivateSle(sl, 0); FreeHeld(sl); } rpc2_IncrementSeqNumber(ce); { /* set up a timer to send a unsolicited ack response (actually an RCP2_BUSY) within 100ms. */ struct timeval tv; tv.tv_sec = 0; tv.tv_usec = RPC2_DELACK_DELAY; sl = rpc2_AllocSle(DELACK, ce); rpc2_ActivateSle(sl, &tv); } /* Look for a waiting recipient */ sl = FindRecipient(pb); if (sl != NULL) { SetState(ce, S_PROCESS); rpc2_DeactivateSle(sl, ARRIVED); sl->data = pb; LWP_NoYieldSignal((char *)sl); } else { /* hold for a future RPC2_GetRequest() */ rpc2_HoldPacket(pb); SetState(ce, S_REQINQUEUE); } }
void rpc2_ClockTick(void *dummy) {/* Non terminating LWP */ struct SL_Entry *sl; struct timeval tval; long timenow; int ticks = 0; sl = rpc2_AllocSle(OTHER, NULL); tval.tv_sec = TICKINTERVAL; tval.tv_usec = 0; while (TRUE) { /* ask for SocketListener to wake me up after TICKINTERVAL seconds */ rpc2_ActivateSle(sl, &tval); LWP_WaitProcess((char *)sl); LUA_clocktick(); /* only reap connections once a minute */ if ((ticks++ % 12) != 0) continue; timenow = rpc2_time(); say(1, RPC2_DebugLevel, "Clock Tick at %ld\n", timenow); #ifdef RPC2DEBUG if (RPC2_Trace && rpc2_TraceBuffHeader) { struct TraceElem *te; struct te_CLOCKTICK *tea; te = (struct TraceElem *)CBUF_NextSlot(rpc2_TraceBuffHeader); tea = &te->Args.ClockTickEntry; te->CallCode = CLOCKTICK; strncpy(te->ActiveLWP, LWP_Name(), sizeof(te->ActiveLWP)-1); tea->TimeNow = timenow; /* structure assignment */ } #endif /* and free up `dead' connections */ if (RPC2_enableReaping) rpc2_ReapDeadConns(); } }