while(!(got_packet=c->get_packet(resultpacket)) && my_timeout > 0 && !c->is_closed())
{
- timeout_checkpoint=monotonic_clock_gettime_sec();
+ timeout_checkpoint=monotonic_clock_gettime_msec();
c->fill_buffer(millisec_timeout);
- my_timeout -= abs(monotonic_clock_gettime_sec() - timeout_checkpoint);
+ my_timeout -= abs(monotonic_clock_gettime_msec() - timeout_checkpoint);
}
int my_timeout=hello_timeout_millisec, timeout_checkpoint;
while(!(got_packet=c->get_packet(resultpacket)) && my_timeout > 0 && !c->is_closed())
{
- timeout_checkpoint=monotonic_clock_gettime_sec();
+ timeout_checkpoint=monotonic_clock_gettime_msec();
c->fill_buffer(my_timeout);
- my_timeout -= abs(monotonic_clock_gettime_sec() - timeout_checkpoint);
+ my_timeout -= abs(monotonic_clock_gettime_msec() - timeout_checkpoint);
c->peek_packet(resultpacket);
check_hello(resultpacket); // will throw before timeout if wrong data received
/**
* @brief fetches the value from the monotonic clock source.
- * @param[out] seconds the seconds.
- * @param[out] nano_seconds the nano seconds.
- * @return @a true if the clock was successfully read.
+ * @return the time since system start in milliseconds, -1 if read was unsuccessful
*/
-bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds)
+int monotonic_clock_gettime_msec()
{
struct timespec tp[1];
+ int millisec, nano_seconds;
int res= clock_gettime (CLOCK_MONOTONIC, tp);
if (0 == res)
{
- seconds= tp->tv_sec;
nano_seconds= tp->tv_nsec;
+ millisec = nano_seconds/1000000;
+ return millisec;
}
- return (res==0);
-}
-
-/**
- * @brief fetches the value from the monotonic clock source.
- * @return the time since system start in seconds, 0 if read was unsuccessful
- */
-int monotonic_clock_gettime_sec()
-{
- long int seconds=0;
- long int nano_seconds;
-
- monotonic_clock_gettime(seconds,nano_seconds);
- return seconds;
-}
+ return -1;
+}
\ No newline at end of file
#ifndef __LIBT2N_MONOTONIC_CLOCK
#define __LIBT2N_MONOTONIC_CLOCK
-bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds);
-int monotonic_clock_gettime_sec();
+int monotonic_clock_gettime_msec();
#endif
\ No newline at end of file
/// check if timeout is expired, close connection if so
void server_connection::check_timeout()
{
- if (timeout != -1 && last_action_time+timeout < monotonic_clock_gettime_sec())
+ if (timeout != -1 && last_action_time+timeout < monotonic_clock_gettime_msec())
{
LOGSTREAM(debug,"timeout on connection " << connection_id << ", closing");
this->close();
/// reset the timeout, e.g. if something is received
void server_connection::reset_timeout()
{
- last_action_time=monotonic_clock_gettime_sec();
+ last_action_time=monotonic_clock_gettime_msec();
}
/** @brief add a callback to one connection