Click here to Skip to main content
15,891,431 members
Articles / Programming Languages / C++

Push Framework - A C++ toolkit for high performance server development

Rate me:
Please Sign up or sign in to vote.
4.96/5 (86 votes)
23 May 2012Apache15 min read 261.4K   26.9K   316  
Write asynchronous, multithreaded servers in a few lines of code. Monitor realtime activity with a deploy-only dashboard.
#include "StdAfx.h"
#include "MyQoSClient.h"

CMyQoSClient::CMyQoSClient(void)
{
	registerHandler(1, this); // incoming packets will be redirected back to this class via ::handleResponse method.
	setProtocol(new QoSExampleProtocol);
}

CMyQoSClient::~CMyQoSClient(void)
{
}

void CMyQoSClient::onConnected( bool bResult )
{
	std::cout << (bResult ? "connection success" : "connection failure") << std::endl;

	if (bResult)
	{
		CQoSPacket packet;
		TCPSocket::sendRequest(&packet);
	}
}

void CMyQoSClient::onConnectionClosed( bool bPeerClose )
{
	std::cout << (bPeerClose ? "connection closed by peer" : "connection closed") << std::endl;
}

void CMyQoSClient::handleResponse( PushFramework::IncomingPacket& packet )
{
	CQoSPacket& response = (CQoSPacket&) packet;

	//std::cout << "new response " << response.getPacketId() << std::endl;
	//
	statsMapT::iterator it = statsMap.find(response.getChannelSourceId());
	if (it == statsMap.end()){
		ChannelPacketsInfo* pInfo = new ChannelPacketsInfo;
		pInfo->lastReceivedId = response.getPacketId();
		pInfo->uPacketsCount = 1;
		pInfo->uMissedCount = 0;
		pInfo->nDuplicates = 0;

		statsMap[response.getChannelSourceId()] = pInfo;
	}
	else{
		ChannelPacketsInfo* pInfo = it->second;
		//
		pInfo->uPacketsCount++;

		if (pInfo->uPacketsCount == UINT_MAX)
		{
			exit(-1);
		}
	
		/*
			int nMissed = response.getPacketId() - pInfo->lastReceivedId -1;
					if (nMissed == -1)
						pInfo->nDuplicates++;
					else if (nMissed < -1)
					{
						cout << "nMissed < -1 FATAL " << endl;
						exit(-1);
					}
					else
						pInfo->uMissedCount+= nMissed;*/
			

		pInfo->lastReceivedId = response.getPacketId();
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Technical Lead
Tunisia Tunisia
Services:
http://www.pushframework.com/?page_id=890

Comments and Discussions