0

Linux に次の C++ コードがあります。

if (epoll_wait(hEvent,&netEvents,1,0))
{
        // check FIRST for disconnection to avoid send() to a closed socket (halts on centos on my server!)
        if ((netEvents.events & EPOLLERR)||(netEvents.events & EPOLLHUP)||(netEvents.events & EPOLLRDHUP)) {
            save_log("> client terminated connection");
            goto connection_ended;              // ---[ if its a CLOSE event .. close :)
        }
        if (netEvents.events & EPOLLOUT)                 // ---[ if socket is available for write
        {
            if (send_len) {
                result = send(s,buffer,send_len,MSG_NOSIGNAL);
                save_slogf("1112:send (s=%d,len=%d,ret=%d,errno=%d,epoll=%d,events=%d)",s,send_len,result,errno,hEvent,netEvents.events);
                if (result > 0) {
                    send_len = 0;
                    current_stage = CL_STAGE_USE_LINK_BRIDGE;
                    if (close_after_send_response) {
                        save_log("> destination machine closed connection");
                        close_after_send_response = false;
                        goto connection_ended;
                    }
                } else {
                    if (errno == EAGAIN) return;
                    else if (errno == EWOULDBLOCK) return;
                    else {
                        save_log("> unexpected error on socket, terminating");
        connection_ended:
                        close_client();
                        reset();
                        return;
                    }
                }
            }
        }
    }
}

hEvent: EPOLLIN、EPOLLOUT、EPOLLERR、EPOLLHUP、EPOLLRDHUP をリッスンするために作成された epoll

s: ノンブロッキング (!!!) ソケットは、ノンブロッキング リッスン ソケットの受け入れから作成されました

基本的に、このコードは、サーバーに接続している接続ユーザーにパケットを送り返そうとしています。通常は問題なく動作しますが、ランダムな場合 (おそらく奇妙なネットワーク イベントが発生した場合)、プログラムは "result = send(s,buffer,send_len,MSG_NOSIGNAL)" 行で無期限にハングします。

何が原因なのかわかりません。ソケット操作を監視しようとしましたが、なぜそれが起こるのかについての手がかりのヒントが得られないようです。これは KERNEL のバグか何か非常に奇妙なものであると想定しなければなりません。Windows で同じプログラムを作成し、Windows で完全に動作するからです。

4

0 に答える 0