discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] gr_file_sink error handling and incorrect behavior on


From: Achilleas Anastasopoulos
Subject: [Discuss-gnuradio] gr_file_sink error handling and incorrect behavior on broken pipes
Date: Fri, 14 Oct 2011 01:13:02 -0400

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 <stdexcept>
+#include <cstdio>
+#include <cerrno>


 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;
   }

Attachment: diff.txt
Description: Text document

Attachment: tx.py
Description: Text Data

Attachment: rx.py
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]