Ejemplo n.º 1
0
 public void Add_Nanos()
 {
     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, 123456789 + 1000);
 }
Ejemplo n.º 2
0
 public void Add_NanosOverflow()
 {
     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, 999);
 }
Ejemplo n.º 3
0
 public void WatchConnectivityState(ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq,
     CompletionRegistry completionRegistry, BatchCompletionDelegate callback)
 {
     var ctx = BatchContextSafeHandle.Create();
     completionRegistry.RegisterBatchCompletion(ctx, callback);
     Native.grpcsharp_channel_watch_connectivity_state(this, lastObservedState, deadline, cq, ctx);
 }
Ejemplo n.º 4
0
 public void Add()
 {
     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, 123456789);
 }
 public ServerRpcNew(Server server, CallSafeHandle call, string method, string host, Timespec deadline, Metadata requestMetadata)
 {
     this.server = server;
     this.call = call;
     this.method = method;
     this.host = host;
     this.deadline = deadline;
     this.requestMetadata = requestMetadata;
 }
Ejemplo n.º 6
0
 public CallSafeHandle CreateCall(CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline, CallCredentialsSafeHandle credentials)
 {
     var result = Native.grpcsharp_channel_create_call(this, parentCall, propagationMask, cq, method, host, deadline);
     if (credentials != null)
     {
         result.SetCredentials(credentials);
     }
     result.Initialize(cq);
     return result;
 }
Ejemplo n.º 7
0
 public CallSafeHandle CreateCall(CompletionRegistry registry, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline, CredentialsSafeHandle credentials)
 {
     using (Profilers.ForCurrentThread().NewScope("ChannelSafeHandle.CreateCall"))
     {
         var result = grpcsharp_channel_create_call(this, parentCall, propagationMask, cq, method, host, deadline);
         if (credentials != null)
         {
             result.SetCredentials(credentials);
         }
         result.SetCompletionRegistry(registry);
         return result;
     }
 }
        private INativeCall CreateNativeCall(CompletionQueueSafeHandle cq)
        {
            using (Profilers.ForCurrentThread().NewScope("AsyncCall.CreateNativeCall"))
            {
                if (injectedNativeCall != null)
                {
                    return(injectedNativeCall);  // allows injecting a mock INativeCall in tests.
                }

                var parentCall = details.Options.PropagationToken != null ? details.Options.PropagationToken.ParentCall : CallSafeHandle.NullInstance;

                var credentials = details.Options.Credentials;
                using (var nativeCredentials = credentials != null ? credentials.ToNativeCredentials() : null)
                {
                    var result = details.Channel.Handle.CreateCall(
                        parentCall, ContextPropagationToken.DefaultMask, cq,
                        details.Method, details.Host, Timespec.FromDateTime(details.Options.Deadline.Value), nativeCredentials);
                    return(result);
                }
            }
        }
        public void ToDateTime_OutOfDateTimeRange()
        {
            // DateTime range goes up to year 9999, 20000 years from now should
            // be out of range.
            long seconds = 20000L * 365L * 24L * 3600L; 

            var timespec = new Timespec(seconds, 0);
            Assert.AreNotEqual(Timespec.InfFuture, timespec);
            Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime());

            Assert.AreEqual(DateTime.MinValue, new Timespec(-seconds, 0).ToDateTime());
        }
Ejemplo n.º 10
0
        public static CallSafeHandle Create(ChannelSafeHandle channel, CompletionRegistry registry, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)
        {
            var result = grpcsharp_channel_create_call(channel, cq, method, host, deadline);

            result.SetCompletionRegistry(registry);
            return(result);
        }
Ejemplo n.º 11
0
        public void ToDateTime_Overflow()
        {
            // we can only get overflow in ticks arithmetic on 64-bit
            if (IntPtr.Size == 8)
            {
                var timespec = new Timespec(new IntPtr(long.MaxValue - 100), 0);
                Assert.AreNotEqual(Timespec.InfFuture, timespec);
                Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime());

                Assert.AreEqual(DateTime.MinValue, new Timespec(new IntPtr(long.MinValue + 100), 0).ToDateTime());
            }
            else
            {
                Console.WriteLine("Test cannot be run on this platform, skipping the test.");
            }
        }
        public void ToDateTime_Overflow()
        {     
            var timespec = new Timespec(long.MaxValue - 100, 0);
            Assert.AreNotEqual(Timespec.InfFuture, timespec);
            Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime());

            Assert.AreEqual(DateTime.MinValue, new Timespec(long.MinValue + 100, 0).ToDateTime());
        }
Ejemplo n.º 13
0
 internal static extern Timespec gprsharp_convert_clock_type(Timespec t, ClockType targetClock);
Ejemplo n.º 14
0
 static extern void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState,
     Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx);
Ejemplo n.º 15
0
 CallSafeHandle IPlatformInvocation.grpcsharp_channel_create_call(ChannelSafeHandle channel,
     CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq,
     string method, string host, Timespec deadline)
 {
     return grpcsharp_channel_create_call(channel, parentCall, propagationMask, cq, method, host, deadline);
 }
Ejemplo n.º 16
0
 public CallSafeHandle CreateCall(CompletionRegistry registry, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline, CallCredentialsSafeHandle credentials)
 {
     using (Profilers.ForCurrentThread().NewScope("ChannelSafeHandle.CreateCall"))
     {
         var result = Native.grpcsharp_channel_create_call(this, parentCall, propagationMask, cq, method, host, deadline);
         if (credentials != null)
         {
             result.SetCredentials(credentials);
         }
         result.Initialize(registry, cq);
         return(result);
     }
 }
Ejemplo n.º 17
0
        private void Initialize(CompletionQueueSafeHandle cq)
        {
            var parentCall = details.Options.PropagationToken != null ? details.Options.PropagationToken.ParentCall : CallSafeHandle.NullInstance;

            var call = details.Channel.Handle.CreateCall(details.Channel.Environment.CompletionRegistry,
                                                         parentCall, ContextPropagationToken.DefaultMask, cq,
                                                         details.Method, details.Host, Timespec.FromDateTime(details.Options.Deadline.Value));

            details.Channel.AddCallReference(this);

            InitializeInternal(call);
            RegisterCancellationCallback();
        }
Ejemplo n.º 18
0
 void IPlatformInvocation.grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel,
                                                                     ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx)
 {
     grpcsharp_channel_watch_connectivity_state(channel, lastObservedState, deadline, cq, ctx);
 }
Ejemplo n.º 19
0
 public static CallSafeHandle Create(ChannelSafeHandle channel, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)
 {
     return(grpcsharp_channel_create_call(channel, cq, method, host, deadline));
 }
Ejemplo n.º 20
0
 static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline);
Ejemplo n.º 21
0
 public CallSafeHandle CreateCall(CompletionRegistry registry, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)
 {
     var result = grpcsharp_channel_create_call(this, cq, method, host, deadline);
     result.SetCompletionRegistry(registry);
     return result;
 }
Ejemplo n.º 22
0
 static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline);
Ejemplo n.º 23
0
 public static CallSafeHandle Create(ChannelSafeHandle channel, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)
 {
     return grpcsharp_channel_create_call(channel, cq, method, host, deadline);
 }
Ejemplo n.º 24
0
        public void WatchConnectivityState(ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, BatchCompletionDelegate callback, object callbackState)
        {
            var ctx = cq.CompletionRegistry.RegisterBatchCompletion(callback, callbackState);

            Native.grpcsharp_channel_watch_connectivity_state(this, lastObservedState, deadline, cq, ctx);
        }
 public ProfilerEntry(Timespec timespec, Type type, string tag)
 {
     this.timespec = timespec;
     this.type = type;
     this.tag = tag;
 }
Ejemplo n.º 26
0
 CallSafeHandle IPlatformInvocation.grpcsharp_channel_create_call(ChannelSafeHandle channel,
                                                                  CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq,
                                                                  string method, string host, Timespec deadline)
 {
     return(grpcsharp_channel_create_call(channel, parentCall, propagationMask, cq, method, host, deadline));
 }
Ejemplo n.º 27
0
 static extern Timespec gprsharp_convert_clock_type(Timespec t, GPRClockType targetClock);
Ejemplo n.º 28
0
 Timespec IPlatformInvocation.gprsharp_convert_clock_type(Timespec t, GPRClockType targetClock)
 {
     return(gprsharp_convert_clock_type(t, targetClock));
 }
Ejemplo n.º 29
0
 internal static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline);
Ejemplo n.º 30
0
 void IPlatformInvocation.grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel,
     ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx)
 {
     grpcsharp_channel_watch_connectivity_state(channel, lastObservedState, deadline, cq, ctx);
 }
Ejemplo n.º 31
0
        public void ToDateTime_OutOfDateTimeRange()
        {
            // we can only get out of range on 64-bit, on 32 bit the max 
            // timestamp is ~ Jan 19 2038, which is far within range of DateTime
            // same case for min value.
            if (IntPtr.Size == 8)
            {
                // DateTime range goes up to year 9999, 20000 years from now should
                // be out of range.
                long seconds = 20000L * 365L * 24L * 3600L; 

                var timespec = new Timespec(new IntPtr(seconds), 0);
                Assert.AreNotEqual(Timespec.InfFuture, timespec);
                Assert.AreEqual(DateTime.MaxValue, timespec.ToDateTime());

                Assert.AreEqual(DateTime.MinValue, new Timespec(new IntPtr(-seconds), 0).ToDateTime());
            }
            else
            {
                Console.WriteLine("Test cannot be run on this platform, skipping the test");
            }
        }
Ejemplo n.º 32
0
 Timespec IPlatformInvocation.gprsharp_convert_clock_type(Timespec t, GPRClockType targetClock)
 {
     return gprsharp_convert_clock_type(t, targetClock);
 }
Ejemplo n.º 33
0
        public CallSafeHandle CreateCall(CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline, CallCredentialsSafeHandle credentials)
        {
            var result = Native.grpcsharp_channel_create_call(this, parentCall, propagationMask, cq, method, host, deadline);

            if (credentials != null)
            {
                result.SetCredentials(credentials);
            }
            result.Initialize(cq);
            return(result);
        }
Ejemplo n.º 34
0
 internal static extern void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState,
                                                                        Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx);
Ejemplo n.º 35
0
 public ServerRpcNew(Server server, CallSafeHandle call, string method, string host, Timespec deadline, Metadata requestMetadata)
 {
     this.server          = server;
     this.call            = call;
     this.method          = method;
     this.host            = host;
     this.deadline        = deadline;
     this.requestMetadata = requestMetadata;
 }
Ejemplo n.º 36
0
 static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline);
Ejemplo n.º 37
0
        public CallSafeHandle CreateCall(CompletionRegistry registry, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)
        {
            var result = grpcsharp_channel_create_call(this, parentCall, propagationMask, cq, method, host, deadline);

            result.SetCompletionRegistry(registry);
            return(result);
        }
Ejemplo n.º 38
0
 public CallSafeHandle CreateCall(CompletionRegistry registry, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)
 {
     var result = grpcsharp_channel_create_call(this, parentCall, propagationMask, cq, method, host, deadline);
     result.SetCompletionRegistry(registry);
     return result;
 }
Ejemplo n.º 39
0
        private INativeCall CreateNativeCall(CompletionQueueSafeHandle cq)
        {
            if (injectedNativeCall != null)
            {
                return(injectedNativeCall);  // allows injecting a mock INativeCall in tests.
            }

            var parentCall = details.Options.PropagationToken != null ? details.Options.PropagationToken.ParentCall : CallSafeHandle.NullInstance;

            var credentials = details.Options.Credentials;

            using (var nativeCredentials = credentials != null ? credentials.ToNativeCredentials() : null)
            {
                return(details.Channel.Handle.CreateCall(environment.CompletionRegistry,
                                                         parentCall, ContextPropagationToken.DefaultMask, cq,
                                                         details.Method, details.Host, Timespec.FromDateTime(details.Options.Deadline.Value), nativeCredentials));
            }
        }