From: Ian Jackson Date: Wed, 1 Oct 2014 17:02:19 +0000 (+0100) Subject: util: Break out pollbadbit() X-Git-Tag: base.ipv6-polypath-fixes.v1~26 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=commitdiff_plain;h=ae5ae3bf5c5709938e3a2bb6203094ede8af45e6 util: Break out pollbadbit() Signed-off-by: Ian Jackson --- diff --git a/util.c b/util.c index 0215f25..c459f13 100644 --- a/util.c +++ b/util.c @@ -613,6 +613,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); + /* POLLNVAL is handled by the event loop - see afterpoll_fn comment */ +#undef BADBIT + return 0; +} + enum async_linebuf_result async_linebuf_read(struct pollfd *pfd, struct buffer_if *buf, const char **emsg_out) @@ -620,12 +631,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); - /* POLLNVAL is handled by the event loop - see afterpoll_fn comment */ -#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 3549eb0..63ceef6 100644 --- a/util.h +++ b/util.h @@ -98,6 +98,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);