diff options
author | Clifford Allan Jansen <cliffjansen@apache.org> | 2012-02-09 17:23:41 +0000 |
---|---|---|
committer | Clifford Allan Jansen <cliffjansen@apache.org> | 2012-02-09 17:23:41 +0000 |
commit | 866664af8c5638d766e4b98af3aa89e8dbfe04df (patch) | |
tree | 2000e7af7c2283e596ac691b27eb2b38d859026b | |
parent | 4f17ae00b4ec517bdf25fb1e70728c73390199f5 (diff) | |
download | qpid-python-866664af8c5638d766e4b98af3aa89e8dbfe04df.tar.gz |
QPID-3620 time conversion fix for sparc architecture
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1242406 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/src/qpid/sys/posix/Time.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/qpid/cpp/src/qpid/sys/posix/Time.cpp b/qpid/cpp/src/qpid/sys/posix/Time.cpp index 9661f0c5e8..dee393f4bf 100644 --- a/qpid/cpp/src/qpid/sys/posix/Time.cpp +++ b/qpid/cpp/src/qpid/sys/posix/Time.cpp @@ -61,15 +61,22 @@ Duration::Duration(const AbsTime& start, const AbsTime& finish) : nanosecs(finish.timepoint - start.timepoint) {} +namespace { +/** type conversion helper: an infinite timeout for time_t sized types **/ +const time_t TIME_T_MAX = std::numeric_limits<time_t>::max(); +} + struct timespec& toTimespec(struct timespec& ts, const Duration& t) { - ts.tv_sec = t / TIME_SEC; - ts.tv_nsec = t % TIME_SEC; + Duration secs = t / TIME_SEC; + ts.tv_sec = (secs > TIME_T_MAX) ? TIME_T_MAX : static_cast<time_t>(secs); + ts.tv_nsec = static_cast<long>(t % TIME_SEC); return ts; } struct timeval& toTimeval(struct timeval& tv, const Duration& t) { - tv.tv_sec = t/TIME_SEC; - tv.tv_usec = (t%TIME_SEC)/TIME_USEC; + Duration secs = t / TIME_SEC; + tv.tv_sec = (secs > TIME_T_MAX) ? TIME_T_MAX : static_cast<time_t>(secs); + tv.tv_usec = static_cast<suseconds_t>((t%TIME_SEC)/TIME_USEC); return tv; } |