send and other network system call2008年09月04日 22時29分33秒

send.2 等のネットワーク関連のシステムコールは、インターラプトされる。そこで、確実にメッセージを送信するには、send が EINTR で終了した場合には再度送信を試みる必要がある。

int my_send(int s, const char *msg, int len, int flags)
{
    int status;

    do
    {
        status = send(s, msg, len, flags);
    }while(status == -1 && errno == EINTR);

    return status;
}

以下の関数も似たような処理が必要になる。


        call        interruptable
        ----        ------------

        accept      yes
        bind        no
        close       yes
        connect     yes
        listen      no
        open        yes
        poll        yes
        read        yes
        pread       yes
        recv        yes
        recvfrom    yes
        recvmsg     yes
        socket      no
        select      yes
        send        yes
        sendmsg     yes
        sendto      yes
        shutdown    no
        write       yes

時折、忘れてしまうのでメモ。