Buffered input/output.

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default Buffered input/output.

    Hello,

    I am struggling with the following problem:
    Two unrelated programs communicate via two fifos (is this a good way of
    communicating between two programs?).
    The first program opens one fifo for reading (R) and the second fifo
    for writing (W), the second program does the same but opens fifos vice
    versa, the first fifo for writing and the second fifo for reading.
    (Also, can i open these fifos with fopen() without blocking? (I know
    about open() and O_NONBLOCK but can i do the same with fopen()?))

    The first program writes something to its W fifo, calls fflush(W) and
    the second program meanwhile has issued select() on its R fifo,
    select() successfully returns, then a fread() follows on R fifo but
    it just blocks.

    I assume this has something to do with buffered input?
    How do i read from the second programs R fifo after the first program
    has successfully written something to it?
    i tried calling setvbuf(R,NULL,_IONBF,0) but it still does not work.
    Also, i am curious - how to auto-flush output (In my case R fifo), so i
    didnt have to call fflush() after each write to that fifo?


    P.Krumins
    Peteris Krumins Guest

  2. Similar Questions and Discussions

    1. buffered output?
      I have an odd problem... I have a perl script that execs another program: $cmd = "motuds t1.dat t2.dat t3.dat > out1"; exec $cmd; Motuds...
    2. International Input/Output
      I hope somone can offer some advice. I have built a database accepting information through ASP from clients in UK, Germany France and Russia. I set...
    3. input/output
      Hi I need to have lists of inputs and outputs being displayed in to their prospective fields when they are called or typed by user.Say, If the...
    4. [PHP] Cannot output before input
      >ob_flush() Thanks curt, it's working ^_^
    5. output/input parameter
      i follow this help: http://support.microsoft.com/default.aspx?scid=kb;en- us;209576 to synchronize two combo boxes. the form works but the form...
  3. #2

    Default Re: Buffered input/output.

    Peteris Krumins <pkruminsREMOVETHIS@inbox.lv> wrote:
    >Hello,
    >
    > I am struggling with the following problem:
    > Two unrelated programs communicate via two fifos (is this a good way of
    > communicating between two programs?).
    > The first program opens one fifo for reading (R) and the second fifo
    > for writing (W), the second program does the same but opens fifos vice
    > versa, the first fifo for writing and the second fifo for reading.
    > (Also, can i open these fifos with fopen() without blocking? (I know
    > about open() and O_NONBLOCK but can i do the same with fopen()?))
    >
    > The first program writes something to its W fifo, calls fflush(W) and
    > the second program meanwhile has issued select() on its R fifo,
    > select() successfully returns, then a fread() follows on R fifo but
    > it just blocks.
    You are using select(), which tells you when a *file descriptor*
    will block. But then you say you are using fread(), which reads
    from a stream (which doesn't block at the same times).

    You can't expect to mix calls using fd's and fp's.
    > I assume this has something to do with buffered input?
    > How do i read from the second programs R fifo after the first program
    > has successfully written something to it?
    Use read() instead of fread(), for example.
    > i tried calling setvbuf(R,NULL,_IONBF,0) but it still does not work.
    > Also, i am curious - how to auto-flush output (In my case R fifo), so i
    > didnt have to call fflush() after each write to that fifo?
    What's wrong with using fflush()?

    --
    Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
    Ukpeagvik (Barrow, Alaska) [email]floyd@barrow.com[/email]
    Floyd Davidson Guest

  4. #3

    Default Re: Buffered input/output.

    Floyd Davidson <floyd@barrow.com> wrote in
    news:87r84kemx2.fld@barrow.com:
    > Peteris Krumins <pkruminsREMOVETHIS@inbox.lv> wrote:
    >>Hello,
    >>
    [...]
    > You are using select(), which tells you when a *file descriptor*
    > will block. But then you say you are using fread(), which reads
    > from a stream (which doesn't block at the same times).
    > You can't expect to mix calls using fd's and fp's.
    Oh, thanks for this information. I didn't know this!
    >> I assume this has something to do with buffered input?
    >> How do i read from the second programs R fifo after the first
    >> program has successfully written something to it?
    >
    > Use read() instead of fread(), for example.
    Yes, it solved the problem.
    >> i tried calling setvbuf(R,NULL,_IONBF,0) but it still does not work.
    >> Also, i am curious - how to auto-flush output (In my case R fifo),
    >> so i didnt have to call fflush() after each write to that fifo?
    >
    > What's wrong with using fflush()?
    Nothing is wrong, i just thought there was a method to auto-flush output
    buffer on each write, so i didnt waste time with fflush() calls.


    P.Krumins
    Peteris Krumins Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139