Skip to content

Commit

Permalink
Socket: Fix stop check for IO event notify (JDimproved#1282)
Browse files Browse the repository at this point in the history
板やスレの読み込みを中止しても通信がキャンセルされないことがある
不具合を修正します。

バグの説明
linuxではselect(2)やpoll(2)を使ってsocketのファイルディスクリプタを
待つと読み込みの準備完了ができたと通知がきた場合でも読み込みが
ブロックされることがあるとマニュアルに書かれています。

間違った準備完了でIO待機を抜ける状況では読み込みブロックとIO待機が
繰り返されて読み込み中止の確認が不能になっていました。

参考文献
https://linuxjm.osdn.jp/html/LDP_man-pages/man2/select.2.html
  • Loading branch information
ma8ma committed Oct 28, 2023
1 parent f9e04c4 commit 41cfdfc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/jdlib/jdsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,12 @@ bool Socket::wait_fds( const WaitFor operation )
break;
}

if( errno != EINTR && pfds[0].revents & input_event ) return true;
// linuxではselect(2)やpoll(2)を使ってsocketのファイルディスクリプタを待つと
// 読み込みの準備完了ができたと通知がきた場合でも読み込みがブロックされることがある
// 間違った準備完了でIO待機を抜ける状況では読み込みブロックとIO待機が繰り返されて
// stopの確認が不能になるため返り値よりstopの確認を先に行う
if( m_stop.load( std::memory_order_acquire ) ) break;
if( errno != EINTR && pfds[0].revents & input_event ) return true;

if( ++count >= m_tout ) break;
#ifdef _DEBUG
Expand Down

0 comments on commit 41cfdfc

Please sign in to comment.