IAsyncResult BeginPoll(MakeConnectionDuplexClientChannel <TChannel> channel, AsyncCallback callback, object state) { TChannel channelToUse = channel.GetChannelForPoll(); this.outstandingPoll = new PollAsyncResult <TChannel>(channel, channelToUse, callback, state); return(this.outstandingPoll); }
public static MakeConnectionPoller <TChannel> AddChannelToPoller(MakeConnectionDuplexClientChannel <TChannel> channel) { MakeConnectionPoller <TChannel> poller = GetForUri(channel.RemoteAddress.Uri); poller.AddChannel(channel); poller.messageVersion = channel.GetProperty <MessageVersion>(); return(poller); }
void EnqueueException(Exception e) { MakeConnectionDuplexClientChannel <TChannel> channelsToFault = this.channel; if (channelsToFault != null) { channelsToFault.EnqueueException(e); } }
void EndPoll(IAsyncResult result) { Message message = null; try { this.outstandingPoll = null; message = PollAsyncResult <TChannel> .End(result); if (message != null && message.IsFault) { MessageFault fault = MessageFault.CreateFault(message, MakeConnectionConstants.Defaults.MaxFaultSize); MakeConnectionMessageFault wsmcFault; if (MakeConnectionMessageFault.TryCreateFault(message, fault, out wsmcFault)) { throw MakeConnectionMessageFault.CreateException(wsmcFault); } } } catch (TimeoutException) { } catch (Exception e) { EnqueueException(e); } if (message != null) { MakeConnectionDuplexClientChannel <TChannel> channelToDispatch = this.channel; if (channelToDispatch != null) { channelToDispatch.EnqueueAndDispatch(message, null, false); } } lock (ThisLock) { polling = false; if (this.channel != null && !stopPolling) { ThreadPool.QueueUserWorkItem(onEnsurePollingLater, this); } else { this.pollingComplete.Set(); } } }
public void EnsurePolling(MakeConnectionDuplexClientChannel <TChannel> channel) { bool shouldSchedule = false; lock (ThisLock) { shouldSchedule = !polling; } if (shouldSchedule) { ThreadPool.QueueUserWorkItem(onEnsurePollingLater, this); } }
public CloseAsyncResult(TimeSpan timeout, MakeConnectionDuplexClientChannel <TChannel> channel, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.timeoutHelper = new TimeoutHelper(timeout); IAsyncResult result = channel.poller.BeginClose(timeoutHelper.RemainingTime(), onClosePollerComplete, this); if (result.CompletedSynchronously) { if (CompleteClosePoller(result)) { base.Complete(true); } } }
public PollAsyncResult( MakeConnectionDuplexClientChannel <T> channel, T innerChannel, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.timeout = new TimeoutHelper(channel.ClientPollTimeout); this.innerChannel = innerChannel; this.pollingMessage = GetPollingMessage(); IAsyncResult result = innerChannel.BeginRequest(pollingMessage, timeout.RemainingTime(), onRequestComplete, this); if (result.CompletedSynchronously) { CompleteRequest(result); base.Complete(true); } }
void EnsurePollingCore() { bool shouldPoll = false; MakeConnectionDuplexClientChannel <TChannel> channelToPoll = null; if (!polling) { lock (ThisLock) { if (!polling) { if (stopPolling) { this.pollingComplete.Set(); } else { channelToPoll = this.channel; if (channelToPoll != null) { polling = shouldPoll = true; } } } } } if (shouldPoll) { IAsyncResult result = BeginPoll(channelToPoll, onPollComplete, this); if (result.CompletedSynchronously) { EndPoll(result); } } }
public void AddChannel(MakeConnectionDuplexClientChannel <TChannel> channel) { channel.Opened += onChannelOpened; channel.Closed += onChannelClosedOrFaulted; channel.Faulted += onChannelClosedOrFaulted; }
void OnChannelClosedOrFaulted(object sender, EventArgs e) { this.channel = null; AbortOutstandingPolls(); }
void OnChannelOpened(object sender, EventArgs e) { this.channel = (MakeConnectionDuplexClientChannel <TChannel>)sender; }