void MultyBuffer::DoWork(const int i)
{
	const std::string num_part = boost::str(boost::format("%03u.txt") % i);
	const std::string inputFile = BINARY_DIR + std::string("/input_") + num_part;
	std::ifstream inputStream(inputFile , std::ios::binary);

	Statistic statistic;
	Sizes sizes;

	if(!inputStream.good())
	{
		std::cout << "Incorrect file path: " << inputFile << std::endl;
		return;
	}

	const std::string outputFile = BINARY_DIR + std::string("/output_") + num_part;
	std::ofstream outputStream(outputFile, std::ios::out | std::ios::binary);

	const boost::uint32_t treshold = 2048;
	boost::uint32_t currentTime = -1;
	int currentSize = 0;
	
	while (true)
	{
		binary_reader::market_message message(inputStream);

		if(inputStream.eof())
			break;

		const boost::uint32_t type = message.type();
		if (sizes.find(type) == sizes.end())
			sizes[type] = 0;

		const boost::uint32_t messageSize = GetMessageSize(message);

		if (message.time() == currentTime && ((sizes[type] + messageSize) <= treshold))
		{
			sizes[type] += messageSize;

			const bool incr_sec = std::find(curentTypes.begin(), curentTypes.end(), type) == curentTypes.end();
			StatisticUp(type, incr_sec, statistic);

		}
		else if ((sizes[type] + messageSize) <= treshold)
		{
			curentTypes.clear();
			currentTime = message.time();
			sizes[type] = messageSize;
			StatisticUp(type, true, statistic);
		}
		else
			continue;

		curentTypes.push_back(type);
	}

	inputStream.close();
	ShowStatictics(statistic, outputStream);
	outputStream.close();
}
Example #2
0
BOOL CPop3Connection::GetMessageHeader(int nMsg, CPop3Message& message)
{
	// Must be connected to retrieve a message
	if(!m_bConnected)
	{
		//m_sLastCommandResponse = _T("ͨÐÅ佨Á¢");//<%IDS_Pop3_28%>
		m_sLastCommandResponse = FuncGetStringFromIDS("<%IDS_Pop3_28%>");
		return FALSE;
	}
	
	// make sure the message actually exists
	DWORD dwSize;
	if (GetMessageSize(nMsg, dwSize))
	{
		// Send the TOP command
		char sBuf[16];
		sprintf(sBuf, "TOP %d 0\r\n", nMsg);
		int nCmdLength = strlen(sBuf);
		if (!m_pop.Send(sBuf, nCmdLength))
		{
			TRACE(_T("Failed to send the TOP command to the POP3 server\n"));
			//m_sLastCommandResponse = _T("·¢ËÍTOPÃüÁîʧ°Ü");//<%IDS_Pop3_29%>
			m_sLastCommandResponse = FuncGetStringFromIDS("<%IDS_Pop3_29%>");
			return FALSE;
		}
		
		// And check the command
		return ReadReturnResponse(message, dwSize);
	}
	else
		return FALSE;
}
Example #3
0
BOOL CPop3Connection::Retrieve(int nMsg, CPop3Message& message)
{
	//Must be connected to retrieve a message
	if(!m_bConnected)
	{
		//m_sLastCommandResponse = _T("ͨÐÅ佨Á¢");//<%IDS_Pop3_24%>
		m_sLastCommandResponse = ::FuncGetStringFromIDS("<%IDS_Pop3_24%>");
		return FALSE;
	}
	
	//work out the size of the message to retrieve
	DWORD dwSize;
	if (GetMessageSize(nMsg, dwSize))
	{
		//Send the RETR command
		char sBuf[20];
		sprintf(sBuf, "RETR %d\r\n", nMsg);	
		int nCmdLength = strlen(sBuf);
		if (!m_pop.Send(sBuf, nCmdLength))
		{
			TRACE(_T("Failed to send the RETR command to the POP3 server\n"));
			//m_sLastCommandResponse = _T("·¢ËÍRETRÃüÁîʧ°Ü");//<%IDS_Pop3_25%>
			m_sLastCommandResponse = ::FuncGetStringFromIDS("<%IDS_Pop3_25%>");
			return FALSE;
		}
		
		//And check the command
		return ReadReturnResponse(message, dwSize);
	}
	else
		return FALSE;
}
Example #4
0
uint8_t GetMessageDataSize( void){
	return GetMessageSize() - INCOMING_MESSAGE_OVERHEAD;	
}