- 论坛徽章:
- 0
|
本帖最后由 没本 于 2010-07-13 23:21 编辑
其实我想看benchmark。。。
已经不用看benchmark了,和TCP协议栈的代码质量没办法比。CUDT::sendCtrl()里面的m_pRcvTimeWindow->getBandwidth()居然冒泡排序都出来了。。。。。。这个项目也就是大学混论文的东东。
随便贴个send函数大家品评
- int CUDT::send(const char* data, const int& len)
- {
- if (UDT_DGRAM == m_iSockType)
- 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_iSndBufSize <= m_pSndBuffer->getCurrBufSize())
- {
- if (!m_bSynSending)
- throw CUDTException(6, 1, 0);
- else
- {
- // wait here during a blocking sending
- #ifndef WIN32
- pthread_mutex_lock(&m_SendBlockLock);
- if (m_iSndTimeOut < 0)
- {
- while (!m_bBroken && m_bConnected && !m_bClosing && (m_iSndBufSize <= m_pSndBuffer->getCurrBufSize()))
- pthread_cond_wait(&m_SendBlockCond, &m_SendBlockLock);
- }
- else
- {
- uint64_t exptime = CTimer::getTime() + m_iSndTimeOut * 1000ULL;
- timespec locktime;
-
- locktime.tv_sec = exptime / 1000000;
- locktime.tv_nsec = (exptime % 1000000) * 1000;
-
- pthread_cond_timedwait(&m_SendBlockCond, &m_SendBlockLock, &locktime);
- }
- pthread_mutex_unlock(&m_SendBlockLock);
- #else
- if (m_iSndTimeOut < 0)
- {
- while (!m_bBroken && m_bConnected && !m_bClosing && (m_iSndBufSize <= m_pSndBuffer->getCurrBufSize()))
- WaitForSingleObject(m_SendBlockCond, INFINITE);
- }
- else
- WaitForSingleObject(m_SendBlockCond, DWORD(m_iSndTimeOut));
- #endif
- // check the connection status
- if (m_bBroken || m_bClosing)
- throw CUDTException(2, 1, 0);
- else if (!m_bConnected)
- throw CUDTException(2, 2, 0);
- }
- }
- if (m_iSndBufSize <= m_pSndBuffer->getCurrBufSize())
- return 0;
- int size = (m_iSndBufSize - m_pSndBuffer->getCurrBufSize()) * m_iPayloadSize;
- if (size > len)
- size = len;
- // record total time used for sending
- if (0 == m_pSndBuffer->getCurrBufSize())
- m_llSndDurationCounter = CTimer::getTime();
- // insert the user buffer into the sening list
- m_pSndBuffer->addBuffer(data, size);
- // insert this socket to snd list if it is not on the list yet
- m_pSndQueue->m_pSndUList->update(this, false);
- return size;
- }
复制代码 |
|