Writing to a partially full pipe - Unix

This is a discussion on Writing to a partially full pipe - Unix ; Hello, I have a query regarding writing data to Unix pipes. Considering an 'almost full' unix pipe or FIFO with only 20 bytes free space left to be written to it. Will a write() (O_NONBLOCK not set) of 50 bytes ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Writing to a partially full pipe

  1. Writing to a partially full pipe

    Hello,
    I have a query regarding writing data to Unix pipes.
    Considering an 'almost full' unix pipe or FIFO with only 20 bytes free
    space left to be written to it. Will a write() (O_NONBLOCK not set) of
    50 bytes to the pipe partially write 20 bytes OR will it not write to
    the pipe at all and block till it can write the full 50 bytes.
    Please let me know it the question is clear.

    Thanks
    Yaniv

  2. Re: Writing to a partially full pipe

    On Feb 6, 3:26 am, Yaniv wrote:

    > I have a query regarding writing data to Unix pipes.
    > Considering an 'almost full' unix pipe or FIFO with only 20 bytes free
    > space left to be written to it. Will a write() (O_NONBLOCK not set) of
    > 50 bytes to the pipe partially write 20 bytes OR will it not write to
    > the pipe at all and block till it can write the full 50 bytes.
    > Please let me know it the question is clear.


    Assuming PIPE_BUF is greater than 50, which it would be on any sane
    UNIX system, the write will block until it can write the full 50 bytes
    (not writing to the pipe at all), and then write the full 50 bytes
    atomically.

    DS

  3. Re: Writing to a partially full pipe

    On Feb 6, 4:42*pm, David Schwartz wrote:
    > Assuming PIPE_BUF is greater than 50, which it would be on any sane
    > UNIX system, the write will block until it can write the full 50 bytes
    > (not writing to the pipe at all), and then write the full 50 bytes
    > atomically.


    Thanks David. Also can you let me know what would happen in the same
    scenario if the O_NONBLOCK is set.
    Will it write partially or will write return -1 with no write to the
    pipe at all.
    -Yaniv

  4. Re: Writing to a partially full pipe

    On Feb 6, 3:51 am, Yaniv wrote:

    > Thanks David. Also can you let me know what would happen in the same
    > scenario if the O_NONBLOCK is set.
    > Will it write partially or will write return -1 with no write to the
    > pipe at all.
    > -Yaniv


    It will return -1 with no write to the pipe at all.

    DS

  5. Re: Writing to a partially full pipe

    "David Schwartz" wrote in message
    news:e894d802-f6a2-4fa3-98a8-914c0d5fa9f4@d21g2000prf.googlegroups.com...
    > On Feb 6, 3:26 am, Yaniv wrote:
    >> I have a query regarding writing data to Unix pipes.
    >> Considering an 'almost full' unix pipe or FIFO with only 20 bytes free
    >> space left to be written to it. Will a write() (O_NONBLOCK not set) of
    >> 50 bytes to the pipe partially write 20 bytes OR will it not write to
    >> the pipe at all and block till it can write the full 50 bytes.
    >> Please let me know it the question is clear.

    >
    > Assuming PIPE_BUF is greater than 50, which it would be on any sane
    > UNIX system,


    PIPE_BUF is (quite reasonably) required to be at least 512 bytes.

    > the write will block until it can write the full 50 bytes
    > (not writing to the pipe at all), and then write the full 50 bytes
    > atomically.


    In general, any write up to and including PIPE_BUF bytes will either be
    written in its entirety, without interleaving data from other writes, or not
    at all. The latter can occur if blocked and interrupted by a signal, or if
    non-blocking and there is insufficient buffer space.

    Alex



+ Reply to Thread