int send(UDTSOCKET u, const char* buf, int len, int flags)
{
return CUDT::send(u, buf, len, flags);
}
int CUDT::send(UDTSOCKET u, const char* buf, int len, int)
{
try
{
CUDT* udt = s_UDTUnited.lookup(u);//这里是通过套接口ID直接找到关联的传输控制块,而之前介绍的connect函数中,是通过套接口ID找到关联的套接口,注意区分
return udt->send(buf, len);//可见传进来的第三个参数没有用
}
catch (CUDTException e)
{
s_UDTUnited.setError(new CUDTException(e));
return ERROR;
}
catch (bad_alloc&)
{
s_UDTUnited.setError(new CUDTException(3, 2, 0));
return ERROR;
}
catch (...)
{
s_UDTUnited.setError(new CUDTException(-1, 0, 0));
return ERROR;
}
}
int CUDT::send(const char* data, int len)
{
if (UDT_DGRAM == m_iSockType)//如果是UDT_DGRAM类型,则抛出错误
throw CUDTException(5, 10, 0);
// throw an exception if not connected
if (m_bBroken || m_bClosing)
throw CUDTException(2, 1, 0);
else if (!m_bConnected)
throw CUDTException(2, 2, 0);
if (len <= 0)
return 0;
CGuard sendguard(m_SendLock);
if (m_pSndBuffer->getCurrBufSize() == 0)//若发送缓存中没有数据
{
// delay the EXP timer to avoid mis-fired timeout
uint64_t currtime;
CTimer::rdtsc(currtime);
m_ullLastRspTime = currtime;
}
if (m_iSndBufSize <&#