Skip to content

Commit

Permalink
修复客户端的一个bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnycase committed Apr 21, 2017
1 parent 64ed1fb commit 2c88857
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/Moesocks.Client.Services/Network/ConnectionRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public Task SendAsync(uint sessionKey, uint identifier, object message)
_logger.LogDebug($"client: {sessionKey} Sending message {message} to server.");
await _serializer.Serialize(sessionKey, identifier, message, _secureTransport);
}
catch(Exception ex)
{
_logger.LogError(default(EventId), ex.Message, ex);
throw;
}
finally
{
_semSlim.Release();
Expand Down Expand Up @@ -110,9 +115,9 @@ private async Task BeginReceiveMessages(CancellationToken cancellationToken)
_logger.LogWarning($"Proxy stopped.");
break;
}
catch (Exception)
catch (Exception ex)
{
_receivers.Clear();
_logger.LogError(default(EventId), ex.Message, ex);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Moesocks.Client.Services/Network/HttpProxyProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ private async void DispatchIncoming(TcpClient tcpClient)
await session.Run();
}
}
}
catch(InvalidDataException)
{

}
catch (Exception ex)
{
Expand Down
21 changes: 14 additions & 7 deletions src/Moesocks.Client.Services/Network/TunnelProxySession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@ public TunnelProxySession(string targetHost, Stream remoteStream, byte[] takenBy

public async Task Run()
{
await SendOkResponse();
var tasks = new[] { RunMessageReceive(), RunClientRead() };
await Task.WhenAll(tasks);
try
{
await SendOkResponse();
var tasks = new[] { RunMessageReceive(), RunClientRead() };
await Task.WhenAll(tasks);
}
finally
{
_messageBus.EndReceive(_sessionKey);
}
}

private const string _okResponse = "HTTP/1.1 200 OK\r\n\r\n";
Expand All @@ -53,11 +60,11 @@ public async Task Run()
private async Task SendOkResponse()
{
var eor = FindEndOfRequest(_takenBytes, _takenBytes.Length);
if(eor == -1)
if (eor == -1)
{
var buffer = new byte[512];
int read = 0;
while(eor == -1)
while (eor == -1)
{
read = await _remoteStream.ReadAsync(buffer, 0, buffer.Length);
if (read == 0)
Expand All @@ -83,7 +90,7 @@ static int FindEndOfRequest(byte[] content, int length)
bool next = false;
for (int i = 0; i < _eor.Length; i++)
{
if(content[first + i] != _eor[i])
if (content[first + i] != _eor[i])
{
next = true;
break;
Expand Down Expand Up @@ -122,7 +129,7 @@ private async Task RunMessageReceive()

private async Task RunClientRead()
{
if(_takenBytes.Length != 0)
if (_takenBytes.Length != 0)
{
await _messageBus.SendAsync(_sessionKey, _identifier++, new TcpContentMessage
{
Expand Down
12 changes: 12 additions & 0 deletions src/Moesocks.Client/Views/ShellView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
SaveWindowPosition="True"
EnableDWMDropShadow="True" ShowIconOnTitleBar="True"
Height="338" Width="601" Title="Moesocks">
<metro:MetroWindow.IconTemplate>
<DataTemplate>
<Grid Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
Margin="4 4 0 4"
Background="Transparent"
RenderOptions.EdgeMode="Aliased"
RenderOptions.BitmapScalingMode="HighQuality">
<Image Source="../Assets/moesocks.ico"/>
</Grid>
</DataTemplate>
</metro:MetroWindow.IconTemplate>
<dockablz:Layout>
<dragablz:TabablzControl HeaderMemberPath="Title" ItemsSource="{Binding Pages}">
<dragablz:TabablzControl.HeaderItemTemplate>
Expand Down

0 comments on commit 2c88857

Please sign in to comment.