Пример #1
0
int CFileBuffer::insert(int size, const BYTE*buf)
{
retry:
	cs.Lock();

	if (no_more_remove)
	{
		cs.Unlock();
		return 0;
	}

	if (size + m_data_size > m_buffer_size)
	{
		cs.Unlock();		// wait for enough space
		Sleep(10);
		goto retry;
	}

	//memcpy(m_the_buffer+m_data_size, buf, size);
	mPut(buf, size, m_data_start + m_data_size);

	m_data_size += size;

	cs.Unlock();
	return 0;
}
Пример #2
0
int CFileBuffer::insert(int size, const BYTE*buf, int time_out /* = INFINITE */)
{
	int time = GetTickCount();
retry:
	if (time_out != INFINITE && GetTickCount() - time > time_out)
		return -1;

	cs.Lock();

	if (no_more_remove)
	{
		cs.Unlock();
		return 0;
	}

	if (size + m_data_size > m_buffer_size)
	{
		cs.Unlock();		// wait for enough space
		Sleep(1);
		goto retry;
	}

	//memcpy(m_the_buffer+m_data_size, buf, size);
	mPut(buf, size, m_data_start + m_data_size);

	m_data_size += size;

	cs.Unlock();
	return 0;
}
Пример #3
0
void CFileBuffer::resort()
{
	unsigned char * tmp = (unsigned char*) malloc(m_data_size);
	mGet(tmp, m_data_size, m_data_start);
	mPut(tmp, m_data_size, 0);
	m_data_start = 0;
	free(tmp);
}