第二人生的源碼分析(三十一)接收資料的流量控制

來源:互聯網
上載者:User

資料接收回來後,本來就應立即處理掉,這樣是比較簡單的想法。但由於網路頻寬有限,這時就需要限制UDP接收資料的速度。下面就來分析這種需求的實現,它的代碼如下:
#001 S32 LLPacketRing::receivePacket (S32 socket, char *datap)
#002 {
#003      S32 packet_size = 0;
#004 
 
下面判斷是否使用接收的流量限制。
#005      // If using the throttle, simulate a limited size input buffer.
#006      if (mUseInThrottle)
#007      {
#008             BOOL done = FALSE;
#009 
#010             // push any current net packet (if any) onto delay ring
下面開始迴圈地接收資料,並且判斷是否到達流量的最大值。
#011             while (!done)
#012             {
#013                    LLPacketBuffer *packetp;
#014                    packetp = new LLPacketBuffer(socket);
#015 
上面建立LLPacketBuffer對象來接收資料。
 
 
#016                    if (packetp->getSize())
#017                    {
#018                           mActualBitsIn += packetp->getSize() * 8;
#019 
#020                           // Fake packet loss
#021           &n

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.