Esempio n. 1
0
        /// <summary>
        /// Handler for unary response completion.
        /// </summary>
        private void HandleUnaryResponse(bool wasError, BatchContextSafeHandleNotOwned ctx)
        {
            lock (myLock)
            {
                finished   = true;
                halfclosed = true;

                ReleaseResourcesIfPossible();
            }

            if (wasError)
            {
                unaryResponseTcs.SetException(new RpcException(new Status(StatusCode.Internal, "Internal error occured.")));
                return;
            }

            var status = ctx.GetReceivedStatus();

            if (status.StatusCode != StatusCode.OK)
            {
                unaryResponseTcs.SetException(new RpcException(status));
                return;
            }

            // TODO: handle deserialization error
            TResponse msg;

            TryDeserialize(ctx.GetReceivedMessage(), out msg);

            unaryResponseTcs.SetResult(msg);
        }
Esempio n. 2
0
        private void HandleFinished(GRPCOpError error, IntPtr batchContextPtr)
        {
            try
            {
                var ctx    = new BatchContextSafeHandleNotOwned(batchContextPtr);
                var status = ctx.GetReceivedStatus();

                bool wasReadingDone;

                lock (myLock)
                {
                    finished       = true;
                    finishedStatus = status;

                    wasReadingDone = readingDone;

                    ReleaseResourcesIfPossible();
                }

                if (wasReadingDone)
                {
                    CompleteStreamObserver(status);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception in a native handler: " + e);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Handles receive status completion for calls with streaming response.
        /// </summary>
        private void HandleFinished(bool wasError, BatchContextSafeHandleNotOwned ctx)
        {
            var status = ctx.GetReceivedStatus();

            lock (myLock)
            {
                finished       = true;
                finishedStatus = status;

                ReleaseResourcesIfPossible();
            }

            CompleteReadObserver();
        }
Esempio n. 4
0
        /// <summary>
        /// Handles receive status completion for calls with streaming response.
        /// </summary>
        private void HandleFinished(bool wasError, BatchContextSafeHandleNotOwned ctx)
        {
            var status = ctx.GetReceivedStatus();

            AsyncCompletionDelegate <TResponse> origReadCompletionDelegate = null;

            lock (myLock)
            {
                finished       = true;
                finishedStatus = status;

                origReadCompletionDelegate = readCompletionDelegate;

                ReleaseResourcesIfPossible();
            }

            ProcessLastRead(origReadCompletionDelegate);
        }
Esempio n. 5
0
        /// <summary>
        /// Handler for unary response completion.
        /// </summary>
        private void HandleUnaryResponse(GRPCOpError error, IntPtr batchContextPtr)
        {
            try
            {
                TaskCompletionSource <TRead> tcs;
                lock (myLock)
                {
                    finished   = true;
                    halfclosed = true;
                    tcs        = unaryResponseTcs;

                    ReleaseResourcesIfPossible();
                }

                var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);

                if (error != GRPCOpError.GRPC_OP_OK)
                {
                    tcs.SetException(new RpcException(
                                         new Status(StatusCode.Internal, "Internal error occured.")
                                         ));
                    return;
                }

                var status = ctx.GetReceivedStatus();
                if (status.StatusCode != StatusCode.OK)
                {
                    tcs.SetException(new RpcException(status));
                    return;
                }

                // TODO: handle deserialize error...
                var msg = deserializer(ctx.GetReceivedMessage());
                tcs.SetResult(msg);
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception in a native handler: " + e);
            }
        }