Fixing LWIP Stack Shutdown Issues and Optimizations
Version Information
1.0.0.26016 (Build 20260103)
Commit Summary
This commit fixes a critical protocol stack error that caused VPN's TCP functionality to fail and includes two modernization improvements aimed at enhancing code quality and performance.
Detailed Changes
1. Fixed VPN TCP Connection Failure Caused by Erroneous LWIP Stack Shutdown
- Issue: On Windows platforms (which use the LWIP protocol stack by default), the VPN client could not access the internet via the TCP protocol. The TCP_PCB state was abnormal.
- Root Cause: In the
VNetstack::TapTcpClient::Finalize()function, cleanup for a single session erroneously invoked the globallwip::netstack::close(), causing the entire protocol stack to shut down. - Change: Removed the erroneous
lwip::netstack::close()call. Now only sets thedisposed_ = TRUEflag to correctly track the session lifecycle. - Impact: After the fix, LWIP works stably on all supported platforms, and the VPN can correctly manage user TCP connections.
2. Optimization: Replaced NULL with NULLPTR Macro
- Change: Globally replaced
NULLwith theNULLPTRmacro (i.e., C++11'snullptr). - Reason: Leverages the
std::nullptr_ttype to improve type safety, eliminate overload ambiguity, and optimize container-related code, aligning with modern C++ standards.
3. Optimization: Introduced FUNCTION Compiler Macro, Defaulting to std::function
- Change: In CMakeList.txt (or the corresponding VS project properties), the
FUNCTIONcompiler macro is now predefined by default. This macro directs the code to usestd::functioninstead of the project's customppp::functionin non-LLVM libc++ environments (e.g., gcc's libstdc++, msvcrt). - Basis: Referencing the implementation and testing of medium-frequency event queues (https://blog.csdn.net/liulilittle/article/details/156061074), in most small-call scenarios,
std::functionoften performs better due to its Small Buffer Optimization (SBO) strategy. SBO stores small callable objects inline, avoiding heap allocation overhead. - Summary: In general standard library environments, using the thread-safe and highly optimized
std::functiontypically yields better and more stable performance compared to non-thread-safe custom implementations.