Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: third_party/grpc/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #region Copyright notice and license
2
3 // Copyright 2015-2016, Google Inc.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 #endregion
33
34 using System;
35 using System.Runtime.InteropServices;
36 using Grpc.Core;
37
38 namespace Grpc.Core.Internal
39 {
40 /// <summary>
41 /// grpcsharp_batch_context
42 /// </summary>
43 internal class BatchContextSafeHandle : SafeHandleZeroIsInvalid
44 {
45 static readonly NativeMethods Native = NativeMethods.Get();
46
47 private BatchContextSafeHandle()
48 {
49 }
50
51 public static BatchContextSafeHandle Create()
52 {
53 return Native.grpcsharp_batch_context_create();
54 }
55
56 public IntPtr Handle
57 {
58 get
59 {
60 return handle;
61 }
62 }
63
64 // Gets data of recv_initial_metadata completion.
65 public Metadata GetReceivedInitialMetadata()
66 {
67 IntPtr metadataArrayPtr = Native.grpcsharp_batch_context_recv_initia l_metadata(this);
68 return MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(metadataArr ayPtr);
69 }
70
71 // Gets data of recv_status_on_client completion.
72 public ClientSideStatus GetReceivedStatusOnClient()
73 {
74 string details = Marshal.PtrToStringAnsi(Native.grpcsharp_batch_cont ext_recv_status_on_client_details(this));
75 var status = new Status(Native.grpcsharp_batch_context_recv_status_o n_client_status(this), details);
76
77 IntPtr metadataArrayPtr = Native.grpcsharp_batch_context_recv_status _on_client_trailing_metadata(this);
78 var metadata = MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(met adataArrayPtr);
79
80 return new ClientSideStatus(status, metadata);
81 }
82
83 // Gets data of recv_message completion.
84 public byte[] GetReceivedMessage()
85 {
86 IntPtr len = Native.grpcsharp_batch_context_recv_message_length(this );
87 if (len == new IntPtr(-1))
88 {
89 return null;
90 }
91 byte[] data = new byte[(int)len];
92 Native.grpcsharp_batch_context_recv_message_to_buffer(this, data, ne w UIntPtr((ulong)data.Length));
93 return data;
94 }
95
96 // Gets data of server_rpc_new completion.
97 public ServerRpcNew GetServerRpcNew(Server server)
98 {
99 var call = Native.grpcsharp_batch_context_server_rpc_new_call(this);
100
101 var method = Marshal.PtrToStringAnsi(Native.grpcsharp_batch_context_ server_rpc_new_method(this));
102 var host = Marshal.PtrToStringAnsi(Native.grpcsharp_batch_context_se rver_rpc_new_host(this));
103 var deadline = Native.grpcsharp_batch_context_server_rpc_new_deadlin e(this);
104
105 IntPtr metadataArrayPtr = Native.grpcsharp_batch_context_server_rpc_ new_request_metadata(this);
106 var metadata = MetadataArraySafeHandle.ReadMetadataFromPtrUnsafe(met adataArrayPtr);
107
108 return new ServerRpcNew(server, call, method, host, deadline, metada ta);
109 }
110
111 // Gets data of receive_close_on_server completion.
112 public bool GetReceivedCloseOnServerCancelled()
113 {
114 return Native.grpcsharp_batch_context_recv_close_on_server_cancelled (this) != 0;
115 }
116
117 protected override bool ReleaseHandle()
118 {
119 Native.grpcsharp_batch_context_destroy(handle);
120 return true;
121 }
122 }
123
124 /// <summary>
125 /// Status + metadata received on client side when call finishes.
126 /// (when receive_status_on_client operation finishes).
127 /// </summary>
128 internal struct ClientSideStatus
129 {
130 readonly Status status;
131 readonly Metadata trailers;
132
133 public ClientSideStatus(Status status, Metadata trailers)
134 {
135 this.status = status;
136 this.trailers = trailers;
137 }
138
139 public Status Status
140 {
141 get
142 {
143 return this.status;
144 }
145 }
146
147 public Metadata Trailers
148 {
149 get
150 {
151 return this.trailers;
152 }
153 }
154 }
155
156 /// <summary>
157 /// Details of a newly received RPC.
158 /// </summary>
159 internal struct ServerRpcNew
160 {
161 readonly Server server;
162 readonly CallSafeHandle call;
163 readonly string method;
164 readonly string host;
165 readonly Timespec deadline;
166 readonly Metadata requestMetadata;
167
168 public ServerRpcNew(Server server, CallSafeHandle call, string method, s tring host, Timespec deadline, Metadata requestMetadata)
169 {
170 this.server = server;
171 this.call = call;
172 this.method = method;
173 this.host = host;
174 this.deadline = deadline;
175 this.requestMetadata = requestMetadata;
176 }
177
178 public Server Server
179 {
180 get
181 {
182 return this.server;
183 }
184 }
185
186 public CallSafeHandle Call
187 {
188 get
189 {
190 return this.call;
191 }
192 }
193
194 public string Method
195 {
196 get
197 {
198 return this.method;
199 }
200 }
201
202 public string Host
203 {
204 get
205 {
206 return this.host;
207 }
208 }
209
210 public Timespec Deadline
211 {
212 get
213 {
214 return this.deadline;
215 }
216 }
217
218 public Metadata RequestMetadata
219 {
220 get
221 {
222 return this.requestMetadata;
223 }
224 }
225 }
226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698