Skip to content

Commit

Permalink
fix: HttpSocks5Service.Stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Aug 8, 2021
1 parent 5e1d6b6 commit 09dd5d6
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions HttpProxy/HttpSocks5Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace HttpProxy
{
public class HttpSocks5Service
{
private readonly TcpListener _tcpListener;
public TcpListener TcpListener { get; }

private readonly HttpToSocks5 _httpToSocks5;
private readonly Socks5CreateOption _socks5CreateOption;
private readonly CancellationTokenSource _cts;
Expand All @@ -24,7 +25,7 @@ public HttpSocks5Service(IPEndPoint local, HttpToSocks5 httpToSocks5, Socks5Crea
throw new ArgumentNullException(nameof(socks5CreateOption.Address));
}

_tcpListener = new TcpListener(local);
TcpListener = new TcpListener(local);
_httpToSocks5 = httpToSocks5;
_socks5CreateOption = socks5CreateOption;

Expand All @@ -35,10 +36,10 @@ public async ValueTask StartAsync()
{
try
{
_tcpListener.Start();
TcpListener.Start();
while (!_cts.IsCancellationRequested)
{
var rec = await _tcpListener.AcceptTcpClientAsync();
var rec = await TcpListener.AcceptTcpClientAsync();
rec.NoDelay = true;
HandleAsync(rec, _cts.Token).Forget();
}
Expand Down Expand Up @@ -98,7 +99,14 @@ static bool IsSocks5Header(ReadOnlySequence<byte> buffer)

public void Stop()
{
_cts.Cancel();
try
{
TcpListener.Stop();
}
finally
{
_cts.Cancel();
}
}
}
}

0 comments on commit 09dd5d6

Please sign in to comment.