00001 /***************************************************************************** 00002 Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois. 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions are 00007 met: 00008 00009 * Redistributions of source code must retain the above 00010 copyright notice, this list of conditions and the 00011 following disclaimer. 00012 00013 * Redistributions in binary form must reproduce the 00014 above copyright notice, this list of conditions 00015 and the following disclaimer in the documentation 00016 and/or other materials provided with the distribution. 00017 00018 * Neither the name of the University of Illinois 00019 nor the names of its contributors may be used to 00020 endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00024 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00025 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00026 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00027 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00028 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00029 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00030 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00031 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00032 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 *****************************************************************************/ 00035 00036 /***************************************************************************** 00037 written by 00038 Yunhong Gu, last updated 01/22/2011 00039 *****************************************************************************/ 00040 00041 #ifndef __UDT_LIST_H__ 00042 #define __UDT_LIST_H__ 00043 00044 00045 #include "udt.h" 00046 #include "common.h" 00047 00048 00049 class CSndLossList 00050 { 00051 public: 00052 CSndLossList(int size = 1024); 00053 ~CSndLossList(); 00054 00055 // Functionality: 00056 // Insert a seq. no. into the sender loss list. 00057 // Parameters: 00058 // 0) [in] seqno1: sequence number starts. 00059 // 1) [in] seqno2: sequence number ends. 00060 // Returned value: 00061 // number of packets that are not in the list previously. 00062 00063 int insert(int32_t seqno1, int32_t seqno2); 00064 00065 // Functionality: 00066 // Remove ALL the seq. no. that are not greater than the parameter. 00067 // Parameters: 00068 // 0) [in] seqno: sequence number. 00069 // Returned value: 00070 // None. 00071 00072 void remove(int32_t seqno); 00073 00074 // Functionality: 00075 // Read the loss length. 00076 // Parameters: 00077 // None. 00078 // Returned value: 00079 // The length of the list. 00080 00081 int getLossLength(); 00082 00083 // Functionality: 00084 // Read the first (smallest) loss seq. no. in the list and remove it. 00085 // Parameters: 00086 // None. 00087 // Returned value: 00088 // The seq. no. or -1 if the list is empty. 00089 00090 int32_t getLostSeq(); 00091 00092 private: 00093 int32_t* m_piData1; // sequence number starts 00094 int32_t* m_piData2; // seqnence number ends 00095 int* m_piNext; // next node in the list 00096 00097 int m_iHead; // first node 00098 int m_iLength; // loss length 00099 int m_iSize; // size of the static array 00100 int m_iLastInsertPos; // position of last insert node 00101 00102 pthread_mutex_t m_ListLock; // used to synchronize list operation 00103 00104 private: 00105 CSndLossList(const CSndLossList&); 00106 CSndLossList& operator=(const CSndLossList&); 00107 }; 00108 00110 00111 class CRcvLossList 00112 { 00113 public: 00114 CRcvLossList(int size = 1024); 00115 ~CRcvLossList(); 00116 00117 // Functionality: 00118 // Insert a series of loss seq. no. between "seqno1" and "seqno2" into the receiver's loss list. 00119 // Parameters: 00120 // 0) [in] seqno1: sequence number starts. 00121 // 1) [in] seqno2: seqeunce number ends. 00122 // Returned value: 00123 // None. 00124 00125 void insert(int32_t seqno1, int32_t seqno2); 00126 00127 // Functionality: 00128 // Remove a loss seq. no. from the receiver's loss list. 00129 // Parameters: 00130 // 0) [in] seqno: sequence number. 00131 // Returned value: 00132 // if the packet is removed (true) or no such lost packet is found (false). 00133 00134 bool remove(int32_t seqno); 00135 00136 // Functionality: 00137 // Remove all packets between seqno1 and seqno2. 00138 // Parameters: 00139 // 0) [in] seqno1: start sequence number. 00140 // 1) [in] seqno2: end sequence number. 00141 // Returned value: 00142 // if the packet is removed (true) or no such lost packet is found (false). 00143 00144 bool remove(int32_t seqno1, int32_t seqno2); 00145 00146 // Functionality: 00147 // Find if there is any lost packets whose sequence number falling seqno1 and seqno2. 00148 // Parameters: 00149 // 0) [in] seqno1: start sequence number. 00150 // 1) [in] seqno2: end sequence number. 00151 // Returned value: 00152 // True if found; otherwise false. 00153 00154 bool find(int32_t seqno1, int32_t seqno2) const; 00155 00156 // Functionality: 00157 // Read the loss length. 00158 // Parameters: 00159 // None. 00160 // Returned value: 00161 // the length of the list. 00162 00163 int getLossLength() const; 00164 00165 // Functionality: 00166 // Read the first (smallest) seq. no. in the list. 00167 // Parameters: 00168 // None. 00169 // Returned value: 00170 // the sequence number or -1 if the list is empty. 00171 00172 int getFirstLostSeq() const; 00173 00174 // Functionality: 00175 // Get a encoded loss array for NAK report. 00176 // Parameters: 00177 // 0) [out] array: the result list of seq. no. to be included in NAK. 00178 // 1) [out] physical length of the result array. 00179 // 2) [in] limit: maximum length of the array. 00180 // Returned value: 00181 // None. 00182 00183 void getLossArray(int32_t* array, int& len, int limit); 00184 00185 private: 00186 int32_t* m_piData1; // sequence number starts 00187 int32_t* m_piData2; // sequence number ends 00188 int* m_piNext; // next node in the list 00189 int* m_piPrior; // prior node in the list; 00190 00191 int m_iHead; // first node in the list 00192 int m_iTail; // last node in the list; 00193 int m_iLength; // loss length 00194 int m_iSize; // size of the static array 00195 00196 private: 00197 CRcvLossList(const CRcvLossList&); 00198 CRcvLossList& operator=(const CRcvLossList&); 00199 }; 00200 00201 00202 #endif