summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2002-04-23 12:02:26 +0000
committerMarc Laukien <marc@zeroc.com>2002-04-23 12:02:26 +0000
commitcb3cca50234f415321f7228b650a6522ca515c08 (patch)
tree14a2567b32fa7c93fbd2b73db11330596eeb316e /cpp/src
parentWIN32 updates. (diff)
downloadice-cb3cca50234f415321f7228b650a6522ca515c08.tar.bz2
ice-cb3cca50234f415321f7228b650a6522ca515c08.tar.xz
ice-cb3cca50234f415321f7228b650a6522ca515c08.zip
Time changes
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Instance.cpp19
-rw-r--r--cpp/src/IceUtil/Time.cpp86
2 files changed, 44 insertions, 61 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 8cf81eb08e7..6e534c3f9f7 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -33,11 +33,8 @@
#ifndef _WIN32
# include <csignal>
# include <syslog.h>
-# include <sys/time.h>
# include <pwd.h>
# include <sys/types.h>
-#else
-# include <sys/timeb.h>
#endif
using namespace std;
@@ -220,6 +217,8 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope
if (_globalStateCounter == 1) // Only on first call
{
+ srand(static_cast<timeval>(IceUtil::Time::now()).tv_usec);
+
#ifdef _WIN32
WORD version = MAKEWORD(1, 1);
WSADATA data;
@@ -238,19 +237,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
sigaction(SIGPIPE, &action, 0);
-#endif
-
-#ifdef _WIN32
- struct _timeb tb;
- _ftime(&tb);
- srand(tb.millitm);
-#else
- timeval tv;
- gettimeofday(&tv, 0);
- srand(tv.tv_usec);
-#endif
-
-#ifndef _WIN32
+
string newUser = _properties->getProperty("Ice.ChangeUser");
if (!newUser.empty())
{
diff --git a/cpp/src/IceUtil/Time.cpp b/cpp/src/IceUtil/Time.cpp
index 4c0e0c12dfe..4cd6c7fb466 100644
--- a/cpp/src/IceUtil/Time.cpp
+++ b/cpp/src/IceUtil/Time.cpp
@@ -23,53 +23,47 @@ Time::Time() :
{
}
-IceUtil::Time::Time(const timeval& tv) :
- _usec((tv.tv_sec * (LongLong)1000000) + tv.tv_usec)
-{
-}
-
Time
IceUtil::Time::now()
{
#ifdef WIN32
- struct _timeb timebuffer;
- _ftime(&timebuffer);
-
- return Time(timebuffer.time * (LongLong)1000000) +
- (timebuffer.millitm * (LongLong)1000);
+ struct _timeb tb;
+ _ftime(&tb);
+ return Time(tb.time * static_cast<LongLong>(1000000) + tb.millitm * static_cast<LongLong>(1000));
#else
struct timeval tv;
gettimeofday(&tv, 0);
-
- return Time(tv);
+ return Time(tv.tv_sec * static_cast<LongLong>(1000000) + tv.tv_usec);
#endif
}
Time
IceUtil::Time::seconds(long t)
{
- return Time(t * (LongLong)1000000);
+ return Time(t * static_cast<LongLong>(1000000));
}
Time
IceUtil::Time::milliSeconds(long t)
{
- return Time(t * (LongLong)1000);
+ return Time(t * static_cast<LongLong>(1000));
}
-#ifdef _WIN32
Time
-IceUtil::Time::microSeconds(__int64 t)
+IceUtil::Time::microSeconds(LongLong t)
{
return Time(t);
}
-#else
+
Time
-IceUtil::Time::microSeconds(long long t)
+IceUtil::Time::operator=(const Time& rhs)
{
- return Time(t);
+ if (this != &rhs)
+ {
+ _usec = rhs._usec;
+ }
+ return *this;
}
-#endif
Time
IceUtil::Time::operator-() const
@@ -78,78 +72,80 @@ IceUtil::Time::operator-() const
}
Time
-IceUtil::Time::operator-(const Time& other) const
+IceUtil::Time::operator-(const Time& rhs) const
{
- return Time(_usec - other._usec);
+ return Time(_usec - rhs._usec);
}
Time
-IceUtil::Time::operator+(const Time& other) const
+IceUtil::Time::operator+(const Time& rhs) const
{
- return Time(_usec + other._usec);
+ return Time(_usec + rhs._usec);
}
Time&
-IceUtil::Time::operator+=(const Time& other)
+IceUtil::Time::operator+=(const Time& rhs)
{
- _usec += other._usec;
+ _usec += rhs._usec;
return *this;
}
Time&
-IceUtil::Time::operator-=(const Time& other)
+IceUtil::Time::operator-=(const Time& rhs)
{
- _usec -= other._usec;
+ _usec -= rhs._usec;
return *this;
}
bool
-IceUtil::Time::operator<(const Time& other) const
+IceUtil::Time::operator<(const Time& rhs) const
{
- return _usec < other._usec;
+ return _usec < rhs._usec;
}
bool
-IceUtil::Time::operator<=(const Time& other) const
+IceUtil::Time::operator<=(const Time& rhs) const
{
- return _usec <= other._usec;
+ return _usec <= rhs._usec;
}
bool
-IceUtil::Time::operator>(const Time& other) const
+IceUtil::Time::operator>(const Time& rhs) const
{
- return _usec > other._usec;
+ return _usec > rhs._usec;
}
bool
-IceUtil::Time::operator>=(const Time& other) const
+IceUtil::Time::operator>=(const Time& rhs) const
{
- return _usec >= other._usec;
+ return _usec >= rhs._usec;
}
bool
-IceUtil::Time::operator==(const Time& other) const
+IceUtil::Time::operator==(const Time& rhs) const
{
- return _usec == other._usec;
+ return _usec == rhs._usec;
}
bool
-IceUtil::Time::operator!=(const Time& other) const
+IceUtil::Time::operator!=(const Time& rhs) const
{
- return _usec != other._usec;
+ return _usec != rhs._usec;
}
IceUtil::Time::operator timeval() const
{
timeval tv;
- tv.tv_sec = (long)(_usec / 1000000);
- tv.tv_usec = (long)(_usec % 1000000);
+ tv.tv_sec = static_cast<long>(_usec / 1000000);
+ tv.tv_usec = static_cast<long>(_usec % 1000000);
return tv;
}
-//
-// Private constructor.
-//
+IceUtil::Time::operator double() const
+{
+ return _usec / 1000000.0L;
+}
+
Time::Time(LongLong usec) :
_usec(usec)
{