Skip to content

Commit cff5645

Browse files
committed
don't throw exception
1 parent 4f368ac commit cff5645

File tree

1 file changed

+5
-41
lines changed

1 file changed

+5
-41
lines changed

src/SuperSocket.Connection/PipeConnectionBase.cs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -117,43 +117,16 @@ public async override IAsyncEnumerable<TPackageInfo> RunAsync<TPackageInfo>(IPip
117117

118118
_connectionTask = GetConnectionTask(readTaskCompletionSource.Task, _cts.Token);
119119

120-
var packagePipeEnumerator = ReadPipeAsync<TPackageInfo>(InputReader, _cts.Token).GetAsyncEnumerator(_cts.Token);
121-
122-
Exception exception = null;
123-
124-
while (true)
120+
try
125121
{
126-
var read = false;
127-
128-
try
129-
{
130-
read = await packagePipeEnumerator.MoveNextAsync().ConfigureAwait(false);
131-
}
132-
catch (OperationCanceledException)
133-
{
134-
break;
135-
}
136-
catch (Exception e)
137-
{
138-
exception = e;
139-
OnError("Unhandled exception in the method PipeConnection.Run.", e);
140-
break;
141-
}
142-
143-
if (read)
122+
await foreach (var packageInfo in ReadPipeAsync<TPackageInfo>(InputReader, _cts.Token))
144123
{
145-
yield return packagePipeEnumerator.Current;
146-
continue;
124+
yield return packageInfo;
147125
}
148-
149-
break;
150126
}
151-
152-
readTaskCompletionSource.TrySetResult();
153-
154-
if (exception != null)
127+
finally
155128
{
156-
throw exception;
129+
readTaskCompletionSource.TrySetResult();
157130
}
158131

159132
yield break;
@@ -391,8 +364,6 @@ protected async IAsyncEnumerable<TPackageInfo> ReadPipeAsync<TPackageInfo>(PipeR
391364
{
392365
var pipelineFilter = _pipelineFilter as IPipelineFilter<TPackageInfo>;
393366

394-
Exception exception = null;
395-
396367
while (!cancellationToken.IsCancellationRequested)
397368
{
398369
ReadResult result;
@@ -431,7 +402,6 @@ protected async IAsyncEnumerable<TPackageInfo> ReadPipeAsync<TPackageInfo>(PipeR
431402

432403
if (bufferFilterResult.Exception != null)
433404
{
434-
exception = bufferFilterResult.Exception;
435405
OnError("Protocol error", bufferFilterResult.Exception);
436406
CloseReason = Connection.CloseReason.ProtocolError;
437407
Close();
@@ -460,12 +430,6 @@ protected async IAsyncEnumerable<TPackageInfo> ReadPipeAsync<TPackageInfo>(PipeR
460430
}
461431

462432
await CompleteReaderAsync(reader, _isDetaching).ConfigureAwait(false);
463-
464-
if (exception != null)
465-
{
466-
throw exception;
467-
}
468-
469433
yield break;
470434
}
471435

0 commit comments

Comments
 (0)