void FileBundlePackImport::CloseNoUpdate() {
  FlushWriteBuffer();
  khLockGuard lock(modify_lock());
  while (!SegmentsEmpty()) {
    FileBundleSegment *close_seg = PopBackSegment();
    delete close_seg;
  }
}
Example #2
0
void CDeflateCompressor::FinishCompression(bool bAfterException)
{
	m_stream.avail_in = 0;
	if (!bAfterException)
	{
		if (m_pFile->m_uMethod == methodDeflate)
		{
			int err;
			do
			{
				if (m_stream.avail_out == 0)
				{
					FlushWriteBuffer();
					m_stream.avail_out = m_pBuffer.GetSize();
					m_stream.next_out = (zarch_Bytef*)(char*)m_pBuffer;
				}
				ZIP_SIZE_TYPE uTotal = m_stream.total_out;
				err = zarch_deflate(&m_stream,  Z_FINISH);
				m_uComprLeft += m_stream.total_out - uTotal;
			}
			while (err == Z_OK);
			
			if (err == Z_STREAM_END)
				err = Z_OK;
			CheckForError(err);

			if (m_uComprLeft > 0)
				FlushWriteBuffer();

			CheckForError(zarch_deflateEnd(&m_stream));
		}
		
		// it may be increased by the encrypted header size in CZipFileHeader::PrepareData
		m_pFile->m_uComprSize += m_stream.total_out;
		m_pFile->m_uUncomprSize = m_stream.total_in;
	}
	EmptyPtrList();
	ReleaseBuffer();
}
Example #3
0
void CDeflateCompressor::Compress(const void *pBuffer, DWORD uSize)
{ 	
	UpdateFileCrc(pBuffer, uSize);
	
	if (m_pFile->m_uMethod == methodDeflate)
	{
		m_stream.next_in = (zarch_Bytef*)pBuffer;
		m_stream.avail_in = uSize;
		
		while (m_stream.avail_in > 0)
		{
			if (m_stream.avail_out == 0)
			{
				FlushWriteBuffer();
				m_stream.avail_out = m_pBuffer.GetSize();
				m_stream.next_out = (zarch_Bytef*)(char*)m_pBuffer;
			}
			
			ZIP_ZLIB_TYPE uTotal = m_stream.total_out;
			CheckForError(zarch_deflate(&m_stream,  Z_NO_FLUSH));
			m_uComprLeft += m_stream.total_out - uTotal;
		}
	}
	else if (uSize > 0)
	{
		if (m_pCryptograph)
		{
			if (m_pBuffer.GetSize() < uSize)
			{
				m_pBuffer.Allocate(uSize);
			}
			memcpy(m_pBuffer, pBuffer, uSize);
			WriteBuffer(m_pBuffer, uSize);
		}
		else
			m_pStorage->Write(pBuffer, uSize, false);		
		m_stream.total_in += uSize;
		m_stream.total_out += uSize;		
	}
}
Example #4
0
/*----------------------------------------------------------------------------*/
static inline char *
GetWriteBuffer(struct mtcp_thread_context *ctx, int method, int ifidx, int len)
{
	struct ps_chunk *w_chunk = ctx->w_chunk;
	uint32_t *w_off = ctx->w_off;
	int w_idx;

	assert(w_chunk != NULL);
	assert(w_off != NULL);
	
	if (ifidx < 0 || ifidx >= g_config.mos->netdev_table->num )
		return NULL;

	//pthread_mutex_lock(&ctx->send_lock);

	if (ctx->w_cur_idx[ifidx] + w_chunk[ifidx].cnt >= MAX_SEND_PCK_CHUNK) {
		if (method == BUF_RET_MAYBE) {
			return NULL;
		} else if (method == BUF_RET_ALWAYS) {
			if (FlushWriteBuffer(ctx, ifidx) <= 0)
				return NULL;
		} else {
			assert(0);
		}
	}

	assert(ctx->w_cur_idx[ifidx] + w_chunk[ifidx].cnt < MAX_SEND_PCK_CHUNK);
	assert(w_off[ifidx] < MAX_PACKET_SIZE * MAX_CHUNK_SIZE);

	w_idx = w_chunk[ifidx].cnt++;
	w_chunk[ifidx].info[w_idx].len = len;
	w_chunk[ifidx].info[w_idx].offset = w_off[ifidx];
	w_off[ifidx] += (len + 63) / 64 * 64;

	//pthread_mutex_unlock(&ctx->send_lock);

	return (w_chunk[ifidx].buf + w_chunk[ifidx].info[w_idx].offset);
}
Example #5
0
bool SocketManager<B>::BufferWriteBytes(B &pkt_buf, size_t len, uchar type) {
  size_t window, pkt_buf_ptr = 0;
  int len_nb;  // length in network byte order

  // check if we don't have enough space in the buffer
  if (wbuf.GetMaxSize() - wbuf.buf_ptr < 1 + sizeof(int32_t)) {
    // buffer needs to be flushed before adding header
    FlushWriteBuffer();
  }

  // assuming wbuf is now large enough to
  // fit type and size fields in one go
  if (type != 0) {
    // type shouldn't be ignored
    wbuf.buf[wbuf.buf_ptr++] = type;
  }

  // make len include its field size as well
  len_nb = htonl(len + sizeof(int32_t));

  // append the bytes of this integer in network-byte order
  std::copy(reinterpret_cast<uchar *>(&len_nb),
            reinterpret_cast<uchar *>(&len_nb) + 4,
            std::begin(wbuf.buf) + wbuf.buf_ptr);

  // move the write buffer pointer and update size of the socket buffer
  wbuf.buf_ptr += sizeof(int32_t);
  wbuf.buf_size = wbuf.buf_ptr;

  // fill the contents
  while (len) {
    window = wbuf.GetMaxSize() - wbuf.buf_ptr;
    if (len <= window) {
      // contents fit in the window, range copy "len" bytes
      std::copy(std::begin(pkt_buf) + pkt_buf_ptr,
                std::begin(pkt_buf) + pkt_buf_ptr + len,
                std::begin(wbuf.buf) + wbuf.buf_ptr);

      // Move the cursor and update size of socket buffer
      wbuf.buf_ptr += len;
      wbuf.buf_size = wbuf.buf_ptr;
      return true;
    } else {
      /* contents longer than socket buffer size, fill up the socket buffer
       *  with "window" bytes
       */
      std::copy(std::begin(pkt_buf) + pkt_buf_ptr,
                std::begin(pkt_buf) + pkt_buf_ptr + window,
                std::begin(wbuf.buf) + wbuf.buf_ptr);

      // move the packet's cursor
      pkt_buf_ptr += window;
      len -= window;

      wbuf.buf_size = wbuf.GetMaxSize();
      // write failure
      if (!FlushWriteBuffer()) return false;
    }
  }
  return true;
}
void FileBundleWriter::Checkpoint() {
  FlushWriteBuffer();
  SaveHeaderFileWithLock();
}
void geFilePool::Writer::Pread(void *buffer, size_t size, off64_t offset)
{
  FlushWriteBuffer();
  fileref->Pread(buffer, size, offset);
}
void geFilePool::Writer::SyncAndClose(void) {
  FlushWriteBuffer();
  fileref->Close();
}