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 | e6d5aa096c62624ef64daaf0c2876f7e45e7c9de (patch) | |
tree | a4982f489f91bfec094544852a830d9eb2fdec9b /cpp | |
parent | ad10e6cfc117b48e09ade71b312a04f06200330a (diff) | |
download | qpid-python-e6d5aa096c62624ef64daaf0c2876f7e45e7c9de.tar.gz |
QPID-3620 time conversion fix for sparc architecture
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1242406 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/qpid/sys/posix/Time.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/cpp/src/qpid/sys/posix/Time.cpp b/cpp/src/qpid/sys/posix/Time.cpp index 9661f0c5e8..dee393f4bf 100644 --- a/cpp/src/qpid/sys/posix/Time.cpp +++ b/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; } |