Exemple #1
0
        public async Task HandleCall(string methodName, CallSafeHandle call, CompletionQueueSafeHandle cq)
        {
            var asyncCall = new AsyncCallServer <TRequest, TResponse>(
                method.ResponseMarshaller.Serializer,
                method.RequestMarshaller.Deserializer);

            asyncCall.Initialize(call);
            var finishedTask   = asyncCall.ServerSideCallAsync();
            var requestStream  = new ServerRequestStream <TRequest, TResponse>(asyncCall);
            var responseStream = new ServerResponseStream <TRequest, TResponse>(asyncCall);
            var context        = new ServerCallContext(); // TODO(jtattermusch): initialize the context

            Status status = Status.DefaultSuccess;

            try
            {
                await handler(context, requestStream, responseStream);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception occured in handler: " + e);
                status = HandlerUtils.StatusFromException(e);
            }
            try
            {
                await responseStream.WriteStatus(status);
            }
            catch (OperationCanceledException)
            {
                // Call has been already cancelled.
            }
            await finishedTask;
        }
Exemple #2
0
        public async Task HandleCall(string methodName, CallSafeHandle call, CompletionQueueSafeHandle cq)
        {
            // We don't care about the payload type here.
            var asyncCall = new AsyncCallServer <byte[], byte[]>(
                (payload) => payload, (payload) => payload);

            asyncCall.Initialize(call);
            var finishedTask   = asyncCall.ServerSideCallAsync();
            var requestStream  = new ServerRequestStream <byte[], byte[]>(asyncCall);
            var responseStream = new ServerResponseStream <byte[], byte[]>(asyncCall);

            await responseStream.WriteStatus(new Status(StatusCode.Unimplemented, "No such method."));

            // TODO(jtattermusch): if we don't read what client has sent, the server call never gets disposed.
            await requestStream.ToList();

            await finishedTask;
        }