// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} #include "ConnectionLayout.h" #include "UdtSocket.h" #include "DataRemote.h" #include #include "communication.h" #include #include #define COMPRESS_CHUNK 1024 ConnectionLayout::ConnectionLayout(UdtSocket *socket, QString name) : Layout(NULL, name, "root") { isRemoteNameDefined = false; this->socket = socket; } ConnectionLayout::~ConnectionLayout() {} void ConnectionLayout::receive(char *buf, int size) { // printf("trame %x\n",buf[0]); // for(int i=0; iBufEvent(&buf, &buf_size, period, big_endian); } } int ConnectionLayout::uncompressBuffer(char *in, ssize_t in_size, char **out, ssize_t *out_size) { int ret; unsigned have; z_stream strm; // allocate inflate state strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit(&strm); if (ret != Z_OK) return ret; *out = (char *)malloc(COMPRESS_CHUNK); if (!(*out)) return Z_BUF_ERROR; strm.avail_in = in_size; strm.next_in = (unsigned char *)in; strm.avail_out = COMPRESS_CHUNK; strm.next_out = (unsigned char *)*out; ret = inflate(&strm, Z_NO_FLUSH); assert(ret != Z_STREAM_ERROR); // state not clobbered switch (ret) { case Z_NEED_DICT: ret = Z_DATA_ERROR; // and fall through case Z_DATA_ERROR: case Z_MEM_ERROR: (void)inflateEnd(&strm); return ret; } have = COMPRESS_CHUNK - strm.avail_out; *out_size = have; // printf("%i -> %i\n",in_size,have); // printf("%s\n",*out); // clean up and return (void)inflateEnd(&strm); return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; }