Example #1
0
        internal void ReadRequest(RemoteConnection connection)
        {
            if (returnImmediately)
            {
                ReadArgs(connection.streamHandler);
                WorkerPool.EnqueueTask(() => ExecutionThreadEntry(connection));
                return;
            }

            var h = connection.streamHandler;

            h.Read(out remoteThreadId);
            h.Read(out localThreadId);
            ReadArgs(h);

            if (localThreadId != 0)
            {
                var call = connection.callStack.Peek(localThreadId);
                lock (call.waitLock) {
                    call.reentryCall = this;
                    System.Threading.Monitor.PulseAll(call.waitLock);
                }
            }
            else
            {
                WorkerPool.EnqueueTask(() => ExecutionThreadEntry(connection));
            }
        }
        private unsafe void ReadLoop()
        {
            for (;;)
            {
                streamHandler.FillReadBuffer(sizeof(ushort));
                fixed(byte *buf = &streamHandler.readBuffer[0])
                {
                    streamHandler.fixedReadBuffer = buf;
                    ushort callId;

                    streamHandler.Read(out callId);
                    RemoteCall newCall;

                    while (newCalls.TryTake(out newCall))
                    {
                        Stack <RemoteCall> stack;
                        if (!threadCallStack.TryGetValue(newCall.localThreadId, out stack))
                        {
                            stack = new Stack <RemoteCall>();
                            threadCallStack.Add(newCall.localThreadId, stack);
                        }
                        stack.Push(newCall);
                    }
                    if (callId == ushort.MaxValue)
                    {
                        int threadId;
                        streamHandler.Read(out threadId);
                        var rc = threadCallStack[threadId].Pop();
                        rc.ReadResponse(streamHandler);
                        lock (rc) {
                            Monitor.PulseAll(rc);
                        }
                    }
                    else
                    {
                        var call = RemoteCallFactory.ForCallId((RemoteCallId)callId);
                        call.ReadRequest(streamHandler);
                        if (call.localThreadId != 0)
                        {
                            var rc = threadCallStack[call.localThreadId].Peek();
                            rc.nextCall = call;
                            lock (rc) {
                                Monitor.PulseAll(rc);
                            }
                        }
                        else
                        {
                            WorkerPool.EnqueueTask(() => {
                                call.Execute(this);
                                if (!call.returnImmediately)
                                {
                                    Write(call.WriteResponse);
                                }
                            });
                        }
                    }
                    streamHandler.fixedReadBuffer = null;
                }
            }
        }
Example #3
0
 private void ReadLoop()
 {
     for (;;)
     {
         var        callId = streamHandler.ReadUInt16();
         RemoteCall newCall;
         while (newCalls.TryTake(out newCall))
         {
             Stack <RemoteCall> stack;
             if (!threadCallStack.TryGetValue(newCall.localThreadId, out stack))
             {
                 stack = new Stack <RemoteCall>();
                 threadCallStack.Add(newCall.localThreadId, stack);
             }
             stack.Push(newCall);
         }
         if (callId == ushort.MaxValue)
         {
             var threadId = streamHandler.ReadInt32();
             var rc       = threadCallStack[threadId].Pop();
             rc.ReadResponse(streamHandler);
             lock (rc) {
                 Monitor.PulseAll(rc);
             }
         }
         else
         {
             var call = RemoteCallFactory.ForCallId((RemoteCallId)callId);
             call.ReadRequest(streamHandler);
             if (call.localThreadId != 0)
             {
                 var rc = threadCallStack[call.localThreadId].Peek();
                 rc.nextCall = call;
                 lock (rc) {
                     Monitor.PulseAll(rc);
                 }
             }
             else
             {
                 WorkerPool.EnqueueTask(() => {
                     call.Execute(this);
                     if (!call.returnImmediately)
                     {
                         Write(call.WriteResponse);
                     }
                 });
             }
         }
     }
 }