diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-07-17 14:24:36 -0700 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-07-17 14:24:36 -0700 |
commit | 2510ce477b8652ef67b45280256479a3c531df13 (patch) | |
tree | c298ca9b617b4dee3eb0f0b4e66f1c8a81944b78 /src | |
parent | e95933587ae735cbed0e6abb3d83efd0dc58bea1 (diff) |
Reflect new gpr_timespec type in C#
Diffstat (limited to 'src')
-rw-r--r-- | src/csharp/Grpc.Core.Tests/TimespecTest.cs | 12 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/Enums.cs | 15 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/Timespec.cs | 8 |
3 files changed, 26 insertions, 9 deletions
diff --git a/src/csharp/Grpc.Core.Tests/TimespecTest.cs b/src/csharp/Grpc.Core.Tests/TimespecTest.cs index f5bae6d935..5831121add 100644 --- a/src/csharp/Grpc.Core.Tests/TimespecTest.cs +++ b/src/csharp/Grpc.Core.Tests/TimespecTest.cs @@ -61,28 +61,28 @@ namespace Grpc.Core.Internal.Tests [Test] public void Add() { - var t = new Timespec { tv_sec = new IntPtr(12345), tv_nsec = new IntPtr(123456789) }; + var t = new Timespec { tv_sec = new IntPtr(12345), tv_nsec = 123456789 }; var result = t.Add(TimeSpan.FromTicks(TimeSpan.TicksPerSecond * 10)); Assert.AreEqual(result.tv_sec, new IntPtr(12355)); - Assert.AreEqual(result.tv_nsec, new IntPtr(123456789)); + Assert.AreEqual(result.tv_nsec, 123456789); } [Test] public void Add_Nanos() { - var t = new Timespec { tv_sec = new IntPtr(12345), tv_nsec = new IntPtr(123456789) }; + var t = new Timespec { tv_sec = new IntPtr(12345), tv_nsec = 123456789 }; var result = t.Add(TimeSpan.FromTicks(10)); Assert.AreEqual(result.tv_sec, new IntPtr(12345)); - Assert.AreEqual(result.tv_nsec, new IntPtr(123456789 + 1000)); + Assert.AreEqual(result.tv_nsec, 123456789 + 1000); } [Test] public void Add_NanosOverflow() { - var t = new Timespec { tv_sec = new IntPtr(12345), tv_nsec = new IntPtr(999999999) }; + var t = new Timespec { tv_sec = new IntPtr(12345), tv_nsec = 999999999 }; var result = t.Add(TimeSpan.FromTicks(TimeSpan.TicksPerSecond * 10 + 10)); Assert.AreEqual(result.tv_sec, new IntPtr(12356)); - Assert.AreEqual(result.tv_nsec, new IntPtr(999)); + Assert.AreEqual(result.tv_nsec, 999); } } } diff --git a/src/csharp/Grpc.Core/Internal/Enums.cs b/src/csharp/Grpc.Core/Internal/Enums.cs index af11b5b9f3..185098160b 100644 --- a/src/csharp/Grpc.Core/Internal/Enums.cs +++ b/src/csharp/Grpc.Core/Internal/Enums.cs @@ -90,4 +90,19 @@ namespace Grpc.Core.Internal /* operation completion */ OpComplete } + + /// <summary> + /// gpr_clock_type from grpc/support/time.h + /// </summary> + internal enum GPRClockType + { + /* Monotonic clock */ + Monotonic, + + /* Realtime clock */ + Realtime, + + /* Timespan - the distance between two time points */ + Timespan + } } diff --git a/src/csharp/Grpc.Core/Internal/Timespec.cs b/src/csharp/Grpc.Core/Internal/Timespec.cs index 775af27db9..de783f5a4b 100644 --- a/src/csharp/Grpc.Core/Internal/Timespec.cs +++ b/src/csharp/Grpc.Core/Internal/Timespec.cs @@ -55,7 +55,8 @@ namespace Grpc.Core.Internal // NOTE: on linux 64bit sizeof(gpr_timespec) = 16, on windows 32bit sizeof(gpr_timespec) = 8 // so IntPtr seems to have the right size to work on both. public System.IntPtr tv_sec; - public System.IntPtr tv_nsec; + public int tv_nsec; + public GPRClockType clock_type; /// <summary> /// Timespec a long time in the future. @@ -99,12 +100,13 @@ namespace Grpc.Core.Internal public Timespec Add(TimeSpan timeSpan) { - long nanos = tv_nsec.ToInt64() + (timeSpan.Ticks % TimeSpan.TicksPerSecond) * NanosPerTick; + long nanos = (long)tv_nsec + (timeSpan.Ticks % TimeSpan.TicksPerSecond) * NanosPerTick; long overflow_sec = (nanos > NanosPerSecond) ? 1 : 0; Timespec result; - result.tv_nsec = new IntPtr(nanos % NanosPerSecond); + result.tv_nsec = (int)(nanos % NanosPerSecond); result.tv_sec = new IntPtr(tv_sec.ToInt64() + (timeSpan.Ticks / TimeSpan.TicksPerSecond) + overflow_sec); + result.clock_type = GPRClockType.Realtime; return result; } } |