Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 61da809

Browse files
committed
Merge branch 'master' into beta
2 parents a285a45 + f225e38 commit 61da809

File tree

9 files changed

+133
-154
lines changed

9 files changed

+133
-154
lines changed

docs/api/Titanium.Web.Proxy.ProxyServer.html

Lines changed: 82 additions & 83 deletions
Large diffs are not rendered by default.

docs/index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/xrefmap.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,19 +3505,6 @@ references:
35053505
isSpec: "True"
35063506
fullName: Titanium.Web.Proxy.ProxyServer.EnableTcpServerConnectionPrefetch
35073507
nameWithType: ProxyServer.EnableTcpServerConnectionPrefetch
3508-
- uid: Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
3509-
name: EnableThreadPoolOptimizing
3510-
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableThreadPoolOptimizing
3511-
commentId: P:Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
3512-
fullName: Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
3513-
nameWithType: ProxyServer.EnableThreadPoolOptimizing
3514-
- uid: Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing*
3515-
name: EnableThreadPoolOptimizing
3516-
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableThreadPoolOptimizing_
3517-
commentId: Overload:Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
3518-
isSpec: "True"
3519-
fullName: Titanium.Web.Proxy.ProxyServer.EnableThreadPoolOptimizing
3520-
nameWithType: ProxyServer.EnableThreadPoolOptimizing
35213508
- uid: Titanium.Web.Proxy.ProxyServer.EnableWinAuth
35223509
name: EnableWinAuth
35233510
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_EnableWinAuth
@@ -3828,6 +3815,19 @@ references:
38283815
isSpec: "True"
38293816
fullName: Titanium.Web.Proxy.ProxyServer.TcpTimeWaitSeconds
38303817
nameWithType: ProxyServer.TcpTimeWaitSeconds
3818+
- uid: Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
3819+
name: ThreadPoolWorkerThread
3820+
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_ThreadPoolWorkerThread
3821+
commentId: P:Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
3822+
fullName: Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
3823+
nameWithType: ProxyServer.ThreadPoolWorkerThread
3824+
- uid: Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread*
3825+
name: ThreadPoolWorkerThread
3826+
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_ThreadPoolWorkerThread_
3827+
commentId: Overload:Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
3828+
isSpec: "True"
3829+
fullName: Titanium.Web.Proxy.ProxyServer.ThreadPoolWorkerThread
3830+
nameWithType: ProxyServer.ThreadPoolWorkerThread
38313831
- uid: Titanium.Web.Proxy.ProxyServer.UpStreamEndPoint
38323832
name: UpStreamEndPoint
38333833
href: api/Titanium.Web.Proxy.ProxyServer.html#Titanium_Web_Proxy_ProxyServer_UpStreamEndPoint

examples/Titanium.Web.Proxy.Examples.Wpf/Titanium.Web.Proxy.Examples.Wpf.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
<Prefer32Bit>true</Prefer32Bit>
7373
</PropertyGroup>
7474
<ItemGroup>
75-
<Reference Include="StreamExtended, Version=1.0.190.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
76-
<HintPath>..\..\src\packages\StreamExtended.1.0.190\lib\net45\StreamExtended.dll</HintPath>
75+
<Reference Include="StreamExtended, Version=1.0.201.0, Culture=neutral, PublicKeyToken=bbfa0f1d54f50043, processorArchitecture=MSIL">
76+
<HintPath>..\..\src\packages\StreamExtended.1.0.201\lib\net45\StreamExtended.dll</HintPath>
7777
</Reference>
7878
<Reference Include="System" />
7979
<Reference Include="System.Data" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="StreamExtended" version="1.0.190" targetFramework="net45" />
3+
<package id="StreamExtended" version="1.0.201" targetFramework="net45" />
44
</packages>

src/Titanium.Web.Proxy/ExplicitClientHandler.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,13 @@ await clientStreamWriter.WriteResponseAsync(connectArgs.HttpClient.Response,
154154

155155
if (EnableTcpServerConnectionPrefetch)
156156
{
157-
//make sure the host can be resolved before creating the prefetch task
158-
var ipAddresses = await Dns.GetHostAddressesAsync(connectArgs.HttpClient.Request.RequestUri.Host);
157+
IPAddress[] ipAddresses = null;
158+
try
159+
{
160+
//make sure the host can be resolved before creating the prefetch task
161+
ipAddresses = await Dns.GetHostAddressesAsync(connectArgs.HttpClient.Request.RequestUri.Host);
162+
}
163+
catch (SocketException) { }
159164

160165
if (ipAddresses != null && ipAddresses.Length > 0)
161166
{

src/Titanium.Web.Proxy/ProxyServer.cs

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@ public partial class ProxyServer : IDisposable
5757
/// </summary>
5858
private WinHttpWebProxyFinder systemProxyResolver;
5959

60-
/// <summary>
61-
/// lock for Thread Pool tuning
62-
/// </summary>
63-
private object lockThreadPoolTuning = new object();
64-
60+
6561
/// <inheritdoc />
6662
/// <summary>
6763
/// Initializes a new instance of ProxyServer class with provided parameters.
@@ -178,12 +174,6 @@ public ProxyServer(string rootCertificateName, string rootCertificateIssuerName,
178174
/// </summary>
179175
public bool EnableTcpServerConnectionPrefetch { get; set; } = true;
180176

181-
/// <summary>
182-
/// Gets or sets a Boolean value that specifies whether ThreadPool grows new connections and decrease when connections close
183-
/// Defaults to true.
184-
/// </summary>
185-
public bool EnableThreadPoolOptimizing { get; set; } = true;
186-
187177
/// <summary>
188178
/// Gets or sets a Boolean value that specifies whether server and client stream Sockets are using the Nagle algorithm.
189179
/// Defaults to true, no nagle algorithm is used.
@@ -363,6 +353,11 @@ public ExceptionHandler ExceptionFunc
363353
/// </summary>
364354
public event AsyncEventHandler<TcpClient> OnServerConnectionCreate;
365355

356+
/// <summary>
357+
/// Customize the minimum ThreadPool size (increase it on a server)
358+
/// </summary>
359+
public int ThreadPoolWorkerThread { get; set; } = Environment.ProcessorCount;
360+
366361
/// <summary>
367362
/// Add a proxy end point.
368363
/// </summary>
@@ -555,6 +550,8 @@ public void Start()
555550
throw new Exception("Proxy is already running.");
556551
}
557552

553+
setThreadPoolMinThread(ThreadPoolWorkerThread);
554+
558555
if (ProxyEndPoints.OfType<ExplicitProxyEndPoint>().Any(x => x.GenericCertificate == null))
559556
{
560557
CertificateManager.EnsureRootCertificate();
@@ -732,56 +729,34 @@ private void onAcceptConnection(IAsyncResult asyn)
732729

733730
if (tcpClient != null)
734731
{
735-
setThreadPoolMinThread(1); // increase the ThreadPool
736-
737732
Task.Run(async () =>
738733
{
739-
try
740-
{
741-
await handleClient(tcpClient, endPoint);
742-
}
743-
finally
744-
{
745-
setThreadPoolMinThread(-1); //decrease the Threadpool
746-
}
747-
734+
await handleClient(tcpClient, endPoint);
748735
});
749736
}
750737

751738
// Get the listener that handles the client request.
752739
endPoint.Listener.BeginAcceptTcpClient(onAcceptConnection, endPoint);
753740
}
754741

755-
private Lazy<int> maxWorkerThreads = new Lazy<int>(() =>
756-
{
757-
int maxWorkerThreads;
758-
ThreadPool.GetMaxThreads(out maxWorkerThreads, out var _);
759-
return maxWorkerThreads;
760-
});
761742

762743
/// <summary>
763744
/// Change the ThreadPool.WorkerThread minThread
764745
/// </summary>
765-
/// <param name="workerThreadsToAdd">Number of threads to add</param>
766-
private void setThreadPoolMinThread(int workerThreadsToAdd)
746+
/// <param name="workerThreadsToAdd">minimum Threads allocated in the ThreadPool</param>
747+
private void setThreadPoolMinThread(int workerThreads)
767748
{
768-
if (EnableThreadPoolOptimizing)
769-
{
770-
lock (lockThreadPoolTuning)
771-
{
772-
int minWorkerThreads, minCompletionPortThreads;
749+
int minWorkerThreads, minCompletionPortThreads, maxWorkerThreads;
773750

774-
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
775-
minWorkerThreads = Math.Max(minWorkerThreads + workerThreadsToAdd, Environment.ProcessorCount);
751+
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
752+
ThreadPool.GetMaxThreads(out maxWorkerThreads, out _);
776753

777-
if (minWorkerThreads <= maxWorkerThreads.Value)
778-
{
779-
ThreadPool.SetMinThreads(minWorkerThreads, minCompletionPortThreads);
780-
}
781-
}
782-
}
754+
minWorkerThreads = Math.Min(maxWorkerThreads, Math.Max(workerThreads, Environment.ProcessorCount));
755+
756+
ThreadPool.SetMinThreads(minWorkerThreads, minCompletionPortThreads);
783757
}
784758

759+
785760
/// <summary>
786761
/// Handle the client.
787762
/// </summary>

src/Titanium.Web.Proxy/Titanium.Web.Proxy.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="BrotliSharpLib" Version="0.3.1" />
17-
<PackageReference Include="Portable.BouncyCastle" Version="1.8.3.37" />
18-
<PackageReference Include="StreamExtended" Version="1.0.190" />
16+
<PackageReference Include="BrotliSharpLib" Version="0.3.3" />
17+
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5" />
18+
<PackageReference Include="StreamExtended" Version="1.0.201" />
1919
</ItemGroup>
2020

2121
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">

src/Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
<tags></tags>
1616
<dependencies>
1717
<group targetFramework="net45">
18-
<dependency id="StreamExtended" version="1.0.190" />
19-
<dependency id="Portable.BouncyCastle" version="1.8.3.37" />
20-
<dependency id="BrotliSharpLib" version="0.3.1" />
18+
<dependency id="StreamExtended" version="1.0.201" />
19+
<dependency id="Portable.BouncyCastle" version="1.8.5" />
20+
<dependency id="BrotliSharpLib" version="0.3.3" />
2121
</group>
2222
<group targetFramework="netstandard2.0">
23-
<dependency id="StreamExtended" version="1.0.190" />
24-
<dependency id="Portable.BouncyCastle" version="1.8.3.37" />
25-
<dependency id="BrotliSharpLib" version="0.3.1" />
23+
<dependency id="StreamExtended" version="1.0.201" />
24+
<dependency id="Portable.BouncyCastle" version="1.8.5" />
25+
<dependency id="BrotliSharpLib" version="0.3.3" />
2626
<dependency id="Microsoft.Win32.Registry" version="4.4.0" />
2727
<dependency id="System.Security.Principal.Windows" version="4.4.1" />
2828
</group>

0 commit comments

Comments
 (0)