From b106fb263d5d4f2a000cf9ea897310dcb18aec66 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Fri, 31 May 2013 16:34:34 +0200
Subject: [PATCH] Added distclean target. Somewhat improved error handling in
 readers.

---
 Makefile                  | 11 +++++++++++
 examples/Makefile         |  2 +-
 lib/Makefile              |  5 +++++
 lib/c/labcomm.c           |  1 +
 lib/c/labcomm_fd_reader.c |  1 +
 lib/c/labcomm_private.h   |  4 ++++
 test/Makefile             |  4 ++--
 7 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index e9388b0..375a244 100644
--- a/Makefile
+++ b/Makefile
@@ -32,3 +32,14 @@ clean-compiler:
 .PHONY: clean-%
 clean-%:
 	$(MAKE) -C $* -e clean
+
+.PHONY: distclean
+distclean: $(SUBDIRS:%=distclean-%)
+
+.PHONY: distclean-compiler
+distclean-compiler:
+	cd compiler ; ant clean
+
+.PHONY: distclean-%
+distclean-%:
+	$(MAKE) -C $* -e distclean
diff --git a/examples/Makefile b/examples/Makefile
index 5f7d860..6ec4b20 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -6,5 +6,5 @@ test:
 	echo More to be done...
 	cd simple ; sh compile.sh && sh run.sh
 
-clean:
+clean distclean:
 	echo To be done...
diff --git a/lib/Makefile b/lib/Makefile
index fd00fcf..ed696a8 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -10,3 +10,8 @@ clean:
 	cd c ; make clean
 	cd csharp ; make clean
 	cd java ; make clean
+
+distclean:
+	cd c ; make distclean
+	cd csharp ; make clean
+	cd java ; make clean
diff --git a/lib/c/labcomm.c b/lib/c/labcomm.c
index 216ca64..978640f 100644
--- a/lib/c/labcomm.c
+++ b/lib/c/labcomm.c
@@ -568,6 +568,7 @@ struct labcomm_decoder *labcomm_decoder_new(
     result->reader->data_size = 0;
     result->reader->count = 0;
     result->reader->pos = 0;
+    result->reader->error = 0;
     result->lock = lock;
     result->on_error = on_error_fprintf;
     result->on_new_datatype = on_new_datatype;
diff --git a/lib/c/labcomm_fd_reader.c b/lib/c/labcomm_fd_reader.c
index a9ee68c..d67e6f6 100644
--- a/lib/c/labcomm_fd_reader.c
+++ b/lib/c/labcomm_fd_reader.c
@@ -76,6 +76,7 @@ static int fd_fill(struct labcomm_reader *r, void *context)
     err = read(fd_context->fd, r->data, r->data_size);
     if (err <= 0) {
       r->count = 0;
+      r->error = -EPIPE;
       result = -EPIPE;
     } else {
       r->count = err;
diff --git a/lib/c/labcomm_private.h b/lib/c/labcomm_private.h
index 4bd2777..695938d 100644
--- a/lib/c/labcomm_private.h
+++ b/lib/c/labcomm_private.h
@@ -158,6 +158,9 @@ static inline unsigned int labcomm_read_packed32(struct labcomm_reader *r)
 
     if (r->pos >= r->count) {	
       r->action->fill(r, r->context);
+      if (r->error != 0) {
+	goto out;
+      }
     }
     tmp = r->data[r->pos];
     r->pos++;
@@ -166,6 +169,7 @@ static inline unsigned int labcomm_read_packed32(struct labcomm_reader *r)
       break; 
     }
   }
+out:
   return result;
 }
  
diff --git a/test/Makefile b/test/Makefile
index 0edf460..75a98a2 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -10,8 +10,8 @@ test: $(TESTS:%=test_%)
 #	PYTHONPATH=../lib/python \
 #		./test_encoder_decoder.py --labcomm="$(LABCOMM)" basic.lc
 
-.PHONY: clean
-clean:
+.PHONY: clean distclean
+clean distclean:
 	rm -rf gen
 
 .PHONY: test_%
-- 
GitLab