void TZlibTransport::write(const uint8_t* buf, uint32_t len) { // zlib's "deflate" function has enough logic in it that I think // we're better off (performance-wise) buffering up small writes. if ((int)len > MIN_DIRECT_DEFLATE_SIZE) { flushToZlib(uwbuf_, uwpos_); uwpos_ = 0; flushToZlib(buf, len); } else if (len > 0) { if (uwbuf_size_ - uwpos_ < (int)len) { flushToZlib(uwbuf_, uwpos_); uwpos_ = 0; } memcpy(uwbuf_ + uwpos_, buf, len); uwpos_ += len; } }
void TZlibTransport::write(const uint8_t* buf, uint32_t len) { if (output_finished_) { throw TTransportException(TTransportException::BAD_ARGS, "write() called after finish()"); } // zlib's "deflate" function has enough logic in it that I think // we're better off (performance-wise) buffering up small writes. if (len > MIN_DIRECT_DEFLATE_SIZE) { flushToZlib(uwbuf_, uwpos_, Z_NO_FLUSH); uwpos_ = 0; flushToZlib(buf, len, Z_NO_FLUSH); } else if (len > 0) { if (uwbuf_size_ - uwpos_ < len) { flushToZlib(uwbuf_, uwpos_, Z_NO_FLUSH); uwpos_ = 0; } memcpy(uwbuf_ + uwpos_, buf, len); uwpos_ += len; } }
void TZlibTransport::flushToTransport(int flush) { // write pending data in uwbuf_ to zlib flushToZlib(uwbuf_, uwpos_, flush); uwpos_ = 0; // write all available data from zlib to the transport transport_->write(cwbuf_, cwbuf_size_ - wstream_->avail_out); wstream_->next_out = cwbuf_; wstream_->avail_out = cwbuf_size_; // flush the transport transport_->flush(); }
void TZlibTransport::flush() { flushToZlib(uwbuf_, uwpos_, true); assert((int)wstream_->avail_out != cwbuf_size_); transport_->write(cwbuf_, cwbuf_size_ - wstream_->avail_out); transport_->flush(); }