apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Florath ...@flonatel.org>
Subject Async write
Date Wed, 29 Feb 2012 07:05:36 GMT
Hello!

I have a question about the implementation of the different 'write'
implementations especially when using async write (I'll concentrate
on the Unix implementation).

>From [1]:

                do {
                    do {
                        rv = write(thefile->filedes, buf, *nbytes);
                    } while (rv == (apr_size_t)-1 && errno == EINTR);
                    if (rv == (apr_size_t)-1 &&
                        (errno == EAGAIN || errno == EWOULDBLOCK)) {
                        *nbytes /= 2; /* yes, we'll loop if kernel lied
                                       * and we can't even write 1 byte
                                       */
                    }
                    else {
                        break;
                    }
                } while (1);

1) Can you please tell me why and when the kernel (and which kernel) lied?
2) Why is there no test 'rv == 0'?
   (From the write(2) man page:
     'On success, the number of bytes written is returned (zero indicates
      nothing was written')
3) Why are there other similar places (e.g. in [3]) where the '*nbytes/=2'
   are missing?
4) Can this kernel lying only happen in file io and not in socket io?
5) Is there an endless loop when (for whatever reason) it was not possible
   write something in the network io [3]?
6) Why you do not use a well known solution for this e.g. from [4]?

I'm especially interested in the answer to question 5) because I think
I found an endless loop when using tomcat with APR - and currently I'm
looking for the correct place to report / fix this.

Kind regards

Andreas Florath


[1] http://svn.apache.org/repos/asf/apr/apr/trunk/file_io/unix/readwrite.c
[2] Debian 6.0.4 man page for write(2), written 2010-08-29
[3] http://svn.apache.org/repos/asf/apr/apr/trunk/network_io/unix/sendrecv.c
[4] ‘Advanced Programming in a UNIX environment’, Stevens, W. Richard,
    Addison Wesley, 1993, p 365.

Mime
View raw message