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 */
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;
#define AssertSanity(sbuf) do { \
Assert(iobuf_sane((sbuf)->io)); \
- Assert((sbuf)->pkt_remain >= 0); \
} while (0)
#define AssertActive(sbuf) do { \
}
/* 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);
}
/* 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);
}
/* 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);
/* 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;
*/
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)
}
/* 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;
}