char *GetQueueLast( MyQueue *p ) { int queue_num = 0; char *element = NULL; queue_num = GetQueueNum( p ); element = GetQueueElem( p, queue_num ); return element; }
// Write the received packet bool LinkPaPutPacket(SESSION *s, void *data, UINT size) { LINK *k; BLOCK *block = NULL; SESSION *server_session; CONNECTION *server_connection; bool ret = true; bool halting = false; // Validate arguments if (s == NULL || (k = (LINK *)s->PacketAdapter->Param) == NULL) { return false; } halting = (k->Halting || (*k->StopAllLinkFlag)); server_session = k->ServerSession; server_connection = server_session->Connection; k->Flag1++; if ((k->Flag1 % 32) == 0) { // Ommit for performance UINT current_num; int diff; current_num = GetQueueNum(server_connection->ReceivedBlocks); diff = (int)current_num - (int)k->LastServerConnectionReceivedBlocksNum; k->LastServerConnectionReceivedBlocksNum = current_num; CedarAddQueueBudget(k->Cedar, diff); } // Since the packet arrives from the HUB of the link destination, // deliver it to the ReceivedBlocks of the server session if (data != NULL) { if (halting == false) { block = NewBlock(data, size, 0); } if (k->LockFlag == false) { UINT current_num; int diff; k->LockFlag = true; LockQueue(server_connection->ReceivedBlocks); current_num = GetQueueNum(server_connection->ReceivedBlocks); diff = (int)current_num - (int)k->LastServerConnectionReceivedBlocksNum; k->LastServerConnectionReceivedBlocksNum = current_num; CedarAddQueueBudget(k->Cedar, diff); } if (halting == false) { if (CedarGetFifoBudgetBalance(k->Cedar) == 0) { FreeBlock(block); } else { InsertReveicedBlockToQueue(server_connection, block, true); } } } else { UINT current_num; int diff; current_num = GetQueueNum(server_connection->ReceivedBlocks); diff = (int)current_num - (int)k->LastServerConnectionReceivedBlocksNum; k->LastServerConnectionReceivedBlocksNum = current_num; CedarAddQueueBudget(k->Cedar, diff); if (k->LockFlag) { k->LockFlag = false; UnlockQueue(server_connection->ReceivedBlocks); } // Issue the Cancel, since finished store all packets when the data == NULL Cancel(server_session->Cancel1); if (k->Hub != NULL && k->Hub->Option != NULL && k->Hub->Option->YieldAfterStorePacket) { YieldCpu(); } } if (halting) { ret = false; } return ret; }