Click here to Skip to main content
15,895,746 members
Articles / Desktop Programming / MFC

STL WebServer

Rate me:
Please Sign up or sign in to vote.
4.89/5 (5 votes)
8 May 2000 90.3K   2.5K   47  
A set of classes written in STL that implement a web server
#include "stdafx.h"

#include "HttpServerStats.h"

/////////////////////////////////////////////////////////////////////////////
// HttpServerStats

HttpServerStats::HttpServerStats () :
	_stats(),
	_numberOfHits(0)
{
	create();
}

HttpServerStats::~HttpServerStats ()
{
	_stats.clear();
}


// create release
bool HttpServerStats::create ()
{
	// if stats not created create
	if ( _stats.size() == 0 )
	{
		// init stats
		for ( long i=0; i < STATUS_NO_COUNTERS; i++ )
		{
			_stats.push_back(0);
		}
	}

	// init stats
	reset();

	return true;
}

void HttpServerStats::release ()
{
	// clear stats
	_stats.clear();

	// show no hits
	_numberOfHits = 0;

	// close log file
	_logFile.close();
	_logFile.release();


}


void HttpServerStats::reset ()
{
	// init stats
	for ( long i=0; i < STATUS_NO_COUNTERS; i++ )
	{
		_stats[i] = 0;
	}

	// show no hits
	_numberOfHits = 0;
}

void HttpServerStats::hit ( HttpRequest & request )
{
	// increment the total hit count
	_numberOfHits++;
}

void HttpServerStats::getStats ( HttpRequest & request )
{
	// increment the status' group count
	long status = request.getStatus();
	if ( status >= 100 && status < 600 )
		_stats[ status/100 - 1 ]++;
	else
		_stats[ STATUS_SERVERERR ]++;

	// see if we want to write entry in log file
	if ( _logging )
	{
		stringstream log;

		// get host where request originated
		log << request.getHost();

		// request status
		log << request.getStatus();

		// elements to add
		// time
		// string args (ex: www.host.com?ar1=val1&ar2=val2
		// request time		

		_logFile << log;
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions