From cdf84dd2b32e30af648420dd10d519a93046b693 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 1 Oct 2014 18:02:19 +0100 Subject: [PATCH] util: Break out pollbadbit() Signed-off-by: Ian Jackson --- util.c | 20 ++++++++++++++------ util.h | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/util.c b/util.c index 240155a..b2cd0e8 100644 --- a/util.c +++ b/util.c @@ -611,6 +611,17 @@ int iaddr_socklen(const union iaddr *ia) } } +const char *pollbadbit(int revents) +{ +#define BADBIT(b) \ + if ((revents & b)) return #b + BADBIT(POLLERR); + BADBIT(POLLHUP); + BADBIT(POLLNVAL); +#undef BADBIT + return 0; +} + enum async_linebuf_result async_linebuf_read(struct pollfd *pfd, struct buffer_if *buf, const char **emsg_out) @@ -618,12 +629,9 @@ async_linebuf_read(struct pollfd *pfd, struct buffer_if *buf, int revents=pfd->revents; #define BAD(m) do{ *emsg_out=(m); return async_linebuf_broken; }while(0) -#define BADBIT(b) \ - if (!(revents & b)) ; else BAD(#b) - BADBIT(POLLERR); - BADBIT(POLLHUP); - BADBIT(POLLNVAL); -#undef BADBIT + + const char *badbit=pollbadbit(revents); + if (badbit) BAD(badbit); if (!(revents & POLLIN)) return async_linebuf_nothing; diff --git a/util.h b/util.h index e1dc69f..82ed822 100644 --- a/util.h +++ b/util.h @@ -99,6 +99,8 @@ enum async_linebuf_result { async_linebuf_broken, }; +const char *pollbadbit(int revents); /* returns 0, or bad bit description */ + enum async_linebuf_result async_linebuf_read(struct pollfd *pfd, struct buffer_if *buf, const char **emsg_out); -- 2.30.2