コード例 #1
0
ファイル: BlobBuffer.cpp プロジェクト: ming-hai/soui
void BlobBuffer::AppendBlobContentChar(const unsigned char BlobChar)
{
	//如果要增加的长度加上当前实际长度大于总缓冲大小的话
	const int nBlobLen = 1;
	if (m_lBufferLen< m_lBlobLen + nBlobLen)
		IncreaseBufferSize(nBlobLen, false);
	char temp[1];
	temp[0] = BlobChar;
	memcpy(m_BlobPtr + m_lBlobLen, &temp, nBlobLen);
	m_lBlobLen += nBlobLen;
}
コード例 #2
0
ファイル: BlobBuffer.cpp プロジェクト: ming-hai/soui
void BlobBuffer::AppendBlobContent(const unsigned char *BlobPtr,unsigned long nBlobLen)
{
   if(nBlobLen>0)
   { 
			//如果要增加的长度加上当前实际长度大于总缓冲大小的话
			if(m_lBufferLen< m_lBlobLen+nBlobLen)
				IncreaseBufferSize(nBlobLen, true);

			memcpy(m_BlobPtr+m_lBlobLen,BlobPtr,nBlobLen);
			m_lBlobLen += nBlobLen;
   }
} 
コード例 #3
0
ファイル: BlobBuffer.cpp プロジェクト: ming-hai/soui
void BlobBuffer::AllocBuffer(unsigned long nBufSize)
{
	if (nBufSize > this->GetBlobBufferLength())
	{
		IncreaseBufferSize(nBufSize - this->GetBlobBufferLength(), false);
		m_lBlobLen = nBufSize;
	}
	else
	{
		m_lBlobLen = nBufSize;
	}
}
コード例 #4
0
ファイル: BlobBuffer.cpp プロジェクト: ming-hai/soui
void BlobBuffer::SetBlobContent(const unsigned char *BlobPtr,unsigned long nBlobLen)
{ 
      if(nBlobLen>0)
      {
		  //如果要增加的长度加上当前实际长度大于总缓冲大小的话
	      if(m_lBufferLen< m_lBlobLen+nBlobLen)
			  IncreaseBufferSize(nBlobLen, false);

		  ClearContent();
	      memcpy(m_BlobPtr,BlobPtr,nBlobLen);
	      m_lBlobLen = nBlobLen;
	  }
	  else
	      Clear();
}
コード例 #5
0
ファイル: TCPTransport.cpp プロジェクト: dandaka/ola
/**
 * Read data until we reach the number of bytes we required or there is no more
 * data to be read
 */
void IncomingStreamTransport::ReadRequiredData() {
    if (m_outstanding_data == 0)
        return;

    if (m_outstanding_data > FreeSpace())
        IncreaseBufferSize(DataLength() + m_outstanding_data);

    unsigned int data_read;
    int ok = m_descriptor->Receive(m_data_end,
                                   m_outstanding_data,
                                   data_read);

    if (ok != 0)
        OLA_WARN << "tcp rx failed";
    OLA_DEBUG << "read " << data_read;
    m_data_end += data_read;
    m_outstanding_data -= data_read;
}
コード例 #6
0
ファイル: FileSource.cpp プロジェクト: kitnic/marmote
fs_ret_t FileSource::GetBuffer( size_t N = 1024 )
{
	while ( !SourceEmpty() && accum_len < N )
	{
		size_t N_new = N - accum_len;

		// Check to see if the buffer is large enough, if not increase size
		unsigned long worst_case_size = accum_len + N;
		if ( accum_total_len < worst_case_size )
			IncreaseBufferSize( worst_case_size - accum_total_len );


		size_t successfully_read_bytes = sizeof(unsigned char) * fread ( (void*) (accum + accum_len), sizeof(unsigned char), N_new, file_p );

		if ( successfully_read_bytes == 0 )
		{
			IterateFileList();
			continue;
		}

		accum_len += successfully_read_bytes;
            
		current_file_bytes_read += successfully_read_bytes;
		bytes_read += successfully_read_bytes;
	}
            
	time_t current_time = time( NULL );
	if ( difftime( current_time, previous_time ) > 3.0 )
	{
		char BPS_str[100];
		GetHumanReadableDataSize( BPS_str, double(bytes_read) / difftime( current_time, previous_time ) );
		printf("Throughput: %s/s; Progress: %.2f%%\n", BPS_str, ((double) current_file_bytes_read) / ((double) current_file_size) * 100.0 );

		bytes_read = 0;
		previous_time = current_time;
	}

	fs_ret_t ret_s;
	ret_s.accum = accum;
	ret_s.accum_len = accum_len;
	ret_s.accum_total_len = accum_total_len;
	return ret_s;
}
コード例 #7
0
ファイル: BlobBuffer.cpp プロジェクト: ming-hai/soui
bool BlobBuffer::LoadBlobFromFile(const char *sFileName)
{
	FILE *fp;
	long nReadCnt;

	fp = fopen(sFileName,"rb");
	if(fp == NULL)
	{
		return false;
	}
    
	fseek(fp,0,SEEK_END);
	long file_size = ftell(fp);
  fseek(fp,0,SEEK_SET);

  Clear();
        
  IncreaseBufferSize(file_size, false);

	if(0 == m_BlobPtr )
	{
		fclose(fp);
		return false;
	}

	nReadCnt = (long)fread(m_BlobPtr, 1, file_size, fp);
	if( nReadCnt<file_size )
	{
           if(ferror(fp))
	       {
              Clear(); 
			  return false;
		   }
    }

    m_lBlobLen = file_size;
	fclose(fp);
	return true;
}