Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
Jan Tattermusch | af77b3d | 2015-02-13 11:22:21 -0800 | [diff] [blame] | 3 | // Copyright 2015, Google Inc. |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 4 | // All rights reserved. |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 5 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 6 | // Redistribution and use in source and binary forms, with or without |
| 7 | // modification, are permitted provided that the following conditions are |
| 8 | // met: |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 9 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 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. |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 19 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 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 | |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 34 | using System; |
Jan Tattermusch | 7ca6179 | 2015-05-18 14:28:22 -0700 | [diff] [blame] | 35 | using System.Collections.Generic; |
Jan Tattermusch | a29d0f3 | 2015-03-04 17:54:56 -0800 | [diff] [blame] | 36 | using System.Linq; |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 37 | using System.Threading.Tasks; |
Jan Tattermusch | 3086862 | 2015-02-19 09:22:33 -0800 | [diff] [blame] | 38 | using Grpc.Core.Internal; |
Jan Tattermusch | a29d0f3 | 2015-03-04 17:54:56 -0800 | [diff] [blame] | 39 | using Grpc.Core.Utils; |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 40 | |
Jan Tattermusch | 286975f | 2015-03-12 14:04:36 -0700 | [diff] [blame] | 41 | namespace Grpc.Core.Internal |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 42 | { |
| 43 | internal interface IServerCallHandler |
| 44 | { |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 45 | Task HandleCall(string methodName, CallSafeHandle call, GrpcEnvironment environment); |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 46 | } |
| 47 | |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 48 | internal class UnaryServerCallHandler<TRequest, TResponse> : IServerCallHandler |
Jan Tattermusch | bdb1b48 | 2015-05-06 14:46:25 -0700 | [diff] [blame] | 49 | where TRequest : class |
| 50 | where TResponse : class |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 51 | { |
| 52 | readonly Method<TRequest, TResponse> method; |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 53 | readonly UnaryServerMethod<TRequest, TResponse> handler; |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 54 | |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 55 | public UnaryServerCallHandler(Method<TRequest, TResponse> method, UnaryServerMethod<TRequest, TResponse> handler) |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 56 | { |
| 57 | this.method = method; |
| 58 | this.handler = handler; |
| 59 | } |
| 60 | |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 61 | public async Task HandleCall(string methodName, CallSafeHandle call, GrpcEnvironment environment) |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 62 | { |
Jan Tattermusch | a29d0f3 | 2015-03-04 17:54:56 -0800 | [diff] [blame] | 63 | var asyncCall = new AsyncCallServer<TRequest, TResponse>( |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 64 | method.ResponseMarshaller.Serializer, |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 65 | method.RequestMarshaller.Deserializer, |
| 66 | environment); |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 67 | |
Jan Tattermusch | a29d0f3 | 2015-03-04 17:54:56 -0800 | [diff] [blame] | 68 | asyncCall.Initialize(call); |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 69 | var finishedTask = asyncCall.ServerSideCallAsync(); |
| 70 | var requestStream = new ServerRequestStream<TRequest, TResponse>(asyncCall); |
| 71 | var responseStream = new ServerResponseStream<TRequest, TResponse>(asyncCall); |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 72 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 73 | Status status = Status.DefaultSuccess; |
| 74 | try |
| 75 | { |
Jan Tattermusch | 7ca6179 | 2015-05-18 14:28:22 -0700 | [diff] [blame] | 76 | Preconditions.CheckArgument(await requestStream.MoveNext()); |
| 77 | var request = requestStream.Current; |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 78 | // TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated. |
Jan Tattermusch | 7ca6179 | 2015-05-18 14:28:22 -0700 | [diff] [blame] | 79 | Preconditions.CheckArgument(!await requestStream.MoveNext()); |
Jan Tattermusch | 8ab1f7e | 2015-05-06 15:56:30 -0700 | [diff] [blame] | 80 | var context = new ServerCallContext(); // TODO(jtattermusch): initialize the context |
| 81 | var result = await handler(context, request); |
Jan Tattermusch | 43dc50b | 2015-05-18 15:27:19 -0700 | [diff] [blame] | 82 | await responseStream.WriteAsync(result); |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 83 | } |
| 84 | catch (Exception e) |
| 85 | { |
| 86 | Console.WriteLine("Exception occured in handler: " + e); |
| 87 | status = HandlerUtils.StatusFromException(e); |
| 88 | } |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 89 | try |
| 90 | { |
Jan Tattermusch | 43dc50b | 2015-05-18 15:27:19 -0700 | [diff] [blame] | 91 | await responseStream.WriteStatusAsync(status); |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 92 | } |
| 93 | catch (OperationCanceledException) |
| 94 | { |
| 95 | // Call has been already cancelled. |
| 96 | } |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 97 | await finishedTask; |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 101 | internal class ServerStreamingServerCallHandler<TRequest, TResponse> : IServerCallHandler |
Jan Tattermusch | bdb1b48 | 2015-05-06 14:46:25 -0700 | [diff] [blame] | 102 | where TRequest : class |
| 103 | where TResponse : class |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 104 | { |
| 105 | readonly Method<TRequest, TResponse> method; |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 106 | readonly ServerStreamingServerMethod<TRequest, TResponse> handler; |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 107 | |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 108 | public ServerStreamingServerCallHandler(Method<TRequest, TResponse> method, ServerStreamingServerMethod<TRequest, TResponse> handler) |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 109 | { |
| 110 | this.method = method; |
| 111 | this.handler = handler; |
| 112 | } |
| 113 | |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 114 | public async Task HandleCall(string methodName, CallSafeHandle call, GrpcEnvironment environment) |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 115 | { |
Jan Tattermusch | a29d0f3 | 2015-03-04 17:54:56 -0800 | [diff] [blame] | 116 | var asyncCall = new AsyncCallServer<TRequest, TResponse>( |
Jan Tattermusch | 15111f5 | 2015-02-05 18:15:14 -0800 | [diff] [blame] | 117 | method.ResponseMarshaller.Serializer, |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 118 | method.RequestMarshaller.Deserializer, |
| 119 | environment); |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 120 | |
Jan Tattermusch | a29d0f3 | 2015-03-04 17:54:56 -0800 | [diff] [blame] | 121 | asyncCall.Initialize(call); |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 122 | var finishedTask = asyncCall.ServerSideCallAsync(); |
| 123 | var requestStream = new ServerRequestStream<TRequest, TResponse>(asyncCall); |
| 124 | var responseStream = new ServerResponseStream<TRequest, TResponse>(asyncCall); |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 125 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 126 | Status status = Status.DefaultSuccess; |
| 127 | try |
| 128 | { |
Jan Tattermusch | 7ca6179 | 2015-05-18 14:28:22 -0700 | [diff] [blame] | 129 | Preconditions.CheckArgument(await requestStream.MoveNext()); |
| 130 | var request = requestStream.Current; |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 131 | // TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated. |
Jan Tattermusch | 7ca6179 | 2015-05-18 14:28:22 -0700 | [diff] [blame] | 132 | Preconditions.CheckArgument(!await requestStream.MoveNext()); |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 133 | |
Jan Tattermusch | 8ab1f7e | 2015-05-06 15:56:30 -0700 | [diff] [blame] | 134 | var context = new ServerCallContext(); // TODO(jtattermusch): initialize the context |
| 135 | await handler(context, request, responseStream); |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 136 | } |
| 137 | catch (Exception e) |
| 138 | { |
| 139 | Console.WriteLine("Exception occured in handler: " + e); |
| 140 | status = HandlerUtils.StatusFromException(e); |
| 141 | } |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 142 | |
| 143 | try |
| 144 | { |
Jan Tattermusch | 43dc50b | 2015-05-18 15:27:19 -0700 | [diff] [blame] | 145 | await responseStream.WriteStatusAsync(status); |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 146 | } |
| 147 | catch (OperationCanceledException) |
| 148 | { |
| 149 | // Call has been already cancelled. |
| 150 | } |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 151 | await finishedTask; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | internal class ClientStreamingServerCallHandler<TRequest, TResponse> : IServerCallHandler |
Jan Tattermusch | bdb1b48 | 2015-05-06 14:46:25 -0700 | [diff] [blame] | 156 | where TRequest : class |
| 157 | where TResponse : class |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 158 | { |
| 159 | readonly Method<TRequest, TResponse> method; |
| 160 | readonly ClientStreamingServerMethod<TRequest, TResponse> handler; |
| 161 | |
| 162 | public ClientStreamingServerCallHandler(Method<TRequest, TResponse> method, ClientStreamingServerMethod<TRequest, TResponse> handler) |
| 163 | { |
| 164 | this.method = method; |
| 165 | this.handler = handler; |
| 166 | } |
| 167 | |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 168 | public async Task HandleCall(string methodName, CallSafeHandle call, GrpcEnvironment environment) |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 169 | { |
| 170 | var asyncCall = new AsyncCallServer<TRequest, TResponse>( |
| 171 | method.ResponseMarshaller.Serializer, |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 172 | method.RequestMarshaller.Deserializer, |
| 173 | environment); |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 174 | |
| 175 | asyncCall.Initialize(call); |
| 176 | var finishedTask = asyncCall.ServerSideCallAsync(); |
| 177 | var requestStream = new ServerRequestStream<TRequest, TResponse>(asyncCall); |
| 178 | var responseStream = new ServerResponseStream<TRequest, TResponse>(asyncCall); |
Jan Tattermusch | 8ab1f7e | 2015-05-06 15:56:30 -0700 | [diff] [blame] | 179 | var context = new ServerCallContext(); // TODO(jtattermusch): initialize the context |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 180 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 181 | Status status = Status.DefaultSuccess; |
| 182 | try |
| 183 | { |
Jan Tattermusch | 8ab1f7e | 2015-05-06 15:56:30 -0700 | [diff] [blame] | 184 | var result = await handler(context, requestStream); |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 185 | try |
| 186 | { |
Jan Tattermusch | 43dc50b | 2015-05-18 15:27:19 -0700 | [diff] [blame] | 187 | await responseStream.WriteAsync(result); |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 188 | } |
| 189 | catch (OperationCanceledException) |
| 190 | { |
| 191 | status = Status.DefaultCancelled; |
| 192 | } |
| 193 | } |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 194 | catch (Exception e) |
| 195 | { |
| 196 | Console.WriteLine("Exception occured in handler: " + e); |
| 197 | status = HandlerUtils.StatusFromException(e); |
| 198 | } |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 199 | |
| 200 | try |
| 201 | { |
Jan Tattermusch | 43dc50b | 2015-05-18 15:27:19 -0700 | [diff] [blame] | 202 | await responseStream.WriteStatusAsync(status); |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 203 | } |
| 204 | catch (OperationCanceledException) |
| 205 | { |
| 206 | // Call has been already cancelled. |
| 207 | } |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 208 | await finishedTask; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | internal class DuplexStreamingServerCallHandler<TRequest, TResponse> : IServerCallHandler |
Jan Tattermusch | bdb1b48 | 2015-05-06 14:46:25 -0700 | [diff] [blame] | 213 | where TRequest : class |
| 214 | where TResponse : class |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 215 | { |
| 216 | readonly Method<TRequest, TResponse> method; |
| 217 | readonly DuplexStreamingServerMethod<TRequest, TResponse> handler; |
| 218 | |
| 219 | public DuplexStreamingServerCallHandler(Method<TRequest, TResponse> method, DuplexStreamingServerMethod<TRequest, TResponse> handler) |
| 220 | { |
| 221 | this.method = method; |
| 222 | this.handler = handler; |
| 223 | } |
| 224 | |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 225 | public async Task HandleCall(string methodName, CallSafeHandle call, GrpcEnvironment environment) |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 226 | { |
| 227 | var asyncCall = new AsyncCallServer<TRequest, TResponse>( |
| 228 | method.ResponseMarshaller.Serializer, |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 229 | method.RequestMarshaller.Deserializer, |
| 230 | environment); |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 231 | |
| 232 | asyncCall.Initialize(call); |
| 233 | var finishedTask = asyncCall.ServerSideCallAsync(); |
| 234 | var requestStream = new ServerRequestStream<TRequest, TResponse>(asyncCall); |
| 235 | var responseStream = new ServerResponseStream<TRequest, TResponse>(asyncCall); |
Jan Tattermusch | 8ab1f7e | 2015-05-06 15:56:30 -0700 | [diff] [blame] | 236 | var context = new ServerCallContext(); // TODO(jtattermusch): initialize the context |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 237 | |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 238 | Status status = Status.DefaultSuccess; |
| 239 | try |
| 240 | { |
Jan Tattermusch | 8ab1f7e | 2015-05-06 15:56:30 -0700 | [diff] [blame] | 241 | await handler(context, requestStream, responseStream); |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 242 | } |
| 243 | catch (Exception e) |
| 244 | { |
| 245 | Console.WriteLine("Exception occured in handler: " + e); |
| 246 | status = HandlerUtils.StatusFromException(e); |
| 247 | } |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 248 | try |
| 249 | { |
Jan Tattermusch | 43dc50b | 2015-05-18 15:27:19 -0700 | [diff] [blame] | 250 | await responseStream.WriteStatusAsync(status); |
Jan Tattermusch | 8c2dd9d | 2015-05-04 09:20:43 -0700 | [diff] [blame] | 251 | } |
| 252 | catch (OperationCanceledException) |
| 253 | { |
| 254 | // Call has been already cancelled. |
| 255 | } |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 256 | await finishedTask; |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | internal class NoSuchMethodCallHandler : IServerCallHandler |
| 261 | { |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 262 | public async Task HandleCall(string methodName, CallSafeHandle call, GrpcEnvironment environment) |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 263 | { |
| 264 | // We don't care about the payload type here. |
Jan Tattermusch | a29d0f3 | 2015-03-04 17:54:56 -0800 | [diff] [blame] | 265 | var asyncCall = new AsyncCallServer<byte[], byte[]>( |
Jan Tattermusch | 04eb89c | 2015-06-12 13:03:05 -0700 | [diff] [blame] | 266 | (payload) => payload, (payload) => payload, environment); |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 267 | |
Jan Tattermusch | a29d0f3 | 2015-03-04 17:54:56 -0800 | [diff] [blame] | 268 | asyncCall.Initialize(call); |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 269 | var finishedTask = asyncCall.ServerSideCallAsync(); |
| 270 | var requestStream = new ServerRequestStream<byte[], byte[]>(asyncCall); |
| 271 | var responseStream = new ServerResponseStream<byte[], byte[]>(asyncCall); |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 272 | |
Jan Tattermusch | 43dc50b | 2015-05-18 15:27:19 -0700 | [diff] [blame] | 273 | await responseStream.WriteStatusAsync(new Status(StatusCode.Unimplemented, "No such method.")); |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 274 | await finishedTask; |
Jan Tattermusch | 37afb9a | 2015-02-18 11:20:04 -0800 | [diff] [blame] | 275 | } |
Jan Tattermusch | 37afb9a | 2015-02-18 11:20:04 -0800 | [diff] [blame] | 276 | } |
Jan Tattermusch | e5c4460 | 2015-05-01 11:12:34 -0700 | [diff] [blame] | 277 | |
| 278 | internal static class HandlerUtils |
| 279 | { |
| 280 | public static Status StatusFromException(Exception e) |
| 281 | { |
| 282 | // TODO(jtattermusch): what is the right status code here? |
| 283 | return new Status(StatusCode.Unknown, "Exception was thrown by handler."); |
| 284 | } |
| 285 | } |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 286 | } |