Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

STL WebServer

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

Share

About the Author

David Hubbard

United States United States
No Biography provided

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