diff options
Diffstat (limited to 'libglouglou/sendbuf.c')
-rw-r--r-- | libglouglou/sendbuf.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libglouglou/sendbuf.c b/libglouglou/sendbuf.c index 7571cc4..15a7d23 100644 --- a/libglouglou/sendbuf.c +++ b/libglouglou/sendbuf.c @@ -101,15 +101,19 @@ sendbuf_gettoken(struct sendbuf *sbuf, int size) /* * Note that you can still add data to the buffer even if flushing is in * progress + * returns 0 on success or -1 on error */ static int flushbuf(struct sendbuf *sbuf) { int tosend, sent; + if (sbuf->buffer_pos == 0) + return 0; + sbuf->flushing = 1; - tosend = sbuf->buffer_size - sbuf->flushing_pos; + tosend = sbuf->buffer_pos - sbuf->flushing_pos; sent = sbuf->send_func(sbuf->buffer + sbuf->flushing_pos, tosend, sbuf->usrdata); if (sent == -1) { @@ -119,6 +123,7 @@ flushbuf(struct sendbuf *sbuf) sbuf->flushing_pos = sbuf->flushing_pos + sent; return -1; } + sbuf->buffer_pos = 0; sbuf->flushing = 0; sbuf->flushing_pos = 0; |