Click here to Skip to main content
15,895,011 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
#if !defined(Thread_H)
#define Thread_H


#include "SysEvent.h"

//#define UseWin32Thread

#if !defined(UseWin32Thread)
#include <process.h>
#endif

////////////////////////////////////////////////////////////////////////
// Thread 

class Thread
{
public:
	enum
	{
		idCancel,
		idSuspend,
		idResume,
		idEnd,
		idNoEvents
	};

private:
	
	static long	m_delayTime;			// define time to delay for a thread sleep 

	void *		m_pThreadData;			// data for this thread

	HANDLE		m_hThread;				// handle to thread
	DWORD		m_idThread;				// id of thread
	SysEvent	m_events[idNoEvents];	// base thread events

public:
	Thread ();
	~Thread ();


	// create/destroy
	bool 		create			( void * pThreadData = NULL );
	void		release			();


	// thread methods
	void *		getData			()				{ return m_pThreadData; }
	HANDLE		getHandle		()				{ return m_hThread; }
	DWORD		getId			()				{ return m_idThread; }

	// event methods
	bool		createThreadEvents ();

	HANDLE		getEvent		( long id )		{ return m_events[id].getEvent(); }
	void		setEvent		( long id )		{ m_events[id].set(); }
	void		resetEvent		( long id )		{ m_events[id].reset(); }

	HANDLE		getEndEvent		()				{ return m_events[idEnd].getEvent(); }
	void		setEndEvent		()				{ m_events[idEnd].set(); }

	HANDLE		getCancelEvent	()				{ return m_events[idCancel].getEvent(); }
	void		setCancelEvent	()				{ m_events[idCancel].set(); }
	void		resetCancelEvent	()			{ m_events[idCancel].reset(); }

	// control
	void		stop			();
	void		suspend			();
	void		resume			();
	void		cancel			();


	// run method
	virtual long run  ();

	// virtual idle method 
	virtual void idle ()
	{}

	// static thread proc
	#if defined(UseWin32Thread)
	static DWORD WINAPI		 threadProc		( LPVOID parameter );

	#else
	static unsigned _stdcall threadProc		( LPVOID parameter );
	#endif
};


#endif

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