[] Once and for all to share practical experience of solving random hot-plug cable problem

Description: The

cable is hot swappable real problem often encountered in the project, there are a variety of hot-swap deal with specific situations to be here to share Applicated program.


The kind of hot-plug problem:
1, before switching on the network cable has not been inserted, how to insert after power handling.
2, when the server mode is used, the cable disconnection is detected, how to handle re-inserted.
3, the client mode, detect the network cable is disconnected, and how to handle re-inserted.
4, for a long time off, such as more than one hour after the re-insertion of the protocol stack can not function properly what to do.
5, the cable is switched from one network environment to another network environment.

These questions, if specific problems with a specific solution would be too cumbersome. And the logic is not easy to stroke along.

Solution:
here to share a solution for everyone, with a new version of the RL-TCPnet V7.X example.
1, has a special plug network notification function, through this function can easily understand the network swap information.
2, then there is the initialization function netInitialize () and a reset initialization function netUninitialize (), where the initial reset functions are especially useful in the detection of the network cable is unplugged, this function is called to release all network resources will be used by the user, and delete Ethernet interface and protocol stack task kernel tasks.
3, the last task is a variety of user-created applications, we will delete it here directly after detecting unplug the network cable (priority call any network reset and then deleted), to detect re-created after the network cable insertion.

Specific processing:
network message function plug, where a global variable directly to identify the state of the plug.
Of course, the pursuit of efficiency, the task can also be used semaphores, event flags, etc., there is no reason that we all used when it is prone to transplant did not go to create a task components used.
 

Open a special network initialization and testing tasks to deal with the problem swap:
 

the actual test results were satisfactory, so do not have specific conditions, and direct all questions have all been dealt with.

Guess you like

Origin www.cnblogs.com/armfly/p/11818240.html