コード例 #1
0
        private void HandleFinishedServerside(GRPCOpError error, IntPtr batchContextPtr)
        {
            try
            {
                var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);

                lock (myLock)
                {
                    finished = true;

                    // TODO: because of the way server calls are implemented, we need to set
                    // reading done to true here. Should be fixed in the future.
                    readingDone = true;

                    ReleaseResourcesIfPossible();
                }
                // TODO: handle error ...

                finishedServersideTcs.SetResult(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception in a native handler: " + e);
            }
        }
コード例 #2
0
ファイル: AsyncCall.cs プロジェクト: varung/grpc
        /// <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);
        }
コード例 #3
0
ファイル: AsyncCallBase.cs プロジェクト: wfarr/grpc
        /// <summary>
        /// Handles streaming read completion.
        /// </summary>
        private void HandleReadFinished(bool wasError, BatchContextSafeHandleNotOwned ctx)
        {
            var payload = ctx.GetReceivedMessage();

            lock (myLock)
            {
                readPending = false;
                if (payload == null)
                {
                    readingDone = true;
                }

                ReleaseResourcesIfPossible();
            }

            // TODO: handle the case when error occured...

            if (payload != null)
            {
                // TODO: handle deserialization error
                TRead msg;
                TryDeserialize(payload, out msg);

                FireReadObserverOnNext(msg);

                // Start a new read. The current one has already been delivered,
                // so correct ordering of reads is assured.
                StartReceiveMessage();
            }
            else
            {
                CompleteReadObserver();
            }
        }
コード例 #4
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);
            }
        }
コード例 #5
0
ファイル: AsyncCallServer.cs プロジェクト: wfarr/grpc
        /// <summary>
        /// Handles the server side close completion.
        /// </summary>
        private void HandleFinishedServerside(bool wasError, BatchContextSafeHandleNotOwned ctx)
        {
            lock (myLock)
            {
                finished = true;

                ReleaseResourcesIfPossible();
            }
            // TODO: handle error ...

            finishedServersideTcs.SetResult(null);
        }
コード例 #6
0
ファイル: AsyncCall.cs プロジェクト: wfarr/grpc
        /// <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();
        }
コード例 #7
0
ファイル: AsyncCallBase.cs プロジェクト: mway08/grpc
 /// <summary>
 /// Creates completion callback delegate that wraps the batch completion handler in a try catch block to
 /// prevent propagating exceptions accross managed/unmanaged boundary.
 /// </summary>
 protected CompletionCallbackDelegate CreateBatchCompletionCallback(Action <bool, BatchContextSafeHandleNotOwned> handler)
 {
     return(new CompletionCallbackDelegate((success, batchContextPtr) =>
     {
         try
         {
             var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);
             handler(success, ctx);
         }
         catch (Exception e)
         {
             Console.WriteLine("Caught exception in a native handler: " + e);
         }
     }));
 }
コード例 #8
0
ファイル: AsyncCallBase.cs プロジェクト: wfarr/grpc
 /// <summary>
 /// Creates completion callback delegate that wraps the batch completion handler in a try catch block to
 /// prevent propagating exceptions accross managed/unmanaged boundary.
 /// </summary>
 protected CompletionCallbackDelegate CreateBatchCompletionCallback(Action <bool, BatchContextSafeHandleNotOwned> handler)
 {
     return(new CompletionCallbackDelegate((error, batchContextPtr) =>
     {
         try
         {
             var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);
             bool wasError = (error != GRPCOpError.GRPC_OP_OK);
             handler(wasError, ctx);
         }
         catch (Exception e)
         {
             Console.WriteLine("Caught exception in a native handler: " + e);
         }
     }));
 }
コード例 #9
0
ファイル: AsyncCall.cs プロジェクト: varung/grpc
        /// <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);
        }
コード例 #10
0
        /// <summary>
        /// Handles the server side close completion.
        /// </summary>
        private void HandleFinishedServerside(bool success, BatchContextSafeHandleNotOwned ctx)
        {
            bool cancelled = ctx.GetReceivedCloseOnServerCancelled();

            lock (myLock)
            {
                finished = true;

                if (cancelled)
                {
                    // Once we cancel, we don't have to care that much
                    // about reads and writes.
                    Cancel();
                }

                ReleaseResourcesIfPossible();
            }
            // TODO(jtattermusch): handle error

            finishedServersideTcs.SetResult(null);
        }
コード例 #11
0
ファイル: AsyncCallBase.cs プロジェクト: mway08/grpc
        /// <summary>
        /// Handles send completion.
        /// </summary>
        private void HandleSendFinished(bool success, BatchContextSafeHandleNotOwned ctx)
        {
            AsyncCompletionDelegate <object> origCompletionDelegate = null;

            lock (myLock)
            {
                origCompletionDelegate = sendCompletionDelegate;
                sendCompletionDelegate = null;

                ReleaseResourcesIfPossible();
            }

            if (!success)
            {
                FireCompletion(origCompletionDelegate, null, new OperationFailedException("Send failed"));
            }
            else
            {
                FireCompletion(origCompletionDelegate, null, null);
            }
        }
コード例 #12
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);
            }
        }
コード例 #13
0
ファイル: AsyncCallBase.cs プロジェクト: mway08/grpc
        /// <summary>
        /// Handles streaming read completion.
        /// </summary>
        private void HandleReadFinished(bool success, BatchContextSafeHandleNotOwned ctx)
        {
            var payload = ctx.GetReceivedMessage();

            AsyncCompletionDelegate <TRead> origCompletionDelegate = null;

            lock (myLock)
            {
                origCompletionDelegate = readCompletionDelegate;
                if (payload != null)
                {
                    readCompletionDelegate = null;
                }
                else
                {
                    // This was the last read. Keeping the readCompletionDelegate
                    // to be either fired by this handler or by client-side finished
                    // handler.
                    readingDone = true;
                }

                ReleaseResourcesIfPossible();
            }

            // TODO: handle the case when error occured...

            if (payload != null)
            {
                // TODO: handle deserialization error
                TRead msg;
                TryDeserialize(payload, out msg);

                FireCompletion(origCompletionDelegate, msg, null);
            }
            else
            {
                ProcessLastRead(origCompletionDelegate);
            }
        }
コード例 #14
0
ファイル: AsyncCallBase.cs プロジェクト: wfarr/grpc
        /// <summary>
        /// Handles halfclose completion.
        /// </summary>
        private void HandleHalfclosed(bool wasError, BatchContextSafeHandleNotOwned ctx)
        {
            AsyncCompletionDelegate origCompletionDelegate = null;

            lock (myLock)
            {
                halfclosed             = true;
                origCompletionDelegate = sendCompletionDelegate;
                sendCompletionDelegate = null;

                ReleaseResourcesIfPossible();
            }

            if (wasError)
            {
                FireCompletion(origCompletionDelegate, new OperationFailedException("Halfclose failed"));
            }
            else
            {
                FireCompletion(origCompletionDelegate, null);
            }
        }
コード例 #15
0
ファイル: Server.cs プロジェクト: mway08/grpc
        /// <summary>
        /// Handles the native callback.
        /// </summary>
        private void HandleNewServerRpc(bool success, IntPtr batchContextPtr)
        {
            try
            {
                var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);

                // TODO: handle error

                CallSafeHandle call = ctx.GetServerRpcNewCall();
                string method = ctx.GetServerRpcNewMethod();

                // after server shutdown, the callback returns with null call
                if (!call.IsInvalid)
                {
                    Task.Run(async () => await InvokeCallHandler(call, method));
                }

                AllowOneRpc();
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception in a native handler: " + e);
            }
        }
コード例 #16
0
 static extern StatusCode grpcsharp_batch_context_recv_status_on_client_status(BatchContextSafeHandleNotOwned ctx);
コード例 #17
0
 static extern IntPtr grpcsharp_batch_context_recv_status_on_client_details(BatchContextSafeHandleNotOwned ctx);  // returns const char*
コード例 #18
0
 static extern StatusCode grpcsharp_batch_context_recv_status_on_client_status(BatchContextSafeHandleNotOwned ctx);
コード例 #19
0
 static extern IntPtr grpcsharp_batch_context_recv_status_on_client_details(BatchContextSafeHandleNotOwned ctx);
コード例 #20
0
 static extern int grpcsharp_batch_context_recv_close_on_server_cancelled(BatchContextSafeHandleNotOwned ctx);
コード例 #21
0
 static extern IntPtr grpcsharp_batch_context_server_rpc_new_method(BatchContextSafeHandleNotOwned ctx);
コード例 #22
0
 static extern CallSafeHandle grpcsharp_batch_context_server_rpc_new_call(BatchContextSafeHandleNotOwned ctx);
コード例 #23
0
 static extern CallSafeHandle grpcsharp_batch_context_server_rpc_new_call(BatchContextSafeHandleNotOwned ctx);
コード例 #24
0
        private void HandleReadFinished(GRPCOpError error, IntPtr batchContextPtr)
        {
            try
            {
                var ctx     = new BatchContextSafeHandleNotOwned(batchContextPtr);
                var payload = ctx.GetReceivedMessage();

                TaskCompletionSource <TRead> oldTcs   = null;
                IObserver <TRead>            observer = null;

                Nullable <Status> status = null;

                lock (myLock)
                {
                    oldTcs  = readTcs;
                    readTcs = null;
                    if (payload == null)
                    {
                        readingDone = true;
                    }
                    observer = readObserver;
                    status   = finishedStatus;

                    ReleaseResourcesIfPossible();
                }

                // TODO: wrap deserialization...
                TRead msg = payload != null?deserializer(payload) : default(TRead);

                oldTcs.SetResult(msg);

                // TODO: make sure we deliver reads in the right order.

                if (observer != null)
                {
                    if (payload != null)
                    {
                        // TODO: wrap to handle exceptions
                        observer.OnNext(msg);

                        // start a new read
                        ReceiveMessageAsync();
                    }
                    else
                    {
                        if (!server)
                        {
                            if (status.HasValue)
                            {
                                CompleteStreamObserver(status.Value);
                            }
                        }
                        else
                        {
                            // TODO: wrap to handle exceptions..
                            observer.OnCompleted();
                        }
                        // TODO: completeStreamObserver serverside...
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception in a native handler: " + e);
            }
        }
コード例 #25
0
 static extern int grpcsharp_batch_context_recv_close_on_server_cancelled(BatchContextSafeHandleNotOwned ctx);
コード例 #26
0
 static extern void grpcsharp_batch_context_recv_message_to_buffer(BatchContextSafeHandleNotOwned ctx, byte[] buffer, UIntPtr bufferLen);
コード例 #27
0
 static extern IntPtr grpcsharp_batch_context_recv_message_length(BatchContextSafeHandleNotOwned ctx);
コード例 #28
0
 static extern IntPtr grpcsharp_batch_context_recv_message_length(BatchContextSafeHandleNotOwned ctx);
コード例 #29
0
 static extern void grpcsharp_batch_context_recv_message_to_buffer(BatchContextSafeHandleNotOwned ctx, byte[] buffer, UIntPtr bufferLen);
コード例 #30
0
ファイル: Server.cs プロジェクト: jwatt/kythe
        private void HandleNewServerRpc(GRPCOpError error, IntPtr batchContextPtr)
        {
            try
            {
                var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);

                if (error != GRPCOpError.GRPC_OP_OK)
                {
                    // TODO: handle error
                }

                var rpcInfo = new NewRpcInfo(ctx.GetServerRpcNewCall(), ctx.GetServerRpcNewMethod());

                // after server shutdown, the callback returns with null call
                if (!rpcInfo.Call.IsInvalid)
                {
                    newRpcQueue.Add(rpcInfo);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Caught exception in a native handler: " + e);
            }
        }
コード例 #31
0
 static extern IntPtr grpcsharp_batch_context_server_rpc_new_method(BatchContextSafeHandleNotOwned ctx);  // returns const char*