rxmit_queue.cc
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
  2. /*
  3.  * Copyright (c) 1997 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  * 3. All advertising materials mentioning features or use of this software
  15.  *    must display the following acknowledgement:
  16.  *      This product includes software developed by the Computer Systems
  17.  *      Engineering Group at Lawrence Berkeley Laboratory.
  18.  * 4. Neither the name of the University nor of the Laboratory may be used
  19.  *    to endorse or promote products derived from this software without
  20.  *    specific prior written permission.
  21.  *
  22.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32.  * SUCH DAMAGE.
  33.  */
  34. /* Ported from CMU/Monarch's code*/
  35. /* -*- c++ -*-
  36.    rexmit_queue.cc
  37.    $Id: rxmit_queue.cc,v 1.4 2000/08/18 18:34:02 haoboy Exp $
  38.    */
  39. #include <assert.h>
  40. #include "packet.h"
  41. #include "imep/rxmit_queue.h"
  42. ReXmitQ::ReXmitQ()
  43. {
  44.   LIST_INIT(&head)
  45. }
  46.   
  47. void 
  48. ReXmitQ::insert(Time rxat, Packet *p, int num_rexmits)
  49. {
  50.   struct rexent *r = new rexent;
  51.   r->rexmit_at = rxat;
  52.   r->p = p;
  53.   r->rexmits_left = num_rexmits;
  54.   struct rexent *i;
  55.   if (NULL == head.lh_first || rxat < head.lh_first->rexmit_at) 
  56.     {
  57.       LIST_INSERT_HEAD(&head, r, next);
  58.       return;
  59.     }
  60.   for (i = head.lh_first ; i != NULL ; i = i->next.le_next )
  61.     {
  62.       if (rxat < i->rexmit_at) 
  63. {
  64.   LIST_INSERT_BEFORE(i, r, next);
  65.   return;
  66. }
  67.       if (NULL == i->next.le_next)
  68. {
  69.   LIST_INSERT_AFTER(i, r, next);
  70.   return;
  71. }
  72.     }
  73. }
  74. void
  75. ReXmitQ::peekHead(Time *rxat, Packet **pp, int *rexmits_left)
  76. {
  77.   struct rexent *i;
  78.   i = head.lh_first;
  79.   if (NULL == i) {
  80.     *rxat = -1; *pp = NULL; *rexmits_left = -1;
  81.     return;
  82.   }
  83.   *rxat = i->rexmit_at;
  84.   *pp = i->p; 
  85.   *rexmits_left = i->rexmits_left;
  86. }
  87. void 
  88. ReXmitQ::removeHead()
  89. {
  90.   struct rexent *i;
  91.   i = head.lh_first;
  92.   if (NULL == i) return;
  93.   LIST_REMOVE(i, next);
  94.   delete i;
  95. }
  96. void 
  97. ReXmitQ::remove(Packet *p)
  98. {
  99.   struct rexent *i;
  100.   for (i = head.lh_first ; i != NULL ; i = i->next.le_next )
  101.     {
  102.       if (p == i->p)
  103. {
  104.   LIST_REMOVE(i, next);
  105.   delete i;
  106.   return;
  107. }
  108.     }
  109. }