/*****************************************************************************
Copyright � 2001 - 2007, The Board of Trustees of the University of Illinois.
All Rights Reserved.
UDP-based Data Transfer Library (UDT) version 4
National Center for Data Mining (NCDM)
University of Illinois at Chicago
http://www.ncdm.uic.edu/
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*****************************************************************************/
/*****************************************************************************
This file contains the implementation of main algorithms of UDT protocol and
the implementation of core UDT interfaces.
Reference:
UDT programming manual
UDT protocol specification (draft-gg-udt-xx.txt)
*****************************************************************************/
/*****************************************************************************
written by
Yunhong Gu [gu@lac.uic.edu], last updated 07/23/2007
*****************************************************************************/
#ifndef WIN32
#include <unistd.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <cerrno>
#include <cstring>
#include <cstdlib>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
#include <cmath>
#include "queue.h"
#include "core.h"
using namespace std;
CUDTUnited CUDT::s_UDTUnited;
const UDTSOCKET CUDT::INVALID_SOCK = -1;
const int CUDT::ERROR = -1;
const UDTSOCKET UDT::INVALID_SOCK = CUDT::INVALID_SOCK;
const int UDT::ERROR = CUDT::ERROR;
const int32_t CSeqNo::m_iSeqNoTH = 0x3FFFFFFF;
const int32_t CSeqNo::m_iMaxSeqNo = 0x7FFFFFFF;
const int32_t CAckNo::m_iMaxAckSeqNo = 0x7FFFFFFF;
const int32_t CMsgNo::m_iMsgNoTH = 0xFFFFFFF;
const int32_t CMsgNo::m_iMaxMsgNo = 0x1FFFFFFF;
const int CUDT::m_iVersion = 4;
const int CUDT::m_iSYNInterval = 10000;
const int CUDT::m_iSelfClockInterval = 64;
CUDT::CUDT()
{
m_pSndBuffer = NULL;
m_pRcvBuffer = NULL;
m_pSndLossList = NULL;
m_pRcvLossList = NULL;
m_pACKWindow = NULL;
m_pSndTimeWindow = NULL;
m_pRcvTimeWindow = NULL;
m_pSndQueue = NULL;
// Initilize mutex and condition variables
initSynch();
// Default UDT configurations
m_iMSS = 1500;
m_bSynSending = true;
m_bSynRecving = true;
m_iFlightFlagSize = 25600;
m_iSndQueueLimit = 10000000;
m_iUDTBufSize = 25600;
m_Linger.l_onoff = 1;
m_Linger.l_linger = 180;
m_iUDPSndBufSize = 1000000;
m_iUDPRcvBufSize = 1000000;
m_iIPversion = AF_INET;
m_bRendezvous = false;
m_iSndTimeOut = -1;
m_iRcvTimeOut = -1;
m_bReuseAddr = true;
m_pCCFactory = new CCCFactory<CUDTCC>;
m_pCC = NULL;
m_pController = NULL;
m_iRTT = 10 * m_iSYNInterval;
m_iRTTVar = m_iRTT >> 1;
m_ullCPUFrequency = CTimer::getCPUFrequency();
// Initial status
m_bOpened = false;
m_bConnected = false;
m_bBroken = false;
m_pPeerAddr = NULL;
m_pSNode = NULL;
m_pRNode = NULL;
}
CUDT::CUDT(const CUDT& ancestor)
{
m_pSndBuffer = NULL;
m_pRcvBuffer = NULL;
m_pSndLossList = NULL;
m_pRcvLossList = NULL;
m_pACKWindow = NULL;
m_pSndTimeWindow = NULL;
m_pRcvTimeWindow = NULL;
m_pSndQueue = NULL;
// Initilize mutex and condition variables
initSynch();
// Default UDT configurations
m_iMSS = ancestor.m_iMSS;
m_bSynSending = ancestor.m_bSynSending;
m_bSynRecving = ancestor.m_bSynRecving;
m_iFlightFlagSize = ancestor.m_iFlightFlagSize;
m_iSndQueueLimit = ancestor.m_iSndQueueLimit;
m_iUDTBufSize = ancestor.m_iUDTBufSize;
m_Linger = ancestor.m_Linger;
m_iUDPSndBufSize = ancestor.m_iUDPSndBufSize;
m_iUDPRcvBufSize = ancestor.m_iUDPRcvBufSize;
m_iSockType = ancestor.m_iSockType;
m_iIPversion = ancestor.m_iIPversion;
m_bRendezvous = ancestor.m_bRendezvous;
m_iSndTimeOut = ancestor.m_iSndTimeOut;
m_iRcvTimeOut = ancestor.m_iRcvTimeOut;
m_bReuseAddr = true;
m_pCCFactory = ancestor.m_pCCFactory->clone();
m_pCC = NULL;
m_pController = ancestor.m_pController;
m_iRTT = ancestor.m_iRTT;
m_iRTTVar = ancestor.m_iRTTVar;
m_ullCPUFrequency = ancestor.m_ullCPUFrequency;
// Initial status
m_bOpened = false;
m_bConnected = false;
m_bBroken = false;
m_pPeerAddr = NULL;
m_pSNode = NULL;
m_pRNode = NULL;
}
CUDT::~CUDT()
{
// release mutex/condtion variables
destroySynch();
// destroy the data structures
delete m_pSndBuffer;
delete m_pRcvBuffer;
delete m_pSndLossList;
delete m_pRcvLossList;
delete m_pACKWindow;
delete m_pSndTimeWindow;
delete m_pRcvTimeWindow;
delete m_pCCFactory;
delete m_pCC;
delete m_pPeerAddr;
delete m_pSNode;
delete m_pRNode;
}
void CUDT::setOpt(UDTOpt optName, const void* optval, const int&)
{
CGuard cg(m_ConnectionLock);
CGuard sendguard(m_SendLock);
CGuard recvguard(m_RecvLock);
switch (optName)
{
case UDT_MSS:
if (m_bOpened)
throw CUDTException(5, 1, 0);
if (*(int*)optval < 28)
throw CUDTException(5, 3, 0);
m_iMSS = *(int*)optval;
break;
case UDT_SNDSYN:
m_bSynSending = *(bool *)optval;
break;
case UDT_RCVSYN:
m_bSynRecving = *(bool *)optval;
break;
case UDT_CC:
if (m_bConnected)
throw CUDTException(5, 1, 0);
if (NULL != m_pCCFactory)
delete m_pCCFactory;
m_pCCFactory = ((CCCVirtualFactory *)optval)->clone();
break;
case UDT_FC:
if (m_bConnected)
throw CUDTException(5, 2, 0);
if (*(int*)optval < 1)
throw CUDTException(5, 3);
m_iFlightFlagSize = *(int*)optval;
break;
case UDT_SNDBUF:
if (m_bOpened)
throw CUDTException(5, 1, 0);
if (*(int*)optval <= 0)
throw CUDTException(5, 3, 0);
m_iSndQueueLimit = *(int*)optval;
break;
case UDT_RCVBUF:
if (m_bOpened)
throw CUDTException(5, 1, 0);
if (*(int*)optval <= 0)
throw CUDTException(5, 3, 0);
// Mimimum recv buffer size is 32 packets
if (*(int*)optval > (m_iMSS - 28) * 32)
m_iUDTBufSize = *(int*)optval / (m_iMSS - 28);
else
m_iUDTBufSize = 32;
break;
case UDT_LINGER:
m_Linger = *(linger*)optval;
break;
case UDP_SNDBUF:
if (m_bOpened)
throw CUDTException(5, 1, 0);
m_iUDPSndBufSize = *(int*)optval;
break;
case UDP_RCVBUF:
if (m_bOpened)
throw CUDTException(5, 1, 0);
m_iUDPRcvBufSize = *(int*)optval;
break;
case UDT_RENDEZVOUS:
if (m_bConnected)
throw CUDTException(5, 1, 0);
m_bRendezvous = *(bool *)optval;
break;
case UDT_SNDTIMEO:
m_iSndTimeOut = *(int*)optval;
break;
case UDT_RCVTIMEO:
m_iRcvTimeOut = *(int*)optval;
break;
case UDT_REUSEADDR:
if (m_bOpened)
throw CUDTException(5, 1, 0);
m_bReuseAddr = *(bool*)optval;
break;
default:
throw CUDTException(5, 0, 0);
}
}
void CUDT::getOpt(UDTOpt optName, void* optval, int& optlen)
{
CGuard cg(m_ConnectionLock);
switch (optName)
{
case UDT_MSS:
*(int*)optval = m_iMSS;
optlen = sizeof(int);
break;
case UDT_SNDSYN:
*(bool*)optval = m_bSynSending;
optlen = sizeof(bool);
break;
cas
没有合适的资源?快使用搜索试试~ 我知道了~
UDP滑动窗口代码,UDP Sliding Window Protocol
共133个文件
htm:42个
h:18个
cpp:15个
4星 · 超过85%的资源 需积分: 19 54 下载量 114 浏览量
2011-06-23
15:16:18
上传
评论 1
收藏 424KB RAR 举报
温馨提示
滑动窗口软件代码,UDP Sliding Window Protocol
资源推荐
资源详情
资源评论
收起资源包目录
UDP滑动窗口代码,UDP Sliding Window Protocol (133个子文件)
traces.0t 0B
output.0t 0B
configure.ac 1KB
Makefile.am 593B
Makefile.am 237B
Makefile.am 99B
Makefile.am 26B
AUTHORS 0B
ChangeLog 0B
configure 735KB
COPYING 26KB
COPYRIGHT 962B
core.cpp 58KB
api.cpp 38KB
queue.cpp 25KB
list.cpp 18KB
common.cpp 15KB
buffer.cpp 13KB
packet.cpp 11KB
window.cpp 10KB
channel.cpp 8KB
control.cpp 6KB
ccc.cpp 6KB
appclient.cpp 4KB
appserver.cpp 3KB
sendfile.cpp 2KB
recvfile.cpp 2KB
udtdoc.css 1KB
treeview.css 326B
.cvsignore 33B
.cvsignore 15B
.cvsignore 15B
.cvsignore 9B
depcomp 15KB
ix_link.gif 134B
ix_open.gif 125B
ix_up.gif 125B
ix_down.gif 123B
ix_book.gif 122B
ix_leaf.gif 118B
ix_listp.gif 92B
ix_endp.gif 91B
ix_listm.gif 89B
ix_endm.gif 88B
ix_list.gif 65B
ix_end.gif 63B
ix_line.gif 63B
ix_space.gif 54B
config.guess 44KB
core.h 18KB
cc.h 13KB
queue.h 13KB
udt.h 10KB
udt.h 10KB
buffer.h 8KB
common.h 8KB
common.h 8KB
ccc.h 8KB
ccc.h 8KB
api.h 6KB
list.h 6KB
window.h 6KB
window.h 6KB
packet.h 6KB
packet.h 6KB
channel.h 5KB
control.h 3KB
main.htm 21KB
faq.htm 10KB
structure.htm 7KB
opt.htm 7KB
ccc.htm 6KB
t-config.htm 5KB
sendmsg.htm 4KB
ecode.htm 4KB
t-cc.htm 4KB
connect.htm 4KB
select.htm 4KB
t-hello.htm 4KB
recvmsg.htm 3KB
recv.htm 3KB
send.htm 3KB
accept.htm 3KB
t-error.htm 3KB
bind.htm 3KB
sendfile.htm 3KB
function.htm 3KB
recvfile.htm 3KB
t-intro.htm 3KB
make.htm 3KB
t-data.htm 3KB
close.htm 3KB
peername.htm 3KB
trace.htm 2KB
listen.htm 2KB
sockname.htm 2KB
socket.htm 2KB
t-msg.htm 2KB
t-firewall.htm 2KB
intro.htm 2KB
共 133 条
- 1
- 2
资源评论
- zhao2000112013-01-10比较好的例子,找了好久才找到
- xuhao19876302012-12-03还是不错的 初学者用来研究
- szkangdun_cn2013-05-30有点遗憾不是C#的啊,看不懂!!
- 可米小2013-05-28怎么运行不了 !!!!
- areyoupig2013-02-09UDT的代码。还是不错的 初学者用来研究
evertop
- 粉丝: 2
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功