diff --git a/src/invoker/invokelib.c b/src/invoker/invokelib.c index 9d01187..6f1173b 100644 --- a/src/invoker/invokelib.c +++ b/src/invoker/invokelib.c @@ -32,10 +32,30 @@ void invoke_send_msg(int fd, uint32_t msg) write(fd, &msg, sizeof(msg)); } -void invoke_recv_msg(int fd, uint32_t *msg) +bool invoke_recv_msg(int fd, uint32_t *msg) { - read(fd, msg, sizeof(*msg)); - debug("%s: %08x\n", __FUNCTION__, *msg); + ssize_t numRead; + uint32_t readBuf; + numRead = read(fd, &readBuf, sizeof(readBuf)); + + if (numRead == -1) + { + debug("%s: Error reading message: %s\n", __FUNCTION__, strerror(errno)); + *msg = 0; + return false; + } + else if (numRead == 0) + { + debug("%s: Error: unexpected end-of-file \n", __FUNCTION__); + *msg = 0; + return false; + } + else + { + debug("%s: %08x\n", __FUNCTION__, readBuf); + *msg = readBuf; + return true; + } } void invoke_send_str(int fd, char *str) diff --git a/src/invoker/invokelib.h b/src/invoker/invokelib.h index 7719510..5af9584 100644 --- a/src/invoker/invokelib.h +++ b/src/invoker/invokelib.h @@ -20,11 +20,10 @@ #ifndef INVOKELIB_H #define INVOKELIB_H -#include #include void invoke_send_msg(int fd, uint32_t msg); -void invoke_recv_msg(int fd, uint32_t *msg); +bool invoke_recv_msg(int fd, uint32_t *msg); void invoke_send_str(int fd, char *str);