Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 1 | #region Copyright notice and license |
Jan Tattermusch | af77b3d | 2015-02-13 11:22:21 -0800 | [diff] [blame] | 2 | // Copyright 2015, Google Inc. |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 3 | // All rights reserved. |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 4 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 8 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 18 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | #endregion |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 32 | using System; |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 33 | using System.Diagnostics; |
Jan Tattermusch | 3086862 | 2015-02-19 09:22:33 -0800 | [diff] [blame] | 34 | using System.Runtime.InteropServices; |
| 35 | using Grpc.Core; |
Jan Tattermusch | 97e294a | 2015-04-23 14:30:59 -0700 | [diff] [blame] | 36 | using Grpc.Core.Utils; |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 37 | |
Jan Tattermusch | 3086862 | 2015-02-19 09:22:33 -0800 | [diff] [blame] | 38 | namespace Grpc.Core.Internal |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 39 | { |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 40 | /// <summary> |
| 41 | /// grpc_call from <grpc/grpc.h> |
| 42 | /// </summary> |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 43 | internal class CallSafeHandle : SafeHandleZeroIsInvalid |
| 44 | { |
Jan Tattermusch | 075dde4 | 2015-03-11 18:21:00 -0700 | [diff] [blame] | 45 | const uint GRPC_WRITE_BUFFER_HINT = 1; |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 46 | CompletionRegistry completionRegistry; |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 47 | |
Jan Tattermusch | e1e1187 | 2015-02-12 10:23:37 -0800 | [diff] [blame] | 48 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | e1e1187 | 2015-02-12 10:23:37 -0800 | [diff] [blame] | 49 | static extern GRPCCallError grpcsharp_call_cancel(CallSafeHandle call); |
| 50 | |
| 51 | [DllImport("grpc_csharp_ext.dll")] |
| 52 | static extern GRPCCallError grpcsharp_call_cancel_with_status(CallSafeHandle call, StatusCode status, string description); |
| 53 | |
| 54 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 55 | static extern GRPCCallError grpcsharp_call_start_unary(CallSafeHandle call, |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 56 | BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 57 | |
| 58 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 59 | static extern GRPCCallError grpcsharp_call_start_client_streaming(CallSafeHandle call, |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 60 | BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
Jan Tattermusch | e1e1187 | 2015-02-12 10:23:37 -0800 | [diff] [blame] | 61 | |
| 62 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 63 | static extern GRPCCallError grpcsharp_call_start_server_streaming(CallSafeHandle call, |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 64 | BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len, |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 65 | MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
Jan Tattermusch | e1e1187 | 2015-02-12 10:23:37 -0800 | [diff] [blame] | 66 | |
| 67 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 68 | static extern GRPCCallError grpcsharp_call_start_duplex_streaming(CallSafeHandle call, |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 69 | BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 70 | |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 71 | [DllImport("grpc_csharp_ext.dll")] |
| 72 | static extern GRPCCallError grpcsharp_call_send_message(CallSafeHandle call, |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 73 | BatchContextSafeHandle ctx, byte[] send_buffer, UIntPtr send_buffer_len, WriteFlags writeFlags); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 74 | |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 75 | [DllImport("grpc_csharp_ext.dll")] |
| 76 | static extern GRPCCallError grpcsharp_call_send_close_from_client(CallSafeHandle call, |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 77 | BatchContextSafeHandle ctx, WriteFlags writeFlags); |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 78 | |
| 79 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 80 | static extern GRPCCallError grpcsharp_call_send_status_from_server(CallSafeHandle call, |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 81 | BatchContextSafeHandle ctx, StatusCode statusCode, string statusMessage, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 82 | |
| 83 | [DllImport("grpc_csharp_ext.dll")] |
| 84 | static extern GRPCCallError grpcsharp_call_recv_message(CallSafeHandle call, |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 85 | BatchContextSafeHandle ctx); |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 86 | |
| 87 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 88 | static extern GRPCCallError grpcsharp_call_start_serverside(CallSafeHandle call, |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 89 | BatchContextSafeHandle ctx); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 90 | |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 91 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 92 | static extern GRPCCallError grpcsharp_call_send_initial_metadata(CallSafeHandle call, |
| 93 | BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags); |
| 94 | |
| 95 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | 062c329 | 2015-07-23 20:28:42 -0700 | [diff] [blame] | 96 | static extern CStringSafeHandle grpcsharp_call_get_peer(CallSafeHandle call); |
| 97 | |
| 98 | [DllImport("grpc_csharp_ext.dll")] |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 99 | static extern void grpcsharp_call_destroy(IntPtr call); |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 100 | |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 101 | private CallSafeHandle() |
| 102 | { |
| 103 | } |
| 104 | |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 105 | public void SetCompletionRegistry(CompletionRegistry completionRegistry) |
| 106 | { |
| 107 | this.completionRegistry = completionRegistry; |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 110 | public void StartUnary(BatchCompletionDelegate callback, byte[] payload, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags) |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 111 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 112 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 113 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 114 | grpcsharp_call_start_unary(this, ctx, payload, new UIntPtr((ulong)payload.Length), metadataArray, writeFlags) |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 115 | .CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 118 | public void StartUnary(BatchContextSafeHandle ctx, byte[] payload, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags) |
Jan Tattermusch | 50faa8f | 2015-02-21 17:51:52 -0800 | [diff] [blame] | 119 | { |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 120 | grpcsharp_call_start_unary(this, ctx, payload, new UIntPtr((ulong)payload.Length), metadataArray, writeFlags) |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 121 | .CheckOk(); |
Jan Tattermusch | 50faa8f | 2015-02-21 17:51:52 -0800 | [diff] [blame] | 122 | } |
| 123 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 124 | public void StartClientStreaming(BatchCompletionDelegate callback, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags) |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 125 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 126 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 127 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 128 | grpcsharp_call_start_client_streaming(this, ctx, metadataArray, writeFlags).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 131 | public void StartServerStreaming(BatchCompletionDelegate callback, byte[] payload, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags) |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 132 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 133 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 134 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 135 | grpcsharp_call_start_server_streaming(this, ctx, payload, new UIntPtr((ulong)payload.Length), metadataArray, writeFlags).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 138 | public void StartDuplexStreaming(BatchCompletionDelegate callback, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags) |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 139 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 140 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 141 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 142 | grpcsharp_call_start_duplex_streaming(this, ctx, metadataArray, writeFlags).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 145 | public void StartSendMessage(BatchCompletionDelegate callback, byte[] payload, WriteFlags writeFlags) |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 146 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 147 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 148 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 149 | grpcsharp_call_send_message(this, ctx, payload, new UIntPtr((ulong)payload.Length), writeFlags).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 152 | public void StartSendCloseFromClient(BatchCompletionDelegate callback, WriteFlags writeFlags) |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 153 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 154 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 155 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 156 | grpcsharp_call_send_close_from_client(this, ctx, writeFlags).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 157 | } |
| 158 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 159 | public void StartSendStatusFromServer(BatchCompletionDelegate callback, Status status, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags) |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 160 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 161 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 162 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 163 | grpcsharp_call_send_status_from_server(this, ctx, status.StatusCode, status.Detail, metadataArray, writeFlags).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 166 | public void StartReceiveMessage(BatchCompletionDelegate callback) |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 167 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 168 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 169 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 170 | grpcsharp_call_recv_message(this, ctx).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 173 | public void StartServerSide(BatchCompletionDelegate callback) |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 174 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 175 | var ctx = BatchContextSafeHandle.Create(); |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 176 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 177 | grpcsharp_call_start_serverside(this, ctx).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Jan Tattermusch | bff90ac | 2015-08-06 21:30:26 -0700 | [diff] [blame^] | 180 | public void SendInitialMetadata(BatchCompletionDelegate callback, MetadataArraySafeHandle metadataArray, WriteFlags writeFlags) |
| 181 | { |
| 182 | var ctx = BatchContextSafeHandle.Create(); |
| 183 | completionRegistry.RegisterBatchCompletion(ctx, callback); |
| 184 | grpcsharp_call_send_initial_metadata(this, ctx, metadataArray, writeFlags).CheckOk(); |
| 185 | } |
| 186 | |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 187 | public void Cancel() |
| 188 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 189 | grpcsharp_call_cancel(this).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | public void CancelWithStatus(Status status) |
| 193 | { |
Jan Tattermusch | d367748 | 2015-06-01 19:27:40 -0700 | [diff] [blame] | 194 | grpcsharp_call_cancel_with_status(this, status.StatusCode, status.Detail).CheckOk(); |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Jan Tattermusch | 062c329 | 2015-07-23 20:28:42 -0700 | [diff] [blame] | 197 | public string GetPeer() |
| 198 | { |
| 199 | using (var cstring = grpcsharp_call_get_peer(this)) |
| 200 | { |
| 201 | return cstring.GetValue(); |
| 202 | } |
| 203 | } |
| 204 | |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 205 | protected override bool ReleaseHandle() |
| 206 | { |
Jan Tattermusch | e1e1187 | 2015-02-12 10:23:37 -0800 | [diff] [blame] | 207 | grpcsharp_call_destroy(handle); |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 208 | return true; |
| 209 | } |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 210 | |
Jan Tattermusch | 075dde4 | 2015-03-11 18:21:00 -0700 | [diff] [blame] | 211 | private static uint GetFlags(bool buffered) |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 212 | { |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 213 | return buffered ? 0 : GRPC_WRITE_BUFFER_HINT; |
| 214 | } |
Jan Tattermusch | 13cd125 | 2015-03-06 10:11:50 -0800 | [diff] [blame] | 215 | } |
Jan Tattermusch | 337a2dd | 2015-02-13 15:41:41 -0800 | [diff] [blame] | 216 | } |