Gr_file_sink error handling and incorrect behavior on broken pipes

This relates to a previous post regarding the behavior of gr_file_sink
when it writes to a named pipe and the other side of the pipe stops
reading.

Currently the bahavior of the block is that it does not catch the
“errno=32=EPIPE”
(or any errno!=0 for that matter)
and thus the work function returns a false number of consumed items
(for some reason even with a broken pipe it always returns 512 items
consumed…)

As a result the remaing graph keeps producing samples that are somehow
falsely
consumed into the file sink.

I added a couple of lines to check for the errno!=0

Please check and comment.
I attach 2 python files to check the bahavior of the file sink.
Firtst do " mkfifo fifo_rx" and then run tx.py and rx.py in different
shells.
You can stop start rx.py any number of times and tx.py pauses and
restarts as well.

Observe though that tx.py consumes cpu even when the pipe is broken
because it continuosly calls
the gr_file_sink work function…

Achilleas

==========

diff --git a/gnuradio-core/src/lib/io/gr_file_sink.cc
b/gnuradio-core/src/lib/io/gr_file_sink.cc
index aab0158…52d4c84 100644
— a/gnuradio-core/src/lib/io/gr_file_sink.cc
+++ b/gnuradio-core/src/lib/io/gr_file_sink.cc
@@ -27,6 +27,8 @@
#include <gr_file_sink.h>
#include <gr_io_signature.h>
#include
+#include
+#include

gr_file_sink_sptr
@@ -64,9 +66,16 @@ gr_file_sink::work (int noutput_items,
return noutput_items; // drop output on the floor

while (nwritten < noutput_items){

  • errno=0;
    int count = fwrite (inbuf, d_itemsize, noutput_items - nwritten,
    d_fp);
  • if (count == 0) // FIXME add error handling
  • if (count == EOF){ // FIXME add error handling
  •  //printf("fwrite() returned EOF. Requested %d and wrote
    

%d\n",noutput_items - nwritten,count);
break;

  • }
  • if (errno!=0){ // FIXME add error handling
  •  //printf("fwrite() raised error no = %d. Requested %d and wrote
    

%d\n",errno,noutput_items - nwritten,count);

  •  break;
    
  • }
    nwritten += count;
    inbuf += count * d_itemsize;
    }

On Fri, Oct 14, 2011 at 1:13 AM, Achilleas A.
<[email protected]

wrote:

You can stop start rx.py any number of times and tx.py pauses and
restarts as well.

Observe though that tx.py consumes cpu even when the pipe is broken
because it continuosly calls
the gr_file_sink work function…

Achilleas

Achilleas,

I have created ticket #448 about this issue. The basic mechanism of your
patch looks correct, but it’s worth having a discussion about the extent
of
the errors checked and the behavior when an error occurs. I will add
this to
the list of topics to discuss during our next developers’ conference
call
(next Thursday).

Thanks!
Tom

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs