Click here to Skip to main content
11,647,170 members (69,742 online)
Click here to Skip to main content
Add your own
alternative version

STL WebServer

, 8 May 2000 73.7K 2.2K 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

Share

About the Author

David Hubbard
United States United States
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150804.2 | Last Updated 9 May 2000
Article Copyright 2000 by David Hubbard
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid