Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / ErrorHandlingAcceptor.cs / 1 / ErrorHandlingAcceptor.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System; using System.ServiceModel; using System.ServiceModel.Channels; class ErrorHandlingAcceptor { readonly ChannelDispatcher dispatcher; readonly IListenerBinder binder; internal ErrorHandlingAcceptor(IListenerBinder binder, ChannelDispatcher dispatcher) { if (binder == null) { DiagnosticUtility.DebugAssert("binder is null"); } if (dispatcher == null) { DiagnosticUtility.DebugAssert("dispatcher is null"); } this.binder = binder; this.dispatcher = dispatcher; } internal void Close() { try { this.binder.Listener.Close(); } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } this.HandleError(e); } } void HandleError(Exception e) { if (this.dispatcher != null) { this.dispatcher.HandleError(e); } } void HandleErrorOrAbort(Exception e) { if ((this.dispatcher == null) || !this.dispatcher.HandleError(e)) { // We only stop if the listener faults. It is a bug // if the listener is in an invalid state and does not // fault. So there are no cases today where this aborts. } } internal bool TryAccept(TimeSpan timeout, out IChannelBinder channelBinder) { try { channelBinder = this.binder.Accept(timeout); if (channelBinder != null) { this.dispatcher.PendingChannels.Add(channelBinder.Channel); } return true; } catch (CommunicationObjectAbortedException) { channelBinder = null; return true; } catch (CommunicationObjectFaultedException) { channelBinder = null; return true; } catch (TimeoutException) { channelBinder = null; return false; } catch (CommunicationException e) { this.HandleError(e); channelBinder = null; return false; } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } this.HandleErrorOrAbort(e); channelBinder = null; return false; } } internal IAsyncResult BeginTryAccept(TimeSpan timeout, AsyncCallback callback, object state) { try { return this.binder.BeginAccept(timeout, callback, state); } catch (CommunicationObjectAbortedException) { return new ErrorHandlingCompletedAsyncResult(true, callback, state); } catch (CommunicationObjectFaultedException) { return new ErrorHandlingCompletedAsyncResult(true, callback, state); } catch (TimeoutException) { return new ErrorHandlingCompletedAsyncResult(false, callback, state); } catch (CommunicationException e) { this.HandleError(e); return new ErrorHandlingCompletedAsyncResult(false, callback, state); } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } this.HandleErrorOrAbort(e); return new ErrorHandlingCompletedAsyncResult(false, callback, state); } } internal bool EndTryAccept(IAsyncResult result, out IChannelBinder channelBinder) { ErrorHandlingCompletedAsyncResult handlerResult = result as ErrorHandlingCompletedAsyncResult; if (handlerResult != null) { channelBinder = null; return ErrorHandlingCompletedAsyncResult.End(handlerResult); } else { try { channelBinder = this.binder.EndAccept(result); if (channelBinder != null) { this.dispatcher.PendingChannels.Add(channelBinder.Channel); } return true; } catch (CommunicationObjectAbortedException) { channelBinder = null; return true; } catch (CommunicationObjectFaultedException) { channelBinder = null; return true; } catch (TimeoutException) { channelBinder = null; return false; } catch (CommunicationException e) { this.HandleError(e); channelBinder = null; return false; } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } this.HandleErrorOrAbort(e); channelBinder = null; return false; } } } internal void WaitForChannel() { try { this.binder.Listener.WaitForChannel(TimeSpan.MaxValue); } catch (CommunicationObjectAbortedException) { } catch (CommunicationObjectFaultedException) { } catch (CommunicationException e) { this.HandleError(e); } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } this.HandleErrorOrAbort(e); } } internal IAsyncResult BeginWaitForChannel(AsyncCallback callback, object state) { try { return this.binder.Listener.BeginWaitForChannel(TimeSpan.MaxValue, callback, state); } catch (CommunicationObjectAbortedException) { return new WaitCompletedAsyncResult(callback, state); } catch (CommunicationObjectFaultedException) { return new WaitCompletedAsyncResult(callback, state); } catch (CommunicationException e) { this.HandleError(e); return new WaitCompletedAsyncResult(callback, state); } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } this.HandleErrorOrAbort(e); return new WaitCompletedAsyncResult(callback, state); } } internal void EndWaitForChannel(IAsyncResult result) { WaitCompletedAsyncResult handlerResult = result as WaitCompletedAsyncResult; if (handlerResult != null) { WaitCompletedAsyncResult.End(handlerResult); } else { try { this.binder.Listener.EndWaitForChannel(result); } catch (CommunicationObjectAbortedException) { } catch (CommunicationObjectFaultedException) { } catch (CommunicationException e) { this.HandleError(e); } catch (Exception e) { if (DiagnosticUtility.IsFatal(e)) { throw; } this.HandleErrorOrAbort(e); } } } class ErrorHandlingCompletedAsyncResult : TypedCompletedAsyncResult{ internal ErrorHandlingCompletedAsyncResult(bool data, AsyncCallback callback, object state) : base(data, callback, state) { } } class WaitCompletedAsyncResult : CompletedAsyncResult { internal WaitCompletedAsyncResult(AsyncCallback callback, object state) : base(callback, state) { } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AssemblySettingAttributes.cs
- ChannelBase.cs
- UiaCoreApi.cs
- ReflectionServiceProvider.cs
- SessionStateContainer.cs
- WebPartDeleteVerb.cs
- InternalCache.cs
- WindowPattern.cs
- XPathParser.cs
- Point3DCollectionValueSerializer.cs
- versioninfo.cs
- ProcessProtocolHandler.cs
- RangeContentEnumerator.cs
- StrongNameKeyPair.cs
- ParameterModifier.cs
- HtmlTitle.cs
- StandardMenuStripVerb.cs
- ProcessInfo.cs
- SerializationStore.cs
- InvalidPrinterException.cs
- RequestTimeoutManager.cs
- VisualTreeHelper.cs
- AvTrace.cs
- DocumentViewer.cs
- QuaternionAnimation.cs
- HttpServerUtilityWrapper.cs
- SortedSetDebugView.cs
- Math.cs
- InputScopeNameConverter.cs
- _SpnDictionary.cs
- ISO2022Encoding.cs
- StateWorkerRequest.cs
- DbParameterCollectionHelper.cs
- MemberRelationshipService.cs
- ServiceDiscoveryBehavior.cs
- RecognizerBase.cs
- MultipleFilterMatchesException.cs
- WindowsPrincipal.cs
- UnsafeNativeMethods.cs
- Fonts.cs
- ObjectDataSourceEventArgs.cs
- mda.cs
- ApplicationBuildProvider.cs
- COM2ICategorizePropertiesHandler.cs
- MembershipSection.cs
- CounterSet.cs
- InvalidCommandTreeException.cs
- CustomExpressionEventArgs.cs
- DynamicControlParameter.cs
- Matrix.cs
- EventTrigger.cs
- ListViewCommandEventArgs.cs
- CacheEntry.cs
- CircleHotSpot.cs
- HandlerBase.cs
- ToolboxItem.cs
- TextRangeSerialization.cs
- HttpModuleCollection.cs
- DesignRelation.cs
- HashMembershipCondition.cs
- ReachSerializationCacheItems.cs
- BoolExpressionVisitors.cs
- DecimalKeyFrameCollection.cs
- DropDownList.cs
- IconBitmapDecoder.cs
- HealthMonitoringSection.cs
- ImageFormat.cs
- GZipStream.cs
- PeerResolverSettings.cs
- DataGridTable.cs
- AsnEncodedData.cs
- HasCopySemanticsAttribute.cs
- HashSetEqualityComparer.cs
- SmtpDateTime.cs
- StringExpressionSet.cs
- TypeConverters.cs
- GroupBoxAutomationPeer.cs
- TimeSpan.cs
- PolicyUnit.cs
- TrackingQueryElement.cs
- SmtpAuthenticationManager.cs
- ButtonChrome.cs
- WriterOutput.cs
- SQLDouble.cs
- ItemCollection.cs
- UrlPropertyAttribute.cs
- SafeRightsManagementSessionHandle.cs
- SuppressMessageAttribute.cs
- ClientSettings.cs
- SqlFactory.cs
- UnionQueryOperator.cs
- XmlAtomErrorReader.cs
- RawKeyboardInputReport.cs
- RpcCryptoRequest.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- CodeExpressionStatement.cs
- FacetChecker.cs
- SafeThreadHandle.cs
- XmlDataImplementation.cs
- XmlQueryOutput.cs