パイプ上の読み取りファイル記述子とソケット接続記述子の 2 つのファイル記述子があります。どちらも非ブロッキングではありません。どちらも単一の EPOLLIN イベントで epoll コンテキストに追加されます。最後に、タイムアウト = -1 で epoll_wait を呼び出します。以下はサンプルコードです。2 つの質問があります:-
パイプおよび接続記述子は非ブロッキングにする必要がありますか。これはエッジ トリガーではありません。はいの場合、それは良い慣行または必須ですか?必須の場合、その理由は?
タイムアウトを -1 に設定していますが、epoll_wait はすぐに戻り値 0 を返します。タイムアウトが -1 の場合、epoll_wait はイベントが発生した場合にのみ返されます。
int total_fd_ready = -1; struct epoll_event pipe_event, connection_event, total_events[64]; pipe_event.data.fd = pipe_fd[0]; piple_event.events = EPOLLIN; connection_event.data.fd = conn_fd; connection_event.events = EPOLLIN; total_fd_ready = Epoll_wait(epoll_fd, total_events, 64, -1); printf("%d\n", total_fd_ready);
Epoll_wait は次のように定義されます。
int Epoll_wait(int e_fd, struct epoll_event *events, int max_events, int timeout) { #ifdef DBG printf("Epoll_wait called on epoll_fd: %d with max_events: %d and timeout: %d\n", e_fd, max_events, timeout); #endif int result = -1; if(result = (epoll_wait(e_fd, events, max_events, timeout)) < 0) if(errno != EINTR) err_sys("epoll_wait error with epoll fd: %d and timeout : %d\n", e_fd, timeout); #ifdef DBG else printf("epoll_wait was interrupted\n"); #endif return result; }
更新: 問題が見つかりましたが、結果が 0 に設定されている理由を説明できません。次の if ステートメントでブレーサーが必要でした
if((result = (epoll_wait(e_fd, events, max_events, timeout))) < 0)