From: Marko Kreen Date: Thu, 14 Feb 2008 14:35:52 +0000 (+0000) Subject: convert SBuf api also to unsigned int X-Git-Tag: pgbouncer_1_2_rc2~36 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=008620e2b3aec3617ac767afe446e5ff2b20a69a;p=pgbouncer convert SBuf api also to unsigned int --- diff --git a/include/sbuf.h b/include/sbuf.h index eaa7e2c..e3482d1 100644 --- a/include/sbuf.h +++ b/include/sbuf.h @@ -68,7 +68,7 @@ struct SBuf { int sock; /* fd for this socket */ - int pkt_remain; /* total packet length remaining */ + unsigned pkt_remain; /* total packet length remaining */ sbuf_cb_t proto_cb; /* protocol callback */ void *proto_cb_arg; /* extra arg to callback */ @@ -89,11 +89,11 @@ void sbuf_continue(SBuf *sbuf); bool sbuf_close(SBuf *sbuf) _MUSTCHECK; /* proto_fn can use those functions to order behaviour */ -void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, int amount); -void sbuf_prepare_skip(SBuf *sbuf, int amount); -void sbuf_prepare_fetch(SBuf *sbuf, int amount); +void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, unsigned amount); +void sbuf_prepare_skip(SBuf *sbuf, unsigned amount); +void sbuf_prepare_fetch(SBuf *sbuf, unsigned amount); -bool sbuf_answer(SBuf *sbuf, const void *buf, int len) _MUSTCHECK; +bool sbuf_answer(SBuf *sbuf, const void *buf, unsigned len) _MUSTCHECK; bool sbuf_continue_with_callback(SBuf *sbuf, sbuf_libevent_cb cb) _MUSTCHECK; diff --git a/src/sbuf.c b/src/sbuf.c index 368de46..d176185 100644 --- a/src/sbuf.c +++ b/src/sbuf.c @@ -38,7 +38,6 @@ #define AssertSanity(sbuf) do { \ Assert(iobuf_sane((sbuf)->io)); \ - Assert((sbuf)->pkt_remain >= 0); \ } while (0) #define AssertActive(sbuf) do { \ @@ -261,7 +260,7 @@ bool sbuf_close(SBuf *sbuf) } /* proto_fn tells to send some bytes to socket */ -void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, int amount) +void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, unsigned amount) { AssertActive(sbuf); Assert(sbuf->pkt_remain == 0); @@ -274,7 +273,7 @@ void sbuf_prepare_send(SBuf *sbuf, SBuf *dst, int amount) } /* proto_fn tells to skip some amount of bytes */ -void sbuf_prepare_skip(SBuf *sbuf, int amount) +void sbuf_prepare_skip(SBuf *sbuf, unsigned amount) { AssertActive(sbuf); Assert(sbuf->pkt_remain == 0); @@ -286,7 +285,7 @@ void sbuf_prepare_skip(SBuf *sbuf, int amount) } /* proto_fn tells to skip some amount of bytes */ -void sbuf_prepare_fetch(SBuf *sbuf, int amount) +void sbuf_prepare_fetch(SBuf *sbuf, unsigned amount) { AssertActive(sbuf); Assert(sbuf->pkt_remain == 0); @@ -451,7 +450,7 @@ try_more: /* process as much data as possible */ static bool sbuf_process_pending(SBuf *sbuf) { - int avail; + unsigned avail; IOBuf *io = sbuf->io; bool full = iobuf_amount_recv(io) <= 0; bool res; @@ -586,7 +585,7 @@ static bool allocate_iobuf(SBuf *sbuf) */ static void sbuf_main_loop(SBuf *sbuf, bool skip_recv) { - int free, ok; + unsigned free, ok; /* sbuf was closed before in this event loop */ if (!sbuf->sock) @@ -686,16 +685,16 @@ failed: } /* send some data to listening socket */ -bool sbuf_answer(SBuf *sbuf, const void *buf, int len) +bool sbuf_answer(SBuf *sbuf, const void *buf, unsigned len) { int res; if (sbuf->sock <= 0) return false; res = safe_send(sbuf->sock, buf, len, 0); - if (res < 0) + if (res < 0) { log_debug("sbuf_answer: error sending: %s", strerror(errno)); - else if (res != len) + } else if ((unsigned)res != len) log_debug("sbuf_answer: partial send: len=%d sent=%d", len, res); - return res == len; + return (unsigned)res == len; }