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

Commit 270c57c

Browse files
committed
soks4 cleanup
1 parent 5bd2c5c commit 270c57c

File tree

6 files changed

+192
-206
lines changed

6 files changed

+192
-206
lines changed

src/Titanium.Web.Proxy/ProxySocket/Authentication/AuthUserPass.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public override void BeginAuthenticate(HandShakeComplete callback)
110110
{
111111
CallBack = callback;
112112
Server.BeginSend(GetAuthenticationBytes(), 0, GetAuthenticationLength(), SocketFlags.None,
113-
new AsyncCallback(this.OnSent), Server);
113+
this.OnSent, Server);
114114
return;
115115
}
116116

@@ -125,7 +125,7 @@ private void OnSent(IAsyncResult ar)
125125
if (Server.EndSend(ar) < GetAuthenticationLength())
126126
throw new SocketException(10054);
127127
Buffer = new byte[2];
128-
Server.BeginReceive(Buffer, 0, 2, SocketFlags.None, new AsyncCallback(this.OnReceive), Server);
128+
Server.BeginReceive(Buffer, 0, 2, SocketFlags.None, this.OnReceive, Server);
129129
}
130130
catch (Exception e)
131131
{
@@ -152,7 +152,7 @@ private void OnReceive(IAsyncResult ar)
152152
throw new ProxyException("Username/password combination not accepted.");
153153
else
154154
Server.BeginReceive(Buffer, Received, Buffer.Length - Received, SocketFlags.None,
155-
new AsyncCallback(this.OnReceive), Server);
155+
this.OnReceive, Server);
156156
}
157157
catch (Exception e)
158158
{

src/Titanium.Web.Proxy/ProxySocket/HttpsHandler.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ public override void Negotiate(string host, int port)
170170
/// <param name="remoteEP">An IPEndPoint that represents the remote device.</param>
171171
/// <param name="callback">The method to call when the negotiation is complete.</param>
172172
/// <param name="proxyEndPoint">The IPEndPoint of the HTTPS proxy server.</param>
173+
/// <param name="state">The state.</param>
173174
/// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns>
174175
public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeComplete callback,
175-
IPEndPoint proxyEndPoint)
176+
IPEndPoint proxyEndPoint, object state)
176177
{
177-
return BeginNegotiate(remoteEP.Address.ToString(), remoteEP.Port, callback, proxyEndPoint);
178+
return BeginNegotiate(remoteEP.Address.ToString(), remoteEP.Port, callback, proxyEndPoint, state);
178179
}
179180

180181
/// <summary>
@@ -184,14 +185,15 @@ public override IAsyncProxyResult BeginNegotiate(IPEndPoint remoteEP, HandShakeC
184185
/// <param name="port">The port to connect to.</param>
185186
/// <param name="callback">The method to call when the negotiation is complete.</param>
186187
/// <param name="proxyEndPoint">The IPEndPoint of the HTTPS proxy server.</param>
188+
/// <param name="state">The state.</param>
187189
/// <returns>An IAsyncProxyResult that references the asynchronous connection.</returns>
188190
public override IAsyncProxyResult BeginNegotiate(string host, int port, HandShakeComplete callback,
189-
IPEndPoint proxyEndPoint)
191+
IPEndPoint proxyEndPoint, object state)
190192
{
191193
ProtocolComplete = callback;
192194
Buffer = GetConnectBytes(host, port);
193-
Server.BeginConnect(proxyEndPoint, new AsyncCallback(this.OnConnect), Server);
194-
AsyncResult = new IAsyncProxyResult();
195+
Server.BeginConnect(proxyEndPoint, this.OnConnect, Server);
196+
AsyncResult = new IAsyncProxyResult(state);
195197
return AsyncResult;
196198
}
197199

@@ -213,7 +215,7 @@ private void OnConnect(IAsyncResult ar)
213215

214216
try
215217
{
216-
Server.BeginSend(Buffer, 0, Buffer.Length, SocketFlags.None, new AsyncCallback(this.OnConnectSent),
218+
Server.BeginSend(Buffer, 0, Buffer.Length, SocketFlags.None, this.OnConnectSent,
217219
null);
218220
}
219221
catch (Exception e)
@@ -233,7 +235,7 @@ private void OnConnectSent(IAsyncResult ar)
233235
HandleEndSend(ar, Buffer.Length);
234236
Buffer = new byte[13];
235237
Received = 0;
236-
Server.BeginReceive(Buffer, 0, 13, SocketFlags.None, new AsyncCallback(this.OnConnectReceive), Server);
238+
Server.BeginReceive(Buffer, 0, 13, SocketFlags.None, this.OnConnectReceive, Server);
237239
}
238240
catch (Exception e)
239241
{
@@ -262,7 +264,7 @@ private void OnConnectReceive(IAsyncResult ar)
262264
if (Received < 13)
263265
{
264266
Server.BeginReceive(Buffer, Received, 13 - Received, SocketFlags.None,
265-
new AsyncCallback(this.OnConnectReceive), Server);
267+
this.OnConnectReceive, Server);
266268
}
267269
else
268270
{
@@ -305,7 +307,7 @@ private void ReadUntilHeadersEnd(bool readFirstByte)
305307
}
306308
else
307309
{
308-
Server.BeginReceive(Buffer, 0, 1, SocketFlags.None, new AsyncCallback(this.OnEndHeadersReceive),
310+
Server.BeginReceive(Buffer, 0, 1, SocketFlags.None, this.OnEndHeadersReceive,
309311
Server);
310312
}
311313
}

0 commit comments

Comments
 (0)