From b814e81bec237b07052088edf05d33086a28aa5d Mon Sep 17 00:00:00 2001
From: Adam Sampson <ats@offog.org>
Date: Wed, 12 Mar 2008 16:43:15 +0000
Subject: [PATCH] Do away with the killval hack. This now uses the same
 approach to detect a kill as libkrocif.

---
 support/tock_support_cif.h | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/support/tock_support_cif.h b/support/tock_support_cif.h
index 87fb06c..43703f5 100644
--- a/support/tock_support_cif.h
+++ b/support/tock_support_cif.h
@@ -48,6 +48,11 @@ static inline void tock_init_chan_array (Channel *pointTo, Channel **pointFrom,
 //}}}
 
 //{{{  top-level process interface
+static void tock_tlp_input_bcall (FILE *in, int *ch) occam_unused;
+static void tock_tlp_input_bcall (FILE *in, int *ch) {
+	*ch = fgetc (in);
+}
+
 static void tock_tlp_input (Workspace wptr) occam_unused;
 static void tock_tlp_input (Workspace wptr) {
 	Channel *out	= ProcGetParam (wptr, 0, Channel *);
@@ -55,16 +60,14 @@ static void tock_tlp_input (Workspace wptr) {
 	FILE *in	= ProcGetParam (wptr, 2, FILE *);
 
 	while (true) {
-		uint8_t ch;
-		KillableBlockingCallN (wptr, fread, kill, 4, &ch, sizeof ch, 1, in);
-
-		// Check if the call was killed.
-		// FIXME: This is a hack; it should be a proper CCSP function.
-		const word killval = *kill;
-		if (killval == 1 || killval == 2)
+		int ch = -1;
+		KillableBlockingCallN (wptr, tock_tlp_input_bcall, kill, 2, in, &ch);
+		if (ch == -1) {
+			// The call was killed -- exit.
 			break;
+		}
 
-		ChanOut (wptr, out, &ch, sizeof ch);
+		ChanOutChar (wptr, out, ch);
 	}
 }