178 lines
4.7 KiB
C#
178 lines
4.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
|
|
namespace System.Net
|
|
{
|
|
// Token: 0x02000264 RID: 612
|
|
internal class WebConnectionGroup
|
|
{
|
|
// Token: 0x06001658 RID: 5720 RVA: 0x0004A200 File Offset: 0x00048400
|
|
public WebConnectionGroup(ServicePoint sPoint, string name)
|
|
{
|
|
this.sPoint = sPoint;
|
|
this.name = name;
|
|
this.connections = new ArrayList(1);
|
|
this.queue = new Queue();
|
|
}
|
|
|
|
// Token: 0x06001659 RID: 5721 RVA: 0x0004A230 File Offset: 0x00048430
|
|
public void Close()
|
|
{
|
|
ArrayList arrayList = this.connections;
|
|
lock (arrayList)
|
|
{
|
|
int count = this.connections.Count;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
WeakReference weakReference = (WeakReference)this.connections[i];
|
|
WebConnection webConnection = weakReference.Target as WebConnection;
|
|
if (webConnection != null)
|
|
{
|
|
webConnection.Close(false);
|
|
}
|
|
}
|
|
this.connections.Clear();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600165A RID: 5722 RVA: 0x0004A2D4 File Offset: 0x000484D4
|
|
public WebConnection GetConnection(HttpWebRequest request)
|
|
{
|
|
WebConnection webConnection = null;
|
|
ArrayList arrayList = this.connections;
|
|
lock (arrayList)
|
|
{
|
|
int count = this.connections.Count;
|
|
ArrayList arrayList2 = null;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
WeakReference weakReference = (WeakReference)this.connections[i];
|
|
webConnection = weakReference.Target as WebConnection;
|
|
if (webConnection == null)
|
|
{
|
|
if (arrayList2 == null)
|
|
{
|
|
arrayList2 = new ArrayList(1);
|
|
}
|
|
arrayList2.Add(i);
|
|
}
|
|
}
|
|
if (arrayList2 != null)
|
|
{
|
|
for (int j = arrayList2.Count - 1; j >= 0; j--)
|
|
{
|
|
this.connections.RemoveAt((int)arrayList2[j]);
|
|
}
|
|
}
|
|
webConnection = this.CreateOrReuseConnection(request);
|
|
}
|
|
return webConnection;
|
|
}
|
|
|
|
// Token: 0x0600165B RID: 5723 RVA: 0x0004A3CC File Offset: 0x000485CC
|
|
private static void PrepareSharingNtlm(WebConnection cnc, HttpWebRequest request)
|
|
{
|
|
if (!cnc.NtlmAuthenticated)
|
|
{
|
|
return;
|
|
}
|
|
bool flag = false;
|
|
NetworkCredential ntlmCredential = cnc.NtlmCredential;
|
|
NetworkCredential credential = request.Credentials.GetCredential(request.RequestUri, "NTLM");
|
|
if (ntlmCredential.Domain != credential.Domain || ntlmCredential.UserName != credential.UserName || ntlmCredential.Password != credential.Password)
|
|
{
|
|
flag = true;
|
|
}
|
|
if (!flag)
|
|
{
|
|
bool unsafeAuthenticatedConnectionSharing = request.UnsafeAuthenticatedConnectionSharing;
|
|
bool unsafeAuthenticatedConnectionSharing2 = cnc.UnsafeAuthenticatedConnectionSharing;
|
|
flag = !unsafeAuthenticatedConnectionSharing || unsafeAuthenticatedConnectionSharing != unsafeAuthenticatedConnectionSharing2;
|
|
}
|
|
if (flag)
|
|
{
|
|
cnc.Close(false);
|
|
cnc.ResetNtlm();
|
|
}
|
|
}
|
|
|
|
// Token: 0x0600165C RID: 5724 RVA: 0x0004A484 File Offset: 0x00048684
|
|
private WebConnection CreateOrReuseConnection(HttpWebRequest request)
|
|
{
|
|
int num = this.connections.Count;
|
|
WebConnection webConnection;
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
WeakReference weakReference = this.connections[i] as WeakReference;
|
|
webConnection = weakReference.Target as WebConnection;
|
|
if (webConnection == null)
|
|
{
|
|
this.connections.RemoveAt(i);
|
|
num--;
|
|
i--;
|
|
}
|
|
else if (!webConnection.Busy)
|
|
{
|
|
WebConnectionGroup.PrepareSharingNtlm(webConnection, request);
|
|
return webConnection;
|
|
}
|
|
}
|
|
if (this.sPoint.ConnectionLimit > num)
|
|
{
|
|
webConnection = new WebConnection(this, this.sPoint);
|
|
this.connections.Add(new WeakReference(webConnection));
|
|
return webConnection;
|
|
}
|
|
if (this.rnd == null)
|
|
{
|
|
this.rnd = new Random();
|
|
}
|
|
int num2 = ((num <= 1) ? 0 : this.rnd.Next(0, num - 1));
|
|
WeakReference weakReference2 = (WeakReference)this.connections[num2];
|
|
webConnection = weakReference2.Target as WebConnection;
|
|
if (webConnection == null)
|
|
{
|
|
webConnection = new WebConnection(this, this.sPoint);
|
|
this.connections.RemoveAt(num2);
|
|
this.connections.Add(new WeakReference(webConnection));
|
|
}
|
|
return webConnection;
|
|
}
|
|
|
|
// Token: 0x1700072C RID: 1836
|
|
// (get) Token: 0x0600165D RID: 5725 RVA: 0x0004A5C0 File Offset: 0x000487C0
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return this.name;
|
|
}
|
|
}
|
|
|
|
// Token: 0x1700072D RID: 1837
|
|
// (get) Token: 0x0600165E RID: 5726 RVA: 0x0004A5C8 File Offset: 0x000487C8
|
|
internal Queue Queue
|
|
{
|
|
get
|
|
{
|
|
return this.queue;
|
|
}
|
|
}
|
|
|
|
// Token: 0x04001236 RID: 4662
|
|
private ServicePoint sPoint;
|
|
|
|
// Token: 0x04001237 RID: 4663
|
|
private string name;
|
|
|
|
// Token: 0x04001238 RID: 4664
|
|
private ArrayList connections;
|
|
|
|
// Token: 0x04001239 RID: 4665
|
|
private Random rnd;
|
|
|
|
// Token: 0x0400123A RID: 4666
|
|
private Queue queue;
|
|
}
|
|
}
|