redis網路事件的特殊處理——stale event

來源:互聯網
上載者:User
在ae.c檔案的aeProcessEvents函數中,針對返回的網路事件有這樣的處理代碼:

int rfired = 0; /* note the fe->mask & mask & ... code: maybe an already processed  * event removed an element that fired and we still didn't  * processed, so we check if the event is still valid. */   if (fe->mask & mask & AE_READABLE) {          rfired = 1;          fe->rfileProc(eventLoop,fd,fe->clientData,mask);       }    if (fe->mask & mask & AE_WRITABLE) {          if (!rfired || fe->wfileProc != fe->rfileProc)               fe->wfileProc(eventLoop,fd,fe->clientData,mask);      }

第一感覺是不是很怪異?當某條串連上同時觸發了可讀和可寫回調,就只執行可讀回調(rfileProc)!

原因是因為clientData,在rfileProc中可能free掉clientData。這樣的話wfileProc處理就會coredump。

(請看redis-benchmark.c的readHandler,它有一句clientDone()調用回釋放掉clientData)

這樣的代碼有點像是在C++的類成員函數,裡面有一句delete this。。。基本屬於胡來行為

不得不說寫的真猥瑣噁心,資源管理非常混亂。

這也是有點厭惡C代碼的原因,放眼望去除nginx外,C代碼都醜陋不堪難以維護,

且都難以根治記憶體問題。

PS:nginx中也有類似的處理,美其名曰stale event。不多評論,我覺得是設計問題才導致了顧慮這麼多,弄出這些裝神弄鬼的東西。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.