Skip to content

Commit

Permalink
fix: SocketException should not stop the server
Browse files Browse the repository at this point in the history
  • Loading branch information
josephnhtam committed Mar 10, 2024
1 parent 13366c2 commit a626de0
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/LiveStreamingServerNet.Networking/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,26 @@ private async Task RunServerLoopAsync(TcpListener tcpListener, ServerEndPoint se
{
var cancellationToken = cts.Token;

try
while (!cancellationToken.IsCancellationRequested)
{
while (!cancellationToken.IsCancellationRequested)
try
{
await AcceptClientAsync(tcpListener, serverEndPoint, cancellationToken);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (SocketException ex)
{
_logger.AcceptClientError(ex);
cts.Cancel();
throw;
}
catch (Exception ex)
{
_logger.ServerLoopError(ex);
cts.Cancel();
throw;
}
catch (SocketException ex)
{
_logger.AcceptClientError(ex);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
throw;
}
catch (Exception ex)
{
_logger.ServerLoopError(ex);
cts.Cancel();
throw;
}
}
}

Expand Down

0 comments on commit a626de0

Please sign in to comment.