aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcoopgamma.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-08-04 21:22:20 +0200
committerMattias Andrée <maandree@kth.se>2016-08-04 21:22:24 +0200
commitff458f3fc2382bba3ffcda62676b9fce1895654a (patch)
tree131c91ee8942207261ae04ffd8991c504b0b10e5 /src/libcoopgamma.c
parentlibcoopgamma_synchronise allows 0 calls to synchronise (diff)
downloadlibcoopgamma-ff458f3fc2382bba3ffcda62676b9fce1895654a.tar.gz
libcoopgamma-ff458f3fc2382bba3ffcda62676b9fce1895654a.tar.bz2
libcoopgamma-ff458f3fc2382bba3ffcda62676b9fce1895654a.tar.xz
Fix bugs (and a tiny improvement)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/libcoopgamma.c8
1 files 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);
}