The old code assumed anything not Z_OK was a failure. However the zlib.h
header says:

   Return codes for the compression/decompression functions. Negative values
   are errors, positive values are used for special but normal events.

As a result mbsync reports and error when we receive Z_STREAM_END which
is simply the correct result for the end of the stream. This changes the
exit path so we handle any final bytes before closing the socket and
returning.

Signed-off-by: Alex Bennée <[email protected]>
---
 src/socket.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/socket.c b/src/socket.c
index 56e041a..f324824 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -598,6 +598,8 @@ socket_fill_z( conn_t *sock )
 {
        char *buf;
        int len;
+       int r;
+       int close = 0;
 
        if (prepare_read( sock, &buf, &len ) < 0)
                return;
@@ -605,10 +607,14 @@ socket_fill_z( conn_t *sock )
        sock->in_z->avail_out = len;
        sock->in_z->next_out = (unsigned char *)buf;
 
-       if (inflate( sock->in_z, Z_SYNC_FLUSH ) != Z_OK) {
-               error( "Error decompressing data from %s: %s\n", sock->name, 
sock->in_z->msg );
+       r = inflate( sock->in_z, Z_SYNC_FLUSH );
+       if (r < 0) {
+               error( "Error decompressing data from %s: %s (%d)\n", 
sock->name, sock->in_z->msg, r );
                socket_fail( sock );
                return;
+       } else if (r > 0) {
+               info( "Reached end of data (%d)\n", r);
+               close = 1;
        }
 
        if (!sock->in_z->avail_out)
@@ -618,6 +624,10 @@ socket_fill_z( conn_t *sock )
                sock->bytes += len;
                sock->read_callback( sock->callback_aux );
        }
+
+       if (close) {
+               socket_close( sock );
+       }
 }
 #endif
 
-- 
2.2.2


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to