summaryrefslogtreecommitdiffstats
path: root/client/zlib_decoder.cpp
diff options
context:
space:
mode:
authorYonit Halperin <yhalperi@redhat.com>2010-06-20 15:24:49 +0300
committerAlexander Larsson <alexl@redhat.com>2010-06-21 15:05:37 +0200
commit25bb38f643af6f0015df369a22176275b6ebfae0 (patch)
tree5bfc75812c6ba89086d1ab8782552de806fd53bb /client/zlib_decoder.cpp
parentcfc1e95bda0e150b3de225c3572bb1004dad070e (diff)
downloadspice-25bb38f643af6f0015df369a22176275b6ebfae0.tar.gz
spice-25bb38f643af6f0015df369a22176275b6ebfae0.tar.xz
spice-25bb38f643af6f0015df369a22176275b6ebfae0.zip
applying zlib compression over glz on WAN connection
Diffstat (limited to 'client/zlib_decoder.cpp')
-rw-r--r--client/zlib_decoder.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/client/zlib_decoder.cpp b/client/zlib_decoder.cpp
new file mode 100644
index 00000000..68b1b339
--- /dev/null
+++ b/client/zlib_decoder.cpp
@@ -0,0 +1,58 @@
+#include "common.h"
+#include "zlib_decoder.h"
+#include "debug.h"
+#include "utils.h"
+
+static void op_decode(SpiceZlibDecoder *decoder,
+ uint8_t *data,
+ int data_size,
+ uint8_t *dest,
+ int dest_size)
+{
+ ZlibDecoder* _decoder = static_cast<ZlibDecoder*>(decoder);
+ _decoder->decode(data, data_size, dest, dest_size);
+}
+
+ZlibDecoder::ZlibDecoder()
+{
+ int z_ret;
+
+ _z_strm.zalloc = Z_NULL;
+ _z_strm.zfree = Z_NULL;
+ _z_strm.opaque = Z_NULL;
+ _z_strm.next_in = Z_NULL;
+ _z_strm.avail_in = 0;
+ z_ret = inflateInit(&_z_strm);
+ if (z_ret != Z_OK) {
+ THROW("zlib decoder init failed, error %d", z_ret);
+ }
+
+ static SpiceZlibDecoderOps decoder_ops = {
+ op_decode,
+ };
+
+ ops = &decoder_ops;
+}
+
+ZlibDecoder::~ZlibDecoder()
+{
+ inflateEnd(&_z_strm);
+}
+
+
+void ZlibDecoder::decode(uint8_t *data, int data_size, uint8_t *dest, int dest_size)
+{
+ int z_ret;
+
+ inflateReset(&_z_strm);
+ _z_strm.next_in = data;
+ _z_strm.avail_in = data_size;
+ _z_strm.next_out = dest;
+ _z_strm.avail_out = dest_size;
+
+ z_ret = inflate(&_z_strm, Z_FINISH);
+
+ if (z_ret != Z_STREAM_END) {
+ THROW("zlib inflate failed, error %d", z_ret);
+ }
+}