00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 /* 00003 * Copyright (c) 1997 Regents of the University of California. 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 2. Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * 3. All advertising materials mentioning features or use of this software 00015 * must display the following acknowledgement: 00016 * This product includes software developed by the Computer Systems 00017 * Engineering Group at Lawrence Berkeley Laboratory. 00018 * 4. Neither the name of the University nor of the Laboratory may be used 00019 * to endorse or promote products derived from this software without 00020 * specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00025 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00028 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00029 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00031 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00032 * SUCH DAMAGE. 00033 */ 00034 /* Ported from CMU/Monarch's code*/ 00035 00036 /* -*- c++ -*- 00037 rexmit_queue.cc 00038 $Id: rxmit_queue.cc,v 1.4 2000/08/18 18:34:02 haoboy Exp $ 00039 */ 00040 00041 #include <assert.h> 00042 00043 #include "packet.h" 00044 #include "imep/rxmit_queue.h" 00045 00046 ReXmitQ::ReXmitQ() 00047 { 00048 LIST_INIT(&head) 00049 } 00050 00051 void 00052 ReXmitQ::insert(Time rxat, Packet *p, int num_rexmits) 00053 { 00054 struct rexent *r = new rexent; 00055 r->rexmit_at = rxat; 00056 r->p = p; 00057 r->rexmits_left = num_rexmits; 00058 00059 struct rexent *i; 00060 00061 if (NULL == head.lh_first || rxat < head.lh_first->rexmit_at) 00062 { 00063 LIST_INSERT_HEAD(&head, r, next); 00064 return; 00065 } 00066 00067 for (i = head.lh_first ; i != NULL ; i = i->next.le_next ) 00068 { 00069 if (rxat < i->rexmit_at) 00070 { 00071 LIST_INSERT_BEFORE(i, r, next); 00072 return; 00073 } 00074 if (NULL == i->next.le_next) 00075 { 00076 LIST_INSERT_AFTER(i, r, next); 00077 return; 00078 } 00079 } 00080 } 00081 00082 void 00083 ReXmitQ::peekHead(Time *rxat, Packet **pp, int *rexmits_left) 00084 { 00085 struct rexent *i; 00086 i = head.lh_first; 00087 if (NULL == i) { 00088 *rxat = -1; *pp = NULL; *rexmits_left = -1; 00089 return; 00090 } 00091 *rxat = i->rexmit_at; 00092 *pp = i->p; 00093 *rexmits_left = i->rexmits_left; 00094 } 00095 00096 void 00097 ReXmitQ::removeHead() 00098 { 00099 struct rexent *i; 00100 i = head.lh_first; 00101 if (NULL == i) return; 00102 LIST_REMOVE(i, next); 00103 delete i; 00104 } 00105 00106 void 00107 ReXmitQ::remove(Packet *p) 00108 { 00109 struct rexent *i; 00110 for (i = head.lh_first ; i != NULL ; i = i->next.le_next ) 00111 { 00112 if (p == i->p) 00113 { 00114 LIST_REMOVE(i, next); 00115 delete i; 00116 return; 00117 } 00118 } 00119 }
1.4.6