source: TFP-WebServer/SpaceWizards.HttpListener/src/System/Net/Managed/HttpListenerTimeoutManager.Managed.cs

Last change on this file was 377, checked in by alloc, 2 years ago

Made SpaceWizards.HttpListener compilable against .NET 4.8 with preprocessor define UNITY_NETFRAMEWORK

File size: 3.0 KB
Line 
1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3
4// ReSharper disable RedundantUsingDirective
5// ReSharper disable UnusedParameter.Local
6
7using System;
8using System.Runtime.Versioning;
9
10namespace SpaceWizards.HttpListener
11{
12 public class HttpListenerTimeoutManager
13 {
14 private TimeSpan _drainEntityBody = TimeSpan.Zero;
15 private TimeSpan _idleConnection = TimeSpan.Zero;
16
17 internal HttpListenerTimeoutManager(HttpListener listener) { }
18
19 public TimeSpan DrainEntityBody
20 {
21 get => _drainEntityBody;
22 set
23 {
24 // Managed implementation currently doesn't pool connections,
25 // so this is a nop other than roundtripping the value.
26 ValidateTimeout(value);
27 _drainEntityBody = value;
28 }
29 }
30
31 public TimeSpan IdleConnection
32 {
33 get => _idleConnection;
34 set
35 {
36 // Managed implementation currently doesn't pool connections,
37 // so this is a nop other than roundtripping the value.
38 ValidateTimeout(value);
39 _idleConnection = value;
40 }
41 }
42
43#if !UNITY_NETFRAMEWORK
44 public TimeSpan EntityBody
45 {
46 get => TimeSpan.Zero;
47 [SupportedOSPlatform("windows")]
48 set
49 {
50 ValidateTimeout(value);
51 throw new PlatformNotSupportedException(); // low usage, not currently implemented
52 }
53 }
54
55 public TimeSpan HeaderWait
56 {
57 get => TimeSpan.Zero;
58 [SupportedOSPlatform("windows")]
59 set
60 {
61 ValidateTimeout(value);
62 throw new PlatformNotSupportedException(); // low usage, not currently implemented
63 }
64 }
65
66 public long MinSendBytesPerSecond
67 {
68 get => 0;
69 [SupportedOSPlatform("windows")]
70 set
71 {
72 if (value < 0 || value > uint.MaxValue)
73 {
74 throw new ArgumentOutOfRangeException(nameof(value));
75 }
76 throw new PlatformNotSupportedException(); // low usage, not currently implemented
77 }
78 }
79
80 public TimeSpan RequestQueue
81 {
82 get => TimeSpan.Zero;
83 [SupportedOSPlatform("windows")]
84 set
85 {
86 ValidateTimeout(value);
87 throw new PlatformNotSupportedException(); // low usage, not currently implemented
88 }
89 }
90#endif
91
92 private void ValidateTimeout(TimeSpan value)
93 {
94 long timeoutValue = Convert.ToInt64(value.TotalSeconds);
95 if (timeoutValue < 0 || timeoutValue > ushort.MaxValue)
96 {
97 throw new ArgumentOutOfRangeException(nameof(value));
98 }
99 }
100 }
101}
Note: See TracBrowser for help on using the repository browser.