#ifndef TimeoutH
#define TimeoutH TimeoutH

#include <time.h>
class CTimeout
{
public:
	explicit CTimeout( unsigned long timeoutmsec )
				{
					Start( timeoutmsec );
				}
	~CTimeout( ){ ; }
	void Start( unsigned long timeoutmsec )
	{
		start = clock( );
		elapse_period = (timeoutmsec * CLOCKS_PER_SEC / 1000) + 1; //+ 1 for small values of CLOCKS_PER_SEC e.g. 18,2
	}

	unsigned char Elapsed( )
	{
		return ( elapse_period < clock() );
	}

	unsigned long Remain( )
	{
		if( Elapsed( ) )
			return 0;
		else
			return ((elapse_period - clock()) * 1000) / CLOCKS_PER_SEC;

	}

private:
	clock_t elapse_period, start, end;
};

#endif //TimeoutH
