Hi
I'm fairly new to many concepts in C/C++ and am just learning. I am trying to to create a timer class that can be used to check for timeouts on network operations. I was told I will need to assign a "handle" to each timer. I do know what handles are (i.e. handle to windows in visual C++) but I don't know in case of a custom timer how I should go about doing it. Can anyone help me understand this concept please?
Thanks
4 replies to this topic
#1
Posted 27 April 2011 - 11:08 PM
|
|
|
#2
Posted 27 April 2011 - 11:59 PM
There is a lack of information on your end. If you are working with network sockets, I would recommend looking at the Winsock select function. select Function (Windows)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 28 April 2011 - 06:57 AM
Sorry!
I'm working with Serial communication not network protocols. I'm trying to write a simple timer code that creates a timer and returns a handle. The timer will be used to time the packet transmission and make sure we retransmit it the ACK doesn't arrive within certain period of time. The handle is used for operations such as checking, resetting, closing etc after it was created. A system can have multiple timers running at the same time. Each timer will have a unique handle.
Thanks
I'm working with Serial communication not network protocols. I'm trying to write a simple timer code that creates a timer and returns a handle. The timer will be used to time the packet transmission and make sure we retransmit it the ACK doesn't arrive within certain period of time. The handle is used for operations such as checking, resetting, closing etc after it was created. A system can have multiple timers running at the same time. Each timer will have a unique handle.
Thanks
#4
Posted 28 April 2011 - 10:43 AM
class Timer {
public:
void start() {
#ifdef _WIN32
::QueryPerformanceCounter(&m_start);
#else
timeval time;
gettimeofday(&time, NULL);
m_start = time.tv_usec;
#endif
}
double elapsed() const {
#ifdef _WIN32
LARGE_INTEGER ticksPerSecond;
LARGE_INTEGER end;
::QueryPerformanceFrequency(&ticksPerSecond);
::QueryPerformanceCounter(&end);
return static_cast<double>(end.QuadPart - m_start.QuadPart) / ticksPerSecond.QuadPart;
#else
timeval time;
gettimeofday(&time, NULL);
return static_cast<double>(time.tv_usec - m_start);
#endif
}
void restart() {
Timer::start();
}
void sleep(int milisec) {
if (milisec > 0)
#ifdef _WIN32
::Sleep(milisec);
#else
usleep(milisec * 1000);
#endif
}
#ifndef _WIN32
void uSleep(int microsec) {
if (microsec > 0)
usleep(microsec);
}
#endif
private:
#ifdef _WIN32
LARGE_INTEGER m_start;
#else
double m_start;
#endif
};
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#5
Posted 29 April 2011 - 06:35 AM
Microsecond timer for Windows
The above explains some timers in win32 and can help to understand what is being used in the code above.
The above explains some timers in win32 and can help to understand what is being used in the code above.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









