void OnTimeout(TimeoutEvent e)
        {
            Flow.Unbind(token);

            coroutine.Result = e;
            coroutine.Continue();
        }
        private void OnTimeout(TimeoutEvent e)
        {
            Trace.Debug("{0} response timeout {1}", Name, e.Key);

            int waitHandle = (int)e.Key;

            int           count = 0;
            PendingRecord pendingRecord;

            lock (pendingRecords)
            {
                if (!pendingRecords.TryGetValue(waitHandle, out pendingRecord))
                {
                    return;
                }
                count = pendingRecord.Count;
                pendingRecords.Remove(waitHandle);
            }

            if (pendingRecord.HandleAllocated)
            {
                WaitHandlePool.Release(waitHandle);
            }

            Unbind(new Event {
                _WaitHandle = waitHandle
            }, OnEvent);
            Unbind((TimeoutEvent)pendingRecord.TimeoutToken.value, OnTimeout);

            Interlocked.Add(ref sessionRefCount, -count);
        }
        protected WaitForAnyEvent(Coroutine coroutine, Event[] requests,
                                  double seconds, params Event[] e)
        {
            this.coroutine = coroutine;

            if (!ReferenceEquals(requests, null))
            {
                waitHandle = WaitHandlePool.Acquire();
                for (int i = 0, count = requests.Length; i < count; ++i)
                {
                    requests[i]._WaitHandle = waitHandle;
                }
                for (int i = 0, count = e.Length; i < count; ++i)
                {
                    e[i]._WaitHandle = waitHandle;
                }
            }

            expected = e;

            handlerTokens = new Binding.Token[expected.Length];
            for (int i = 0; i < expected.Length; ++i)
            {
                handlerTokens[i] = Flow.Bind(expected[i], OnEvent);
            }

            if (seconds > 0)
            {
                TimeoutEvent timeoutEvent = new TimeoutEvent {
                    Key = this
                };
                timeoutToken = Flow.Bind(timeoutEvent, OnTimeout);
                timerToken   = TimeFlow.Default.Reserve(timeoutEvent, seconds);
            }
        }
        protected override bool IsEquivalent(Cell other, Fingerprint fingerprint)
        {
            if (!base.IsEquivalent(other, fingerprint))
            {
                return(false);
            }
            TimeoutEvent o       = (TimeoutEvent)other;
            var          touched = new Capo <bool>(fingerprint, tag.Offset);

            if (touched[0])
            {
                if (key_ != o.key_)
                {
                    return(false);
                }
            }
            if (touched[1])
            {
                if (intParam_ != o.intParam_)
                {
                    return(false);
                }
            }
            return(true);
        }
 private void OnTimer(TimeoutEvent e)
 {
     if (!ReferenceEquals(session, null))
     {
         if (!session.IsBusy && sessionRefCount == 0)
         {
             Disconnect();
         }
     }
 }
        public WaitForSeconds(Coroutine coroutine, double seconds)
        {
            this.coroutine = coroutine;
            TimeoutEvent e = new TimeoutEvent {
                Key = this
            };

            token = Flow.Bind(e, OnTimeout);
            TimeFlow.Default.Reserve(e, seconds);
        }
Exemple #7
0
        public WaitForNext(Coroutine coroutine, object result)
        {
            this.coroutine = coroutine;
            this.result    = result;
            TimeoutEvent e = new TimeoutEvent {
                Key = this
            };

            token = Flow.Bind(e, OnTimeout);
            Hub.Post(e);
        }
        void OnTimeout(TimeoutEvent e)
        {
            Flow.Unbind(handlerToken);
            Flow.Unbind(timeoutToken);

            int waitHandle = handlerToken.Key._WaitHandle;

            if (waitHandle != 0)
            {
                WaitHandlePool.Release(waitHandle);
            }

            Trace.Error("WaitForEvent timeout for {0}", handlerToken.Key);

            coroutine.Status = CoroutineStatus.Timeout;
            coroutine.Result = null;  // indicates timeout
            coroutine.Continue();
        }
        protected override bool EqualsTo(Cell other)
        {
            if (!base.EqualsTo(other))
            {
                return(false);
            }
            TimeoutEvent o = (TimeoutEvent)other;

            if (key_ != o.key_)
            {
                return(false);
            }
            if (intParam_ != o.intParam_)
            {
                return(false);
            }
            return(true);
        }
        void OnTimeout(TimeoutEvent e)
        {
            for (int i = 0, length = expected.Length; i < length; ++i)
            {
                Flow.Unbind(handlerTokens[i]);
            }

            Flow.Unbind(timeoutToken);

            if (waitHandle != 0)
            {
                WaitHandlePool.Release(waitHandle);
            }

            Trace.Error("WaitForAnyEvent timeout for {0}", expected);

            coroutine.Status = CoroutineStatus.Timeout;
            coroutine.Result = null;
            coroutine.Continue();
        }
        public void ConnectAndRequest(Event req)
        {
            int waitHandle = req._WaitHandle;

            bool handleAllocated = false;

            if (waitHandle == 0)
            {
                waitHandle      = WaitHandlePool.Acquire();
                req._WaitHandle = waitHandle;
                handleAllocated = true;
            }

            lock (pendingRecords)
            {
                PendingRecord pendingRecord;
                if (!pendingRecords.TryGetValue(waitHandle, out pendingRecord))
                {
                    TimeoutEvent timeoutEvent = new TimeoutEvent {
                        Key = waitHandle
                    };

                    Bind(new Event {
                        _WaitHandle = waitHandle
                    }, OnEvent);
                    Bind(timeoutEvent, OnTimeout);

                    pendingRecord = new PendingRecord {
                        HandleAllocated = handleAllocated,
                        TimeoutToken    =
                            TimeFlow.Default.Reserve(timeoutEvent, ResponseTimeout)
                    };
                    pendingRecords.Add(waitHandle, pendingRecord);
                }
                ++pendingRecord.Count;
            }

            Interlocked.Increment(ref sessionRefCount);

            ConnectAndSend(req);
        }
        protected WaitForEvent(Coroutine coroutine, Event request, Event e, double seconds)
        {
            this.coroutine = coroutine;

            if (!ReferenceEquals(request, null))
            {
                int waitHandle = WaitHandlePool.Acquire();
                request._WaitHandle = waitHandle;
                e._WaitHandle       = waitHandle;
            }

            handlerToken = Flow.Bind(e, OnEvent);
            if (seconds > 0)
            {
                TimeoutEvent timeoutEvent = new TimeoutEvent {
                    Key = this
                };
                timeoutToken = Flow.Bind(timeoutEvent, OnTimeout);
                timerToken   = TimeFlow.Default.Reserve(timeoutEvent, seconds);
            }
        }
        void OnTimeout(TimeoutEvent e)
        {
            for (int i = 0, count = actual.Length; i < count; ++i)
            {
                if (ReferenceEquals(actual[i], null))
                {
                    Flow.Unbind(handlerTokens[i]);
                }
            }
            Flow.Unbind(timeoutToken);

            if (waitHandle != 0)
            {
                WaitHandlePool.Release(waitHandle);
            }

            Trace.Error("WaitForAllEvents timeout for {0}", expected);

            coroutine.Status = CoroutineStatus.Timeout;
            coroutine.Result = actual;  // incomplete array indicates timeout
            coroutine.Continue();
        }