home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / std_unix / volume.12 / text0021.txt < prev    next >
Encoding:
Internet Message Format  |  1989-01-07  |  23.9 KB

  1. From: jsq@usenix.uucp (John Quarterman)
  2.  
  3.        Pipe Write Problems     Page 1 of 11      IEEE 1003.1 N.116
  4.  
  5.  
  6.  
  7.                            John S. Quarterman
  8.                            Institutional Representative
  9.                            From USENIX to IEEE P1003
  10.                            {uunet,ucbvax,seismo}!usenix!jsq
  11.  
  12.                            Texas Internet Consulting
  13.                            701 Brazos, Suite 500
  14.                            Austin, Texas 78701-3243
  15.                            +1-512-320-9031
  16.                            jsq@longway.tic.com
  17.  
  18.                            24 August 1987
  19.  
  20.        Attention: P1003 Working Group
  21.        Secretary, IEEE Standards Board
  22.        345 East 47th Street
  23.        New York, NY 10017
  24.  
  25.        Cc: 1003.1 Technical Reviewers:
  26.  
  27.        Maggie Lee, 2         Jeff Smits, 6       Hal Jespersen, Rationale
  28.        +1-408-746-7216         +1-201-522-6263       +1-415-420-6400
  29.        ihnp4!amdahl!maggie   ihnp4!attunix!smits   ucbvax!unisoft!hlj
  30.  
  31.        There are several problems in IEEE Std 1003.1, Draft 11
  32.        regarding writes to a pipe or FIFO.  These problems are
  33.        sufficient to produce a no ballot from USENIX.  This
  34.        objection includes discussion of the problems, their
  35.        sources, and suggested solutions, including both standard
  36.        and rationale text.
  37.  
  38.  
  39.        1.  Problems
  40.  
  41.        1.1  Ambiguous O_NONBLOCK wording in Draft 11, 6.4.2.2.
  42.  
  43.        Understanding the case of the triple condition
  44.  
  45.       + O_NONBLOCK is set,
  46.  
  47.       + and {PIPE_BUF} < nbyte <= {PIPE_MAX},
  48.  
  49.       + and 0 < immediately writable < nbyte,
  50.  
  51.        requires a close reading of Draft 11, 6.4.2.2, page 125,
  52.        lines 224-227:
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  62.  
  63.  
  64.  
  65.        Pipe Write Problems     Page 2 of 11      IEEE 1003.1 N.116
  66.  
  67.  
  68.  
  69.         If the O_NONBLOCK flag is set, write() shall not block
  70.         the process.  If nbyte > {PIPE_BUF}, and some data can
  71.         be written without blocking the process, write() shall
  72.         write what it can and return the number of bytes
  73.         written.  Otherwise, it shall return -1 and errno shall
  74.         be set to [EAGAIN].
  75.  
  76.        It is not immediately obvious what ``Otherwise'' refers to
  77.        (which clause of the condition?).  But in the context of the
  78.        paragraph at lines 217-221 it must refer to the case when
  79.        {PIPE_BUF} < nbyte <= {PIPE_MAX} and no data can be written
  80.        without blocking the process.
  81.  
  82.        1.2  Nonblocking partial pipe writes are an option in
  83.         Draft 11.
  84.  
  85.        According to David Willcox, who was in many of the atomic
  86.        pipe write small groups, the word ``can'' in both uses in
  87.        the preceding quote is meant to refer to what the
  88.        implementation permits.    In other words, the case where
  89.        ``some data can be written'' may refer to there being some
  90.        space free in the pipe, or the case may be null, meaning
  91.        that [EAGAIN] will always be returned when {PIPE_BUF} <
  92.        nbyte <= {PIPE_MAX}, regardless of whether there is free
  93.        space in the pipe or not.  Which is to say that the standard
  94.        permits the implementation to perform partial writes, but
  95.        does not require it to do so.
  96.  
  97.        Partial writes are not implementation-defined (according to
  98.        the definition in 2.1), because the standard completely
  99.        describes their behavior (or attempts to).  So partial
  100.        writes are an interface implementation option in Draft 11,
  101.        even though they are not properly specified as such by the
  102.        use of the word ``may'' or listing in 2.2.1.2.
  103.  
  104.        1.3  Incorrect error code?
  105.  
  106.        If partial writes are not implemented, the error [EAGAIN] is
  107.        not appropriate, because the write will never succeed, no
  108.        matter how many times it is retried.  Better would be
  109.        [EINVAL], which matches the other cases where retrying will
  110.        not help.  However, this argument assumes that {PIPE_BUF} is
  111.        not only the maximum atomic size, but also the maximum
  112.        amount writable on one operation: this may not be so; see
  113.        below.
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  124.  
  125.  
  126.  
  127.        Pipe Write Problems     Page 3 of 11      IEEE 1003.1 N.116
  128.  
  129.  
  130.  
  131.        1.4  {PIPE_MAX} with O_NONBLOCK clear.
  132.  
  133.        Should {PIPE_MAX} apply when O_NONBLOCK is not set?  All of
  134.        Version 7, System V Release 3, 4.2BSD, and 4.3BSD permit
  135.        arbitrarily large values of nbyte when O_NDELAY is not set.
  136.        While it is possible to imagine a system where such a limit
  137.        would be required by the implementation, there seem to be
  138.        none at the moment, so there are probably no applications
  139.        that depend on it.  The enforcement of such a limit would
  140.        make pipes basically different from other things that
  141.        write() can be applied to, requiring extra code in
  142.        applications.  Thus there is no obvious advantage in
  143.        portability for applications.  So {PIPE_MAX} should not be
  144.        applied when O_NONBLOCK is clear.
  145.  
  146.  
  147.        2.  Sources of the problems.
  148.  
  149.        There are three basic sources of confusion about the
  150.        behavior of pipes and FIFOs (especially when the non-
  151.        blocking flag is set):
  152.  
  153.      1.  It is not clear what the various existing systems do.
  154.  
  155.      2.  It is clear that they do many things differently.
  156.  
  157.      3.  It is not clear what behavior is important to
  158.          applications, and thus worth standardizing.
  159.  
  160.        2.1  Existing systems.
  161.  
  162.        Some of the following descriptions may not be totally
  163.        accurate, but they should serve to illustrate the point of
  164.        diversity.
  165.  
  166.       + Version 7 introduced atomicity of writes to pipes.    The
  167.         manual page write(2) guarantees that write requests of
  168.         4096 bytes or less will not be interleaved with writes
  169.         from any other process.  The purpose of this feature
  170.         was to allow multiple processes to write to the same
  171.         pipe while permitting a single reader to parse their
  172.         data.
  173.  
  174.         4096 also happens to be the size of a pipe, and is
  175.         fixed at compile time (it is not larger because that
  176.         would have made pipes large files, that is, they would
  177.         have had indirect blocks).
  178.  
  179.         Any amount (that will fit in an int) of data may be
  180.         requested on a single call to write().
  181.  
  182.  
  183.  
  184.  
  185.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  186.  
  187.  
  188.  
  189.        Pipe Write Problems     Page 4 of 11      IEEE 1003.1 N.116
  190.  
  191.  
  192.  
  193.         Version 7 does not have a non-blocking flag.
  194.  
  195.       + The SVID requires atomicity of writes to pipes when the
  196.         request is of {PIPE_BUF} bytes or less.  This feature
  197.         may have been introduced from the /usr/group Standard,
  198.         which had it.
  199.  
  200.         There is no maximum write request, regardless of
  201.         whether O_NDELAY is set.
  202.  
  203.         With O_NDELAY set, write requests of less than
  204.         {PIPE_BUF} bytes either succeed or return zero.  Write
  205.         requests of more than that may also succeed partially,
  206.         returning the amount written.
  207.  
  208.       + 4.2BSD appears to guarantee atomicity of pipe write
  209.         requests up to 1024 bytes.    It will return an error for
  210.         requests for more than 4096 bytes when the O_NDELAY
  211.         flag is set.  Partial writes are not done.    With the
  212.         flag clear, any size write request will succeed
  213.         eventually.
  214.  
  215.       + 4.3BSD does not guarantee atomicity of any size pipe
  216.         write (greater than one byte).  The maximum amount that
  217.         can be requested will vary dynamically, as will the
  218.         maximum amount that can be written on a single
  219.         operation.    With the O_NDELAY flag set, any write of
  220.         more than one byte may be partial.    UCB CSRG is
  221.         probably amenable to changing this behavior.
  222.  
  223.       + Version 8 does not necessarily measure the maximum
  224.         amount of data that can be written to a pipe on a given
  225.         operation in bytes, i.e., it may depend on the number
  226.         of outstanding write requests.
  227.  
  228.         There is no nonblocking flag in Version 8 or Version 9.
  229.  
  230.        2.2  Useful behavior.
  231.  
  232.        It is more useful to specify how an application should
  233.        interpret a return value than it is to specify precisely
  234.        when the implementation shall return it.     I believe this
  235.        observation may be the rope for climbing out of the chronic
  236.        pipe write morasse.
  237.  
  238.        [EAGAIN]       should mean that retrying later with the same
  239.            size request may succeed.  The Rationale should
  240.            recommend actions the application should take in
  241.            such a case.     Because some systems dynamically
  242.            vary their pipe size, what would have succeeded
  243.            this time on an empty pipe may not succeed next
  244.  
  245.  
  246.  
  247.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  248.  
  249.  
  250.  
  251.        Pipe Write Problems     Page 5 of 11      IEEE 1003.1 N.116
  252.  
  253.  
  254.  
  255.            time.  Of course, if the request was for
  256.            {PIPE_BUF} or less bytes, retries shall
  257.            eventually succeed (unless no reader reads
  258.            enough from the pipe).  But it is not useful for
  259.            the standard to attempt to specify for exactly
  260.            what larger requests [EAGAIN] will be returned,
  261.            or the probability of success on later retries.
  262.            After all, if the reader does not read, no
  263.            retries will succeed.
  264.  
  265.        [EINVAL]       should mean that retrying later with the same
  266.            size request shall never succeed.  But the
  267.            standard should not require the implementation
  268.            to always return this error at a fixed limit.
  269.  
  270.        There is no reason for the standard to try to specify what
  271.        happens in every corner case produced by the intersections
  272.        of all the known implementations.  The standard should
  273.        specify behavior that promotes portability of applications
  274.        and that is implementable relatively readily on existing
  275.        systems.     In addition, the behavior of writes to pipes or
  276.        FIFOs should be made as little different from that of writes
  277.        to other file descriptors as possible.  The main reason for
  278.        making it different at all is that POSIX does not currently
  279.        include any more sophisticated interprocess communication
  280.        facility: for example, given a reliable sequenced datagram
  281.        service, there would be no need to require pipes to be
  282.        atomic.
  283.  
  284.      1.  Atomic writes are useful.    The standard should specify
  285.          that write requests of {PIPE_BUF} or less bytes shall
  286.          be atomic, regardless of whether O_NONBLOCK is set.
  287.  
  288.      2.  Write requests of more than {PIPE_BUF} bytes with
  289.          O_NONBLOCK set are useful.     A real time data
  290.          acquisition process might want to write large amounts
  291.          of data through a pipe to a single processing process,
  292.          while never blocking.
  293.  
  294.      3.  Partial writes are useful, but not useful enough for
  295.          the standard to require the implementation to include
  296.          them.  The standard should require portable
  297.          applications to expect them, however: since the
  298.          application should expect them for other kinds of
  299.          writes, anyway.  In other words, partial writes should
  300.          not be a major option, instead merely an
  301.          implementation-defined detail.  Exactly when they
  302.          occur is not important enough to specify (especially
  303.          considering that it is not specified for other kinds
  304.          of writes), except that they are prohibited when nbyte
  305.          <= {PIPE_BUF} because of the guarantee of atomicity.
  306.  
  307.  
  308.  
  309.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  310.  
  311.  
  312.  
  313.        Pipe Write Problems     Page 6 of 11      IEEE 1003.1 N.116
  314.  
  315.  
  316.  
  317.          There is no strong reason for an application to be
  318.          able to discover at compile or run time whether
  319.          partial writes are implemented: every application
  320.          should assume that they may be implemented.
  321.  
  322.        The usefulness of {PIPE_MAX} is slightly dubious, and it
  323.        might be better to eliminate it, instead specifying that
  324.        [EINVAL] may be returned whenever O_NONBLOCK is set and
  325.        nbyte > {PIPE_BUF}.  But let us assume that it is useful.
  326.  
  327.      1.  A maximum amount that can be requested without ever
  328.          producing [EINVAL] is worthwhile.    {PIPE_MAX} could be
  329.          used for this.  But it should not apply if O_NONBLOCK
  330.          is not set.
  331.  
  332.      2.  {PIPE_MAX} >= {PIPE_BUF}.    Allowing {PIPE_MAX} <
  333.          {PIPE_BUF} would permit a guaranteed atomic write to
  334.          return [EINVAL], which is a contradiction.
  335.  
  336.      3.  The standard should explicitly permit an
  337.          implementation to set {PIPE_MAX} = {PIPE_BUF}, simply
  338.          because there is no reason to prohibit it.     This would
  339.          not rule out partial writes, but would mean that
  340.          applications running on such an implementation should
  341.          never depend on successful writes with nbyte >
  342.          {PIPE_BUF}.
  343.  
  344.      4.  The standard should permit an implementation to set
  345.          {PIPE_MAX} = {INT_MAX}, meaning that [EINVAL] will
  346.          never be returned.     That is effectively what some
  347.          implementations do, and there is no reason not to if
  348.          partial writes are implemented.
  349.  
  350.      5.  An implementation could even set all three limits
  351.          equal: {PIPE_BUF} = {PIPE_MAX} = {INT_MAX}, meaning
  352.          that [EINVAL] will never be returned, there are no
  353.          partial writes, and all writes are atomic.
  354.  
  355.        Finally, this is an interface standard: it should not try to
  356.        specify implementation details, such as the internal
  357.        buffering arrangements of the pipe.  Such phrases as ``it
  358.        shall write as much as it can'' are inappropriate.
  359.  
  360.  
  361.        3.  Rewording.
  362.  
  363.        Here is rewording to account for the implications of the
  364.        above arguments.
  365.  
  366.        The text and tables below include specifications and
  367.        rationale for {PIPE_MAX}.  But, if the Working Group decides
  368.  
  369.  
  370.  
  371.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  372.  
  373.  
  374.  
  375.        Pipe Write Problems     Page 7 of 11      IEEE 1003.1 N.116
  376.  
  377.  
  378.  
  379.        to drop {PIPE_MAX}, it can be excised with no ill effects.
  380.        References to it should then also be removed from Draft 11
  381.        2.9.2, page 42, lines 808-810, and 5.7.1.2, page 117, line
  382.        971.
  383.  
  384.        3.1  Standard.
  385.  
  386.        Move the definition of {PIPE_MAX} down into the text that
  387.        specifies what happens when O_NONBLOCK is set.  That is,
  388.        first remove Draft 11 6.4.2.2, page 125, lines 215-216:
  389.  
  390.         Write requests for greater than {PIPE_MAX} bytes shall
  391.         result in a return of value of -1 and set errno to
  392.         [EINVAL].
  393.  
  394.        Then replace the wording (quoted in 1.1 above) of Draft 11,
  395.        6.4.2.2, page 125, lines 224-227 with this new wording:
  396.  
  397.         If the O_NONBLOCK flag is set, write requests shall be
  398.         handled differently in the following ways: The write()
  399.         function shall not block the process.  Write requests
  400.         for {PIPE_BUF} or less bytes shall either succeed
  401.         completely and return nbyte, or return -1 and set errno
  402.         to [EAGAIN] to indicate that retrying the write() later
  403.         with the same arguments may succeed.  Write requests
  404.         for more than {PIPE_BUF} bytes may in addition write
  405.         some amount of data less than nbyte and return the
  406.         amount written.  Write requests for more than
  407.         {PIPE_MAX} bytes may in addition return -1 and set
  408.         errno to [EINVAL] to indicate that retrying the write()
  409.         later with the same arguments shall never succeed.
  410.         {PIPE_MAX} shall be greater than or equal to {PIPE_BUF}
  411.         and less than or equal to {INT_MAX}.
  412.  
  413.        The beginning of the following paragraph, 6.4.2.2, page 125,
  414.        lines 228-229, is misleading and should be changed from
  415.  
  416.         When attempting to write to a file descriptor...
  417.  
  418.        to
  419.  
  420.         When attempting to write to a file descriptor (other
  421.         than one for a pipe or FIFO)...
  422.  
  423.        The meaning of [EINVAL] when set by write() as specified in
  424.        6.4.2.4, page 126, lines 260-261, should be changed from
  425.  
  426.        [EINVAL]       An attempt was made to write more than
  427.            {PIPE_MAX} bytes to a pipe or FIFO special file.
  428.        to
  429.  
  430.  
  431.  
  432.  
  433.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  434.  
  435.  
  436.  
  437.        Pipe Write Problems     Page 8 of 11      IEEE 1003.1 N.116
  438.  
  439.  
  440.  
  441.        [EINVAL]       An attempt was made to write to a pipe or FIFO
  442.            special file with a value of nbyte greater than
  443.            {PIPE_MAX} and also large enough that the
  444.            operation shall never succeed if retried.
  445.  
  446.        3.2  Rationale.
  447.  
  448.        In the Rationale, remove the editorial note from B.6.4.2,
  449.        Page 240, line 2104, and replace B.6.4.2, Page 240, line
  450.        2105 (``Write to a Pipe'') with:
  451.  
  452.        [begin replacement]
  453.  
  454.        An attempt to write to a pipe or FIFO has several major
  455.        characteristics:
  456.  
  457.        Atomic/non-atomic
  458.         A write is atomic if the whole amount written in one
  459.         operation is not interleaved with data from any other
  460.         process.  This is useful when there are multiple
  461.         writers sending data to a single reader.  Applications
  462.         need to know how large a write request can be expected
  463.         to be performed atomically.     We call this maximum
  464.         {PIPE_BUF}.     The standard does not say whether write
  465.         requests for more than {PIPE_BUF} bytes will be atomic,
  466.         but requires that writes of {PIPE_BUF} or less bytes
  467.         shall be atomic.
  468.  
  469.        Blocking/immediate
  470.         Blocking is only possible with O_NONBLOCK clear.  If
  471.         there is enough space for all the data requested to be
  472.         written immediately, the implementation should do so.
  473.         Otherwise, the process may block, that is, pause until
  474.         enough space is available for writing.  The effective
  475.         size of a pipe or FIFO (the maximum amount that can be
  476.         written in one operation without blocking) may vary
  477.         dynamically, depending on the implementation, so it is
  478.         not possible to specify a fixed value for it.
  479.  
  480.        Complete/partial/deferred
  481.         A write request,
  482.  
  483.          int fildes, nbyte, ret;
  484.          char *buf;
  485.  
  486.          ret = write(fildes, buf, nbyte);
  487.  
  488.         may return
  489.  
  490.         complete:    ret = nbyte
  491.  
  492.  
  493.  
  494.  
  495.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  496.  
  497.  
  498.  
  499.        Pipe Write Problems     Page 9 of 11      IEEE 1003.1 N.116
  500.  
  501.  
  502.  
  503.         partial:    ret < nbyte
  504.             This shall never happen if nbyte <=
  505.             {PIPE_BUF}.  If it does happen (with nbyte
  506.             > {PIPE_BUF}), the standard does not
  507.             guarantee atomicity, even if ret <=
  508.             {PIPE_BUF}, because atomicity is guaranteed
  509.             according to the amount requested, not the
  510.             amount written.
  511.  
  512.         deferred:    ret = -1, errno = [EAGAIN]
  513.             This error indicates that a later request
  514.             may succeed.  It does not indicate that it
  515.             shall succeed, even if nbyte <= {PIPE_BUF},
  516.             because if no process reads from the pipe
  517.             or FIFO, the write will never succeed.    An
  518.             application could usefully count the number
  519.             of times [EAGAIN] is caused by a particular
  520.             value of nbyte > {PIPE_BUF} and perhaps do
  521.             later writes with a smaller value, on the
  522.             assumption that the effective size of the
  523.             pipe may have decreased.
  524.  
  525.         Partial and deferred writes are only possible with
  526.         O_NONBLOCK set.
  527.  
  528.        Requestable/invalid
  529.         If a write request shall never succeed with the value
  530.         given for nbyte, the request is invalid, and write()
  531.         shall return -1 with errno set to [EINVAL].     This is
  532.         only permitted to happen when nbyte > {PIPE_MAX} and
  533.         O_NONBLOCK is set, and it is never required to happen.
  534.         {PIPE_MAX} is not necessarily a minimum on the
  535.         effective size of a pipe or FIFO; if it says anything
  536.         about that size, it is that it sometimes varies above
  537.         {PIPE_MAX}.     Because {PIPE_MAX} specifies the maximum
  538.         size write request that shall never cause [EINVAL], it
  539.         must be greater than or equal to the maximum atomic
  540.         write size, {PIPE_BUF}.  {PIPE_BUF} and {PIPE_MAX} may
  541.         be equal, which means that [EINVAL] may be produced by
  542.         any write of greater than {PIPE_BUF} bytes.     {PIPE_MAX}
  543.         may be equal to {INT_MAX}, meaning that [EINVAL] shall
  544.         never be returned (unless nbyte > {INT_MAX}, when the
  545.         result is implementation-defined).    All three limits
  546.         may be equal, meaning that [EINVAL] shall never be
  547.         returned, no partial writes are done, and all completed
  548.         writes are atomic.    Applications should be prepared for
  549.         all these cases.
  550.  
  551.        The relations of these properties are best shown in tables.
  552.  
  553.  
  554.  
  555.  
  556.  
  557.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  558.  
  559.  
  560.  
  561.        Pipe Write Problems    Page 10 of 11      IEEE 1003.1 N.116
  562.  
  563.  
  564.  
  565.          ________________________________________________
  566.         | Write to a Pipe or FIFO with O_NONBLOCK clear.|
  567.         |_____________|_________________________________|
  568.         | immediately |                    |
  569.         |  writable:  |   none      some         nbyte  |
  570.         |_____________|_________________________________|
  571.         |          | atomic    atomic        atomic  |
  572.         |    nbyte <=  | blocking    blocking   immediate|
  573.         | {PIPE_BUF}  |   nbyte     nbyte         nbyte  |
  574.         |_____________|_________________________________|
  575.         |          | atomic?    atomic?        atomic? |
  576.         |    nbyte >      | blocking    blocking   immediate|
  577.         | {PIPE_BUF}  |   nbyte     nbyte         nbyte  |
  578.         |_____________|_________________________________|
  579.  
  580.        If the O_NONBLOCK flag is clear, a write request shall block
  581.        if the amount writable immediately is less than that
  582.        requested.  If the flag is set (by fcntl()), a write request
  583.        shall never block.
  584.  
  585.     __________________________________________________________
  586.        |       Write to a Pipe or FIFO with O_NONBLOCK set.     |
  587.        |____________|____________________________________________|
  588.        | immediately|                         |
  589.        |  writable: |       none          some        nbyte     |
  590.        |____________|____________________________________________|
  591.        |   nbyte <= |       -1,          -1,        atomic     |
  592.        | {PIPE_BUF} |     [EAGAIN]    [EAGAIN]    nbyte     |
  593.        |____________|____________________________________________|
  594.        |        |            atomic?           atomic?     |
  595.        |        |            < nbyte           <=nbyte     |
  596.        |   nbyte >  |       -1,         or -1,        or -1,     |
  597.        | {PIPE_BUF} |     [EAGAIN]    [EAGAIN]       [EAGAIN]     |
  598.        |____________|____________________________________________|
  599.        |        |            atomic?           atomic?     |
  600.        |        |            < nbyte           <=nbyte     |
  601.        |   nbyte >  |       -1,         or -1,        or -1,     |
  602.        | {PIPE_MAX} |    ([EAGAIN]      ([EAGAIN]      ([EAGAIN]     |
  603.        |        |  or [EINVAL])   or [EINVAL])   or [EINVAL])|
  604.        |____________|____________________________________________|
  605.  
  606.        There is no way provided for an application to determine
  607.        whether the implementation will ever perform partial writes
  608.        to a pipe or FIFO.  Every application should be prepared to
  609.        handle partial writes when O_NONBLOCK is set and the
  610.        requested amount is greater than {PIPE_BUF}, just as every
  611.        application should be prepared to handle partial writes on
  612.        other kinds of file descriptors.
  613.  
  614.        Where the standard requires -1 returned and errno set to
  615.        [EAGAIN], most historical implementations return 0 (with the
  616.  
  617.  
  618.  
  619.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  620.  
  621.  
  622.  
  623.        Pipe Write Problems    Page 11 of 11      IEEE 1003.1 N.116
  624.  
  625.  
  626.  
  627.        O_NDELAY flag set: that flag is the historical predecessor
  628.        of O_NONBLOCK, but is not itself in the standard).  The
  629.        error indications in the standard were chosen so that an
  630.        application can distinguish these cases from end of file.
  631.        While write() cannot receive an indication of end of file,
  632.        read() can, and the Working Group chose to make the two
  633.        functions have similar return values.  Also, some existing
  634.        systems (e.g., Version 8) permit a write of zero bytes to
  635.        mean that the reader should get an end of file indication:
  636.        for those systems, a return value of zero from write
  637.        indicates a successful write of an end of file indication.
  638.        [end replacement]
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.        $Revision: 3.1 $          DRAFT     $Date: 87/08/24 10:54:56 $
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.                  CONTENTS
  690.  
  691.  
  692.        1.  Problems.............................................  1
  693.        1.1    Ambiguous O_NONBLOCK wording in Draft 11,
  694.         6.4.2.2.........................................  1
  695.        1.2    Nonblocking partial pipe writes are an option
  696.         in Draft 11.....................................  2
  697.        1.3    Incorrect error code?...........................  2
  698.        1.4    {PIPE_MAX} with O_NONBLOCK clear................  3
  699.  
  700.        2.  Sources of the problems..............................  3
  701.        2.1    Existing systems................................  3
  702.        2.2    Useful behavior.................................  4
  703.  
  704.        3.  Rewording............................................  6
  705.        3.1    Standard........................................  7
  706.        3.2    Rationale.......................................  8
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.                   - i -
  744.  
  745.  
  746.  
  747.  
  748.  
  749. Volume-Number: Volume 12, Number 22
  750.  
  751.