Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / HttpListenerTimeoutManager.cs / 1305376 / HttpListenerTimeoutManager.cs
using System; using System.Net; using System.Diagnostics.CodeAnalysis; namespace System.Net { internal class HttpListenerTimeoutManager { private HttpListener listener; private int[] timeouts; private uint minSendRate; private const int defaulServerTimeout = 120; private const uint defaultMinSendRate = 150; // // Timeouts are configurable only if Http API V2 is being used which is available on Vista+. On XP and // Win2k3, doing a GET on HttpListener for HttpListenerTimeoutManager will throw an exception. // internal HttpListenerTimeoutManager(HttpListener context) { listener = context; // // We have to maintain local state since we allow applications to set individual timeouts. Native Http // API for setting timeouts expects all timeout values in every call so we have remember timeout values // to fill in the blanks. Except MinSendRate, local state for remaining five timeouts is maintained in // timeouts array. // timeouts = new int[5]; } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] private TimeSpan GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE type) { // // Since we maintain local state, GET is local. // return new TimeSpan(0, 0, (int)timeouts[(int)type]); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] private void SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE type, TimeSpan value) { Int64 timeoutValue; // // All timeouts are defined as USHORT in native layer (except MinSendRate, which is ULONG). Make sure that // timeout value is within range. // timeoutValue = Convert.ToInt64(value.TotalSeconds); if (timeoutValue < 0 || timeoutValue > ushort.MaxValue) { throw new ArgumentOutOfRangeException("value"); } // // Use local state to get values for other timeouts. Call into the native layer and if that // call succeeds, update local state. // int[] currentTimeouts = timeouts; currentTimeouts[(int)type] = (int)timeoutValue; listener.SetServerTimeout(currentTimeouts, minSendRate); timeouts[(int)type] = (int)timeoutValue; } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan EntityBody { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.EntityBody); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.EntityBody, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan DrainEntityBody { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan RequestQueue { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan IdleConnection { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan HeaderWait { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public long MinSendRate { get { // // Since we maintain local state, GET is local. // return minSendRate; } set { // // MinSendRate value is ULONG in native layer. // if (value < 0 || value > uint.MaxValue) { throw new ArgumentOutOfRangeException("value"); } listener.SetServerTimeout(timeouts, (uint)value); minSendRate = (uint)value; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Net; using System.Diagnostics.CodeAnalysis; namespace System.Net { internal class HttpListenerTimeoutManager { private HttpListener listener; private int[] timeouts; private uint minSendRate; private const int defaulServerTimeout = 120; private const uint defaultMinSendRate = 150; // // Timeouts are configurable only if Http API V2 is being used which is available on Vista+. On XP and // Win2k3, doing a GET on HttpListener for HttpListenerTimeoutManager will throw an exception. // internal HttpListenerTimeoutManager(HttpListener context) { listener = context; // // We have to maintain local state since we allow applications to set individual timeouts. Native Http // API for setting timeouts expects all timeout values in every call so we have remember timeout values // to fill in the blanks. Except MinSendRate, local state for remaining five timeouts is maintained in // timeouts array. // timeouts = new int[5]; } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] private TimeSpan GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE type) { // // Since we maintain local state, GET is local. // return new TimeSpan(0, 0, (int)timeouts[(int)type]); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] private void SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE type, TimeSpan value) { Int64 timeoutValue; // // All timeouts are defined as USHORT in native layer (except MinSendRate, which is ULONG). Make sure that // timeout value is within range. // timeoutValue = Convert.ToInt64(value.TotalSeconds); if (timeoutValue < 0 || timeoutValue > ushort.MaxValue) { throw new ArgumentOutOfRangeException("value"); } // // Use local state to get values for other timeouts. Call into the native layer and if that // call succeeds, update local state. // int[] currentTimeouts = timeouts; currentTimeouts[(int)type] = (int)timeoutValue; listener.SetServerTimeout(currentTimeouts, minSendRate); timeouts[(int)type] = (int)timeoutValue; } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan EntityBody { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.EntityBody); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.EntityBody, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan DrainEntityBody { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan RequestQueue { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan IdleConnection { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public TimeSpan HeaderWait { get { return GetTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait); } set { SetTimespanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait, value); } } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "Suppress due to tools issues with unit test infrastructure")] public long MinSendRate { get { // // Since we maintain local state, GET is local. // return minSendRate; } set { // // MinSendRate value is ULONG in native layer. // if (value < 0 || value > uint.MaxValue) { throw new ArgumentOutOfRangeException("value"); } listener.SetServerTimeout(timeouts, (uint)value); minSendRate = (uint)value; } } } } // 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
- InkCanvasInnerCanvas.cs
- ClientConfigurationSystem.cs
- JulianCalendar.cs
- WebPartVerb.cs
- RangeValuePattern.cs
- ResourceExpressionBuilder.cs
- ErrorWebPart.cs
- Evaluator.cs
- ModelPropertyDescriptor.cs
- Table.cs
- NullableConverter.cs
- GetPageNumberCompletedEventArgs.cs
- ContextStaticAttribute.cs
- DataSourceExpressionCollection.cs
- BamlLocalizationDictionary.cs
- XmlComment.cs
- CacheOutputQuery.cs
- Clock.cs
- StreamInfo.cs
- LinearGradientBrush.cs
- ExpressionBuilderCollection.cs
- NullReferenceException.cs
- SecurityIdentifierElement.cs
- MailWriter.cs
- RegexBoyerMoore.cs
- DataColumnPropertyDescriptor.cs
- ConnectorDragDropGlyph.cs
- KeyFrames.cs
- ObjectStateManager.cs
- TextEditorCopyPaste.cs
- Signature.cs
- OleDbFactory.cs
- MaskInputRejectedEventArgs.cs
- DBParameter.cs
- ProfileSection.cs
- TreeViewImageGenerator.cs
- DynamicPropertyHolder.cs
- MouseGesture.cs
- TextControlDesigner.cs
- TemplateLookupAction.cs
- IPCCacheManager.cs
- Mutex.cs
- NetworkInterface.cs
- DispatcherHooks.cs
- CapabilitiesUse.cs
- ToolbarAUtomationPeer.cs
- ListDictionaryInternal.cs
- EventToken.cs
- EventKeyword.cs
- DbReferenceCollection.cs
- ReadWriteControlDesigner.cs
- TypeGeneratedEventArgs.cs
- SQLDateTime.cs
- DataGridViewCellValueEventArgs.cs
- ObjectManager.cs
- ListControl.cs
- SiteIdentityPermission.cs
- MetadataItemSerializer.cs
- GeneralTransformCollection.cs
- TextTreeTextNode.cs
- PrimitiveType.cs
- GeneratedContractType.cs
- VariableExpressionConverter.cs
- ProgressBarRenderer.cs
- ExtractCollection.cs
- DataGridCellEditEndingEventArgs.cs
- ViewService.cs
- ResourceBinder.cs
- OperationAbortedException.cs
- DataControlExtensions.cs
- CallbackException.cs
- CalendarAutoFormat.cs
- GZipStream.cs
- SHA1CryptoServiceProvider.cs
- XmlNamespaceMappingCollection.cs
- keycontainerpermission.cs
- ReferenceConverter.cs
- QuaternionRotation3D.cs
- BrowserCapabilitiesFactory.cs
- VideoDrawing.cs
- DataKey.cs
- FontFamily.cs
- SchemaCompiler.cs
- TimelineGroup.cs
- TimeSpanSecondsConverter.cs
- InputLangChangeEvent.cs
- ThicknessConverter.cs
- SqlProcedureAttribute.cs
- NullableLongSumAggregationOperator.cs
- ListBoxItemAutomationPeer.cs
- ModelItemKeyValuePair.cs
- Matrix3D.cs
- MemoryFailPoint.cs
- ObjectListField.cs
- XmlObjectSerializerContext.cs
- UIAgentAsyncParams.cs
- Stack.cs
- MembershipPasswordException.cs
- DrawListViewItemEventArgs.cs
- SqlPersonalizationProvider.cs