/*---------------------------------------------------------------------------* Project: Horizon File: rdt_ResendQueue.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46347 $ *---------------------------------------------------------------------------*/ #include "stdafx.h" #include "rdt_ResendQueue.h" #include #include "Test.h" #include "rdt_Utility.h" namespace { } // End of anonymous namespace namespace nn { namespace rdt { namespace CTR { ResendQueue::ResendQueue(void) :m_bResendMode(false) { Clear(); } ResendQueue::~ResendQueue(void) { } bool ResendQueue::Push(const Segment &seg) { if(m_queue.IsFull()) { return false; } // TORIAEZU SegmentWithTime swt; swt.segment = seg; swt.timeStamp = nn::rdt::CTR::GetCurrentTimeAsMillisecond(); // Unlike data segments, SYN segments do not need to be sent at a high pace. if(seg.IsSyn()) { swt.timeOut = SYN_SEGMENT_TIMEOUT; } else { swt.timeOut = m_defaultTimeout; } if(!m_queue.IsEmpty()) { // With the new implementation, a partially ordered relationship for timestamps is no longer guaranteed. // (With resend mode, the partially ordered relationship falls apart.) // But, because it is a problem to call this function in this state (that is, trying to send new data before the resend process is finished), this code will be left for a while longer. // // // Checks whether the timestamps of the element group registered in the queue have a partially ordered relationship. // ASSERT(swt.timeStamp >= m_queue.Back().timeStamp); } m_queue.PushBack(swt); return true; } bool ResendQueue::Front(Segment *pSeg) const { ASSERT(pSeg!=NULL); if(m_queue.IsEmpty()) { return false; } else { *pSeg = m_queue.Front().segment; return true; } } // // The Remove function must be reviewed because it cannot be assumed that the queue is arranged in timestamp order. // // With this implementation, if the Remove function target is not at the start of the queue, the target is not deleted. void ResendQueue::Remove(u32 ack) { while(!m_queue.IsEmpty()) { const Segment &seg = m_queue.Front().segment; u32 lastSeq = seg.GetLastSeqNumber(); if(0 < static_cast(ack) - static_cast(lastSeq)) { m_queue.PopFront(); VERBOSE("The start of the resend queue was deleted. \n"); if(m_queue.IsEmpty()) { // Resend mode ends if the resend queue is empty. m_bResendMode = false; } } else { // If an arrival confirmation by ACK cannot be acquired even at the start, the same goes without saying for subsequent segments. // Leave loop. break; } } } bool ResendQueue::IsResendRequired(void) const { if(m_queue.IsEmpty()) { return false; } else { return m_queue.Front().IsTimeOut(); } } u32 ResendQueue::GetTotalDataSize(void) const { u32 ret = 0; for(size_t i= 0; i