예제 #1
0
        /// <summary>
        /// Handles the native callback.
        /// </summary>
        private void HandleNewServerRpc(bool success, RequestCallContextSafeHandle ctx, CompletionQueueSafeHandle cq)
        {
            bool nextRpcRequested = false;

            if (success)
            {
                var newRpc = ctx.GetServerRpcNew(this);

                // after server shutdown, the callback returns with null call
                if (!newRpc.Call.IsInvalid)
                {
                    nextRpcRequested = true;

                    // Start asynchronous handler for the call.
                    // Don't await, the continuations will run on gRPC thread pool once triggered
                    // by cq.Next().
                    #pragma warning disable 4014
                    HandleCallAsync(newRpc, cq, (server, state) => server.AllowOneRpc(state));
                    #pragma warning restore 4014
                }
            }

            if (!nextRpcRequested)
            {
                AllowOneRpc(cq);
            }
        }
예제 #2
0
 public void RequestCall(RequestCallCompletionDelegate callback, CompletionQueueSafeHandle completionQueue)
 {
     using (completionQueue.NewScope())
     {
         var ctx = RequestCallContextSafeHandle.Create();
         completionQueue.CompletionRegistry.RegisterRequestCallCompletion(ctx, callback);
         Native.grpcsharp_server_request_call(this, completionQueue, ctx).CheckOk();
     }
 }
예제 #3
0
 /// <summary>
 /// Creates gRPC environment.
 /// </summary>
 private GrpcEnvironment()
 {
     GrpcNativeInit();
     batchContextPool       = new DefaultObjectPool <BatchContextSafeHandle>(() => BatchContextSafeHandle.Create(this.batchContextPool), batchContextPoolSharedCapacity, batchContextPoolThreadLocalCapacity);
     requestCallContextPool = new DefaultObjectPool <RequestCallContextSafeHandle>(() => RequestCallContextSafeHandle.Create(this.requestCallContextPool), requestCallContextPoolSharedCapacity, requestCallContextPoolThreadLocalCapacity);
     threadPool             = new GrpcThreadPool(this, GetThreadPoolSizeOrDefault(), GetCompletionQueueCountOrDefault(), inlineHandlers);
     threadPool.Start();
 }
        public void CreateAsyncAndShutdown()
        {
            var env = GrpcEnvironment.AddRef();
            var cq  = CompletionQueueSafeHandle.CreateAsync(new CompletionRegistry(env, () => BatchContextSafeHandle.Create(), () => RequestCallContextSafeHandle.Create()));

            cq.Shutdown();
            var ev = cq.Next();

            cq.Dispose();
            GrpcEnvironment.ReleaseAsync().Wait();
            Assert.AreEqual(CompletionQueueEvent.CompletionType.Shutdown, ev.type);
            Assert.AreNotEqual(IntPtr.Zero, ev.success);
        }
 public void RegisterExtract()
 {
     RunConcurrent(() => {
         CompletionRegistry sharedRegistry = UseSharedRegistry ? new CompletionRegistry(Environment, () => BatchContextSafeHandle.Create(), () => RequestCallContextSafeHandle.Create()) : null;
         RunBody(sharedRegistry);
     });
 }
        public void Run(int threadCount, int iterations, bool useSharedRegistry)
        {
            Console.WriteLine(string.Format("CompletionRegistryBenchmark: threads={0}, iterations={1}, useSharedRegistry={2}", threadCount, iterations, useSharedRegistry));
            CompletionRegistry sharedRegistry = useSharedRegistry ? new CompletionRegistry(environment, () => BatchContextSafeHandle.Create(), () => RequestCallContextSafeHandle.Create()) : null;
            var threadedBenchmark             = new ThreadedBenchmark(threadCount, () => ThreadBody(iterations, sharedRegistry));

            threadedBenchmark.Run();
            // TODO: parametrize by number of pending completions
        }