From ff458f3fc2382bba3ffcda62676b9fce1895654a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 4 Aug 2016 21:22:20 +0200 Subject: Fix bugs (and a tiny improvement) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libcoopgamma.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcoopgamma.c b/src/libcoopgamma.c index 0314500..fbdef21 100644 --- a/src/libcoopgamma.c +++ b/src/libcoopgamma.c @@ -1523,14 +1523,15 @@ int libcoopgamma_synchronise(libcoopgamma_context_t* restrict ctx, if (ctx->inbound_head == ctx->inbound_tail) ctx->inbound_head = ctx->inbound_tail = ctx->curline = 0; - - if (ctx->inbound_tail > 0) + else if (ctx->inbound_tail > 0) { memmove(ctx->inbound, ctx->inbound + ctx->inbound_tail, ctx->inbound_head -= ctx->inbound_tail); ctx->curline -= ctx->inbound_tail; ctx->inbound_tail = 0; } + if (ctx->inbound_head) + goto skip_recv; for (;;) { if (ctx->inbound_head == ctx->inbound_size) @@ -1552,6 +1553,7 @@ int libcoopgamma_synchronise(libcoopgamma_context_t* restrict ctx, } ctx->inbound_head += (size_t)got; + skip_recv: while (ctx->have_all_headers == 0) { line = ctx->inbound + ctx->curline; @@ -1686,9 +1688,9 @@ static int send_message(libcoopgamma_context_t* restrict ctx, char* msg, size_t } memcpy(ctx->outbound + ctx->outbound_head, msg, n); ctx->outbound_head += n; - ctx->message_id += 1; free(msg); } + ctx->message_id += 1; return libcoopgamma_flush(ctx); } -- cgit v1.2.3-70-g09d2