-
-
Notifications
You must be signed in to change notification settings - Fork 362
feat(ITcpSocketClient): add OnConnecting callback #6392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR introduces OnConnecting and OnConnected hooks to the TCP client API, refactors connection cleanup and auto-reconnect flows in DefaultTcpSocketClient, enhances disconnection detection and logging, adds a Blazor auto-reconnect demo with a mock disconnect server, and expands unit tests to cover the new callbacks and disconnect scenarios. Sequence diagram for TCP client connection with OnConnecting and OnConnected hookssequenceDiagram
participant User as actor User
participant Client as DefaultTcpSocketClient
participant Server as TcpServer
User->>Client: ConnectAsync()
alt OnConnecting callback set
Client->>Client: await OnConnecting()
end
Client->>Server: Establish TCP connection
alt OnConnected callback set
Client->>Client: await OnConnected()
end
Server-->>Client: Connection established
Class diagram for ITcpSocketClient and DefaultTcpSocketClient with new connection callbacksclassDiagram
class ITcpSocketClient {
+Func<ReadOnlyMemory<byte>, ValueTask>? ReceivedCallBack
+Func<Task>? OnConnecting
+Func<Task>? OnConnected
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask CloseAsync()
}
class DefaultTcpSocketClient {
+Func<ReadOnlyMemory<byte>, ValueTask>? ReceivedCallBack
+Func<Task>? OnConnecting
+Func<Task>? OnConnected
+ValueTask<bool> ConnectAsync(IPEndPoint, CancellationToken)
+ValueTask CloseAsync()
-ValueTask CloseCoreAsync()
-void Reconnect()
-void Log(LogLevel, Exception?, string?)
}
ITcpSocketClient <|.. DefaultTcpSocketClient
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
- Ensure existing _autoConnectTokenSource is cancelled and disposed before reassigning a new one in ConnectAsync to avoid leaking cancellation tokens.
- Wrap invocations of OnConnecting and OnConnected in try/catch blocks so that exceptions in user callbacks don’t break the connection flow.
- Move MockDisconnectServerService under the BootstrapBlazor.Server.Services namespace (instead of Longbow.Tasks.Services) to keep project namespace consistency.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Ensure existing _autoConnectTokenSource is cancelled and disposed before reassigning a new one in ConnectAsync to avoid leaking cancellation tokens.
- Wrap invocations of OnConnecting and OnConnected in try/catch blocks so that exceptions in user callbacks don’t break the connection flow.
- Move MockDisconnectServerService under the BootstrapBlazor.Server.Services namespace (instead of Longbow.Tasks.Services) to keep project namespace consistency.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6392 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 718 718
Lines 31712 31729 +17
Branches 4473 4477 +4
=========================================
+ Hits 31712 31729 +17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6391
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add OnConnecting and OnConnected callbacks around the TCP client connection process, refine auto-reconnect and resource cleanup logic, update logging behavior, introduce an auto-reconnect sample with mock disconnect server, and extend unit tests accordingly.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: