Windows network model selection experience

Source: Internet
Author: User

1. First, one thread and one socket, each read/write operation. It is suitable for beginners and some simple test clients. It is essential to get started. Don't talk about it. Remind me, the Recv and recvfrom functions can be completely locked for a long time without any response. No matter what parameters are set, the simple write server often appears. Remember to enable a thread to monitor this situation, if you disable socket, you can force it to return.

2. iocp that is blown up to the day. Similarly, there are not many bugs, it is recommended that you use it only when the logic of a single socket is exactly the same as that of the first scenario. In other cases, complicated thread synchronization is generally required, poor efficiency will completely offset the advantage of iocp, and it is best not to have any logical relationship between any two sockets. Pay attention to a bug. The socket of iocp can also be locked for a long time and cannot be returned. In fact, all setsockopt settings that may avoid this situation are invalid for the socket in iocp mode. Therefore, it is necessary to regularly check all sockets. In addition, even if the socket is closed, the wsarecv operation may not return the result from the port, but it is generally safe to delete the overlapped structure without returning the result within 30 seconds, if you need absolute security to prevent system corruption, write an overlapped structure resource pool.

3. The window message model implemented by MFC, casyncsocket. We recommend that you use the class in eMule to replace the original configuration of MFC, with better performance. If you did not intentionally initialize two sockets in two threads, there will be no thread security issues. Therefore, when implementing complicated logic, the additional overhead will be relatively small, the implementation and debugging are relatively simple. The most important thing is that this model is the only model that provides a reliable full-duplex working mode. full-duplex means reading and writing on a socket at the same time, if data exists, it is sent and received. In this mode, two data queues are required for sending queues and receiving buffer pools, and a specific function is called after receiving is successful. If this model is implemented under iocp, the performance loss of thread security is huge, which makes little sense. Let alone the frequent blocking of iocp processing threads weakens the iocp model management advantage.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.