cache.cpp

00001 /*****************************************************************************
00002 Copyright (c) 2001 - 2009, 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 05/05/2009
00039 *****************************************************************************/
00040 
00041 #ifdef WIN32
00042    #include <winsock2.h>
00043    #include <ws2tcpip.h>
00044    #ifdef LEGACY_WIN32
00045       #include <wspiapi.h>
00046    #endif
00047 #endif
00048 
00049 #include <cstring>
00050 #include "cache.h"
00051 #include "core.h"
00052 
00053 using namespace std;
00054 
00055 CInfoBlock& CInfoBlock::operator=(const CInfoBlock& obj)
00056 {
00057    std::copy(obj.m_piIP, obj.m_piIP + 3, m_piIP);
00058    m_iIPversion = obj.m_iIPversion;
00059    m_ullTimeStamp = obj.m_ullTimeStamp;
00060    m_iRTT = obj.m_iRTT;
00061    m_iBandwidth = obj.m_iBandwidth;
00062    m_iLossRate = obj.m_iLossRate;
00063    m_iReorderDistance = obj.m_iReorderDistance;
00064    m_dInterval = obj.m_dInterval;
00065    m_dCWnd = obj.m_dCWnd;
00066 
00067    return *this;
00068 }
00069 
00070 bool CInfoBlock::operator==(const CInfoBlock& obj)
00071 {
00072    if (m_iIPversion != obj.m_iIPversion)
00073       return false;
00074 
00075    else if (m_iIPversion == AF_INET)
00076       return (m_piIP[0] == obj.m_piIP[0]);
00077 
00078    for (int i = 0; i < 4; ++ i)
00079    {
00080       if (m_piIP[i] != obj.m_piIP[i])
00081          return false;
00082    }
00083 
00084    return true;
00085 }
00086 
00087 CInfoBlock* CInfoBlock::clone()
00088 {
00089    CInfoBlock* obj = new CInfoBlock;
00090 
00091    std::copy(m_piIP, m_piIP + 3, obj->m_piIP);
00092    obj->m_iIPversion = m_iIPversion;
00093    obj->m_ullTimeStamp = m_ullTimeStamp;
00094    obj->m_iRTT = m_iRTT;
00095    obj->m_iBandwidth = m_iBandwidth;
00096    obj->m_iLossRate = m_iLossRate;
00097    obj->m_iReorderDistance = m_iReorderDistance;
00098    obj->m_dInterval = m_dInterval;
00099    obj->m_dCWnd = m_dCWnd;
00100 
00101    return obj;
00102 }
00103 
00104 int CInfoBlock::getKey()
00105 {
00106    if (m_iIPversion == AF_INET)
00107       return m_piIP[0];
00108 
00109    return m_piIP[0] + m_piIP[1] + m_piIP[2] + m_piIP[3];
00110 }
00111 
00112 void CInfoBlock::convert(const sockaddr* addr, int ver, uint32_t ip[])
00113 {
00114    if (ver == AF_INET)
00115    {
00116       ip[0] = ((sockaddr_in*)addr)->sin_addr.s_addr;
00117       ip[1] = ip[2] = ip[3] = 0;
00118    }
00119    else
00120    {
00121       memcpy((char*)ip, (char*)((sockaddr_in6*)addr)->sin6_addr.s6_addr, 16);
00122    }
00123 }

Generated on 9 Feb 2013 for barchart-udt-core-2.2.2 by  doxygen 1.6.1