void OnTimeout(TimeoutEvent e) { Flow.Unbind(token); coroutine.Result = e; coroutine.Continue(); }
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); }
protected WaitForMultipleEvents(Coroutine coroutine, Event[] requests, double seconds, params Event[] e) { this.coroutine = coroutine; if (!Object.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; actual = new Event[expected.Length]; handlerTokens = new Binder.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); } }
void OnTimeout(TimeoutEvent e) { Flow.Unbind(token); coroutine.Context = e; coroutine.Continue(); coroutine.Context = null; }
public WaitForNothing(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(timeoutToken); Flow.Unbind(handlerToken); Log.Error("WaitForSingleEvent timeout for {0}", handlerToken.key); coroutine.Context = null; // indicates timeout coroutine.Continue(); }
public WaitForSingleEvent(Coroutine coroutine, Event e, double seconds) { this.coroutine = coroutine; 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) { Flow.Unbind(handlerToken); Flow.Unbind(timeoutToken); int waitHandle = handlerToken.Key._WaitHandle; if (waitHandle != 0) { WaitHandlePool.Release(waitHandle); } Log.Error("WaitForSingleEvent timeout for {0}", handlerToken.Key); coroutine.Result = null; // indicates timeout coroutine.Continue(); }
protected WaitForSingleEvent(Coroutine coroutine, Event request, Event e, double seconds) { this.coroutine = coroutine; if (!Object.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); } }
internal override void OnInstantDisconnect(LinkSession session) { bool flag; // Ensure that the specified session is recoverable. LinkSession existing = null; lock (recoverable) { flag = recoverable.TryGetValue(session.Token, out existing); } if (!flag) { Log.Info("{0} {1} unrecoverable session", Name, session.Handle); OnLinkSessionDisconnectedInternal(session.Handle, session); return; } else if (!Object.ReferenceEquals(session, existing)) { Log.Warn("{0} {1} gave up session recovery", Name, session.Handle); return; } existing = null; using (new ReadLock(rwlock)) { sessions.TryGetValue(session.Handle, out existing); } if (!Object.ReferenceEquals(session, existing)) { Log.Warn("{0} {1} gave up session recovery", Name, session.Handle); return; } var e = new TimeoutEvent { Key = session }; Binder.Token binderToken = this.Flow.Subscribe(e, OnSessionRecoveryTimeout); TimeFlow.Default.Reserve(e, SessionRecoveryTimeout); lock (recoveryTokens) { recoveryTokens[session.Handle] = binderToken; } Log.Trace("{0} {1} started recovery timer", Name, session.Handle); }
void OnSessionRecoveryTimeout(TimeoutEvent e) { this.Flow.Unsubscribe(e, OnSessionRecoveryTimeout); var session = e.Key as LinkSession; if (Object.ReferenceEquals(session, null)) { return; } session.Release(); Log.Debug("{0} {1} session recovery timeout {1} {2}", Name, session.Handle, session.Token); lock (recoveryTokens) { recoveryTokens.Remove(session.Handle); } OnLinkSessionDisconnectedInternal(session.Handle, session); }
private void OnTimer(TimeoutEvent e) { if (!session.IsBusy && sessionRefCount == 0) { Disconnect(); } }
private void OnTimeout(TimeoutEvent e) { Log.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); }
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); }
void OnTimer(TimeoutEvent e) { new TestReq { Serial = serial++ }.Post(); }
void OnTimeout(TimeoutEvent e) { for (int i = 0, count = actual.Length; i < count; ++i) { if (Object.ReferenceEquals(actual[i], null)) { Flow.Unbind(handlerTokens[i]); } } Flow.Unbind(timeoutToken); if (waitHandle != 0) { WaitHandlePool.Release(waitHandle); } Log.Error("WaitForMultipleEvents timeout for {0}", expected); coroutine.Result = actual; // incomplete array indicates timeout coroutine.Continue(); }