Re: Man page for revised timerfd API

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Matti Aarnio
Date: Wednesday, October 3, 2007 - 1:14 am

On Wed, Oct 03, 2007 at 08:50:09AM +0200, Michael Kerrisk wrote:

When returning multi-byte long numeric values via read(2) as byte streams,
my default question is:

   Can you explicitely state what is the byte order ?

It _probably_ is the host-byte-order as kernel- and userspaces can hardly
run with different ones and this does not sound like an API to be used
over the network, but nevertheless...


In the code-example:

    for (tot_exp = 0; tot_exp < max_exp;) {
        s = read(fd, &exp, sizeof(uint64_t));
        if (s != sizeof(uint64_t))
            die("read");
        tot_exp += exp;
        print_elapsed_time();
        printf("read: %llu; total=%d\\n", exp, tot_exp);
    }

If I may suggest some alterations:

    for (tot_exp = 0; tot_exp < max_exp;) {
        s = read(fd, &exp, sizeof(exp));
        if (s < 0) {
            /* add: EINTR etc. processing */
            continue;
        }
        if (s != sizeof(exp))
            die("read");
        tot_exp += exp;
        print_elapsed_time();
        printf("read: %lu; total=%d\\n", (unsigned long) exp, tot_exp);
    }

The "die if surprised" -strategy is not nice.
Somebody will take example out of that code.

Indeed defining all possible error modes may be impossible, but it may
be possible to define those errors that result in so severe dysfunction
that closing and re-creating the timer-handle may be your only choice.
(About the impossibility:  Solaris STREAMS based network accept() does/did
 yield all kinds of odd errors out from the STREAMS stack in addition to
 those listed in the syscall man-page.  Reacting on all unknown errors
 by dying is not really a smart thing on a program.)



  /Matti Aarnio  <matti.aarnio@zmailer.org>
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Man page for revised timerfd API, Michael Kerrisk, (Wed Sep 26, 12:12 am)
Re: Man page for revised timerfd API, Davide Libenzi, (Wed Sep 26, 11:06 am)
Re: Man page for revised timerfd API, Michael Kerrisk, (Wed Sep 26, 2:13 pm)
Re: Man page for revised timerfd API, Geoff Clare, (Thu Sep 27, 1:20 am)
Re: Man page for revised timerfd API, Michael Kerrisk, (Thu Sep 27, 3:35 am)
Re: Man page for revised timerfd API, Michael Kerrisk, (Thu Sep 27, 3:50 am)
Re: Man page for revised timerfd API, Davide Libenzi, (Thu Sep 27, 9:45 am)
Re: Man page for revised timerfd API, Michael Kerrisk, (Tue Oct 2, 11:50 pm)
Re: Man page for revised timerfd API, Matti Aarnio, (Wed Oct 3, 1:14 am)
Re: Man page for revised timerfd API, Michael Kerrisk, (Thu Oct 4, 11:19 am)