static TACommandVerdict deflateCopy_cmd(TAThread thread,TAInputStream stream) { z_stream source, dest; int res, is_null_source, is_null_dest; is_null_dest = readZStream(&stream, &dest); is_null_source = readZStream(&stream, &source); /*ta_debug_printf( "next_in==%d\navail_in==%u\ntotal_in==%lu\nnext_out==%d\n" "avail_out==%u\ntotal_out==%lu\n", strm.next_in, strm.avail_in, strm.total_in, strm.next_out, strm.avail_out,strm.total_out); ta_debug_printf( "msg==%s\nstate==%d\nzalloc==%d\nzfree==%d\n" "opaque==%d\ndata_type==%d\nadler==%lu\nreserved==%lu\n", strm.msg, strm.state, strm.zalloc, strm.zfree, strm.opaque, strm.data_type, strm.adler, strm.reserved);*/ START_TARGET_OPERATION(thread); if(!is_null_dest) { if(!is_null_source) { res = deflateCopy(&dest, &source); } else { res = deflateCopy(&dest, 0); } } else { if(!is_null_source) { res = deflateCopy(0, &source); } else { res = deflateCopy(0, 0); } } END_TARGET_OPERATION(thread); // Response if(!is_null_dest) writeZStream(thread, &dest); else writeZStream(thread, 0); writeInt(thread, res); sendResponse(thread); return taDefaultVerdict; }
GzipHeaderCodec::GzipHeaderCodec(int compressionLevel, const SPDYVersionSettings& versionSettings) : versionSettings_(versionSettings) { // Create compression and decompression contexts by cloning thread-local // copies of the initial SPDY compression state auto context = getZlibContext(versionSettings, compressionLevel); deflateCopy(&deflater_, const_cast<z_stream*>(&(context->deflater))); inflateCopy(&inflater_, const_cast<z_stream*>(&(context->inflater))); }
static PyObject * PyZlib_copy(compobject *self) { compobject *retval = NULL; int err; retval = newcompobject(&Comptype); if (!retval) return NULL; /* Copy the zstream state * We use ENTER_ZLIB / LEAVE_ZLIB to make this thread-safe */ ENTER_ZLIB(self); err = deflateCopy(&retval->zst, &self->zst); switch(err) { case(Z_OK): break; case(Z_STREAM_ERROR): PyErr_SetString(PyExc_ValueError, "Inconsistent stream state"); goto error; case(Z_MEM_ERROR): PyErr_SetString(PyExc_MemoryError, "Can't allocate memory for compression object"); goto error; default: zlib_error(self->zst, err, "while copying compression object"); goto error; } Py_INCREF(self->unused_data); Py_INCREF(self->unconsumed_tail); Py_XDECREF(retval->unused_data); Py_XDECREF(retval->unconsumed_tail); retval->unused_data = self->unused_data; retval->unconsumed_tail = self->unconsumed_tail; retval->eof = self->eof; /* Mark it as being initialized */ retval->is_initialised = 1; LEAVE_ZLIB(self); return (PyObject *)retval; error: LEAVE_ZLIB(self); Py_XDECREF(retval); return NULL; }