• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 // Copyright 2015 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 #endregion
16 using System;
17 using System.Runtime.InteropServices;
18 using System.Threading.Tasks;
19 
20 namespace Grpc.Core.Internal
21 {
22     /// <summary>
23     /// grpc_channel_args from <c>grpc/grpc.h</c>
24     /// </summary>
25     internal class ChannelArgsSafeHandle : SafeHandleZeroIsInvalid
26     {
27         static readonly NativeMethods Native = NativeMethods.Get();
28 
ChannelArgsSafeHandle()29         private ChannelArgsSafeHandle()
30         {
31         }
32 
CreateNull()33         public static ChannelArgsSafeHandle CreateNull()
34         {
35             return new ChannelArgsSafeHandle();
36         }
37 
Create(int size)38         public static ChannelArgsSafeHandle Create(int size)
39         {
40             return Native.grpcsharp_channel_args_create(new UIntPtr((uint)size));
41         }
42 
SetString(int index, string key, string value)43         public void SetString(int index, string key, string value)
44         {
45             Native.grpcsharp_channel_args_set_string(this, new UIntPtr((uint)index), key, value);
46         }
47 
SetInteger(int index, string key, int value)48         public void SetInteger(int index, string key, int value)
49         {
50             Native.grpcsharp_channel_args_set_integer(this, new UIntPtr((uint)index), key, value);
51         }
52 
ReleaseHandle()53         protected override bool ReleaseHandle()
54         {
55             Native.grpcsharp_channel_args_destroy(handle);
56             return true;
57         }
58     }
59 }
60