From 5605c48f28f847152f1f2b38cba1d580e7058b3c Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Thu, 14 Feb 2008 14:02:05 +0000 Subject: [PATCH] make IOBuf use unsigned ints --- include/iobuf.h | 38 +++++++++++++++++++------------------- src/sbuf.c | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/iobuf.h b/include/iobuf.h index 42574b3..2fc0e45 100644 --- a/include/iobuf.h +++ b/include/iobuf.h @@ -47,19 +47,19 @@ extern int cf_sbuf_len; * parse_pos .. recv_pos -- received, to parse */ struct iobuf { - int done_pos; - int parse_pos; - int recv_pos; + unsigned done_pos; + unsigned parse_pos; + unsigned recv_pos; uint8_t buf[FLEX_ARRAY]; }; typedef struct iobuf IOBuf; static inline bool iobuf_sane(const IOBuf *io) { - return (io == NULL) || (io->done_pos >= 0 - && io->parse_pos >= io->done_pos + return (io == NULL) || + ( io->parse_pos >= io->done_pos && io->recv_pos >= io->parse_pos - && cf_sbuf_len >= io->recv_pos); + && (unsigned)cf_sbuf_len >= io->recv_pos); } static inline bool iobuf_empty(const IOBuf *io) @@ -68,36 +68,36 @@ static inline bool iobuf_empty(const IOBuf *io) } /* unsent amount */ -static inline int iobuf_amount_pending(const IOBuf *buf) +static inline unsigned iobuf_amount_pending(const IOBuf *buf) { return buf->parse_pos - buf->done_pos; } /* max possible to parse (tag_send/tag_skip) */ -static inline int iobuf_amount_parse(const IOBuf *buf) +static inline unsigned iobuf_amount_parse(const IOBuf *buf) { return buf->recv_pos - buf->parse_pos; } /* max possible to recv */ -static inline int iobuf_amount_recv(const IOBuf *buf) +static inline unsigned iobuf_amount_recv(const IOBuf *buf) { return cf_sbuf_len - buf->recv_pos; } /* put all unparsed to mbuf */ -static inline int iobuf_parse_all(const IOBuf *buf, MBuf *mbuf) +static inline unsigned iobuf_parse_all(const IOBuf *buf, MBuf *mbuf) { - int avail = iobuf_amount_parse(buf); + unsigned avail = iobuf_amount_parse(buf); const uint8_t *pos = buf->buf + buf->parse_pos; mbuf_init(mbuf, pos, avail); return avail; } /* put all unparsed to mbuf, with size limit */ -static inline int iobuf_parse_limit(const IOBuf *buf, MBuf *mbuf, int limit) +static inline unsigned iobuf_parse_limit(const IOBuf *buf, MBuf *mbuf, unsigned limit) { - int avail = iobuf_amount_parse(buf); + unsigned avail = iobuf_amount_parse(buf); const uint8_t *pos = buf->buf + buf->parse_pos; if (avail > limit) avail = limit; @@ -106,11 +106,11 @@ static inline int iobuf_parse_limit(const IOBuf *buf, MBuf *mbuf, int limit) } /* recv */ -static inline int _MUSTCHECK iobuf_recv_limit(IOBuf *io, int fd, int len) +static inline int _MUSTCHECK iobuf_recv_limit(IOBuf *io, int fd, unsigned len) { uint8_t *pos = io->buf + io->recv_pos; int got; - int avail = iobuf_amount_recv(io); + unsigned avail = iobuf_amount_recv(io); if (len > avail) len = avail; @@ -143,14 +143,14 @@ static inline int _MUSTCHECK iobuf_send_pending(IOBuf *io, int fd) return res; } -static inline void iobuf_tag_send(IOBuf *io, int len) +static inline void iobuf_tag_send(IOBuf *io, unsigned len) { Assert(len > 0 && len <= iobuf_amount_parse(io)); io->parse_pos += len; } -static inline void iobuf_tag_skip(IOBuf *io, int len) +static inline void iobuf_tag_skip(IOBuf *io, unsigned len) { Assert(io->parse_pos == io->done_pos); /* no send pending */ Assert(len > 0 && len <= iobuf_amount_parse(io)); @@ -159,9 +159,9 @@ static inline void iobuf_tag_skip(IOBuf *io, int len) io->done_pos = io->parse_pos; } -static inline void iobuf_try_resync(IOBuf *io, int small_pkt) +static inline void iobuf_try_resync(IOBuf *io, unsigned small_pkt) { - int avail = io->recv_pos - io->done_pos; + unsigned avail = io->recv_pos - io->done_pos; if (avail == 0) { if (io->recv_pos > 0) io->recv_pos = io->parse_pos = io->done_pos = 0; diff --git a/src/sbuf.c b/src/sbuf.c index f97cffa..368de46 100644 --- a/src/sbuf.c +++ b/src/sbuf.c @@ -57,7 +57,7 @@ static void sbuf_try_resync(SBuf *sbuf, bool release); static bool sbuf_wait_for_data(SBuf *sbuf) _MUSTCHECK; static void sbuf_main_loop(SBuf *sbuf, bool skip_recv); static bool sbuf_call_proto(SBuf *sbuf, int event) /* _MUSTCHECK */; -static bool sbuf_actual_recv(SBuf *sbuf, int len) _MUSTCHECK; +static bool sbuf_actual_recv(SBuf *sbuf, unsigned len) _MUSTCHECK; static bool sbuf_after_connect_check(SBuf *sbuf) _MUSTCHECK; static inline IOBuf *get_iobuf(SBuf *sbuf) { return sbuf->io; } @@ -533,7 +533,7 @@ static void sbuf_try_resync(SBuf *sbuf, bool release) } /* actually ask kernel for more data */ -static bool sbuf_actual_recv(SBuf *sbuf, int len) +static bool sbuf_actual_recv(SBuf *sbuf, unsigned len) { int got; IOBuf *io = sbuf->io; -- 2.40.0