chiark
/
gitweb
/
~mdw
/
secnet
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
polypath: Provide polypath comm module
[secnet]
/
util.c
diff --git
a/util.c
b/util.c
index 0f24282e772d17904092e5c5c7c9d1d465284fea..c459f1340a6d406caf528eebf2f777e173ed3a76 100644
(file)
--- a/
util.c
+++ b/
util.c
@@
-291,6
+291,14
@@
void buffer_init(struct buffer_if *buffer, int32_t max_start_pad)
buffer->size=0;
}
buffer->size=0;
}
+void buffer_destroy(struct buffer_if *buf)
+{
+ BUF_ASSERT_FREE(buf);
+ free(buf->base);
+ buf->start=buf->base=0;
+ buf->size=buf->alloclen=0;
+}
+
void *buf_append(struct buffer_if *buf, int32_t amount) {
void *p;
assert(amount <= buf_remaining_space(buf));
void *buf_append(struct buffer_if *buf, int32_t amount) {
void *p;
assert(amount <= buf_remaining_space(buf));
@@
-605,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)
enum async_linebuf_result
async_linebuf_read(struct pollfd *pfd, struct buffer_if *buf,
const char **emsg_out)
@@
-612,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)
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;
if (!(revents & POLLIN))
return async_linebuf_nothing;