Skip to content

Commit 7f514a3

Browse files
committed
refactor: 代码重构精简逻辑
1 parent c870a62 commit 7f514a3

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/BootstrapBlazor/Services/TcpSocket/DefaultTcpSocketClient.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ sealed class DefaultTcpSocketClient(IPEndPoint localEndPoint) : TcpSocketClientB
2626

2727
public override void SetDataHandler(IDataPackageHandler handler)
2828
{
29+
base.SetDataHandler(handler);
30+
2931
_dataPackageHandler = handler;
3032
}
3133

@@ -214,8 +216,10 @@ private async ValueTask<int> ReceiveCoreAsync(TcpClient client, Memory<byte> buf
214216
return len;
215217
}
216218

217-
protected override ValueTask DisposeAsync(bool disposing)
219+
protected override async ValueTask DisposeAsync(bool disposing)
218220
{
221+
await base.DisposeAsync(disposing);
222+
219223
if (disposing)
220224
{
221225
LocalEndPoint = null;
@@ -236,6 +240,5 @@ protected override ValueTask DisposeAsync(bool disposing)
236240
_client = null;
237241
}
238242
}
239-
return ValueTask.CompletedTask;
240243
}
241244
}

src/BootstrapBlazor/Services/TcpSocket/TcpSocketClientBase.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ public virtual ValueTask CloseAsync()
105105
/// unmanaged resources.</param>
106106
protected virtual ValueTask DisposeAsync(bool disposing)
107107
{
108-
if (disposing)
109-
{
110-
LocalEndPoint = null;
111-
}
112108
return ValueTask.CompletedTask;
113109
}
114110

test/UnitTest/Services/TcpSocketFactoryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public async Task SendAsync_Error()
101101
// 测试未建立连接前调用 SendAsync 方法报异常逻辑
102102
var data = new ReadOnlyMemory<byte>([1, 2, 3, 4, 5]);
103103
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await client.SendAsync(data));
104-
Assert.Equal("TCP Socket is not connected 127.0.0.1:0", ex.Message);
104+
Assert.NotNull(ex);
105105
}
106106

107107
[Fact]

0 commit comments

Comments
 (0)