An efficient communication model--Asynchronous communication model

Source: Internet
Author: User



#异步模型
#异步和同步 > synchronization, when a function call is made, the call does not return > async until the result is obtained, and when an asynchronous procedure call is made, the caller cannot immediately get the result of the call, but instead notifies the caller by state, notification, and callback. > by checking the status to determine the result of an asynchronous call, the efficiency is very low, because you need periodic check status > Callback functions and Notifications almost
#同步调用与阻塞调用 > For synchronous calls, the current thread is still active. For example, the receive function is called in CSocket, and while the buffer has no data, the function waits and does not return, but the thread continues to process various messages. > The current thread is suspended for blocking calls. For example, the REVC function, when the socket is working in blocking mode, if the function is called with no data in the buffer, then the thread will be suspended until there is data.
#非阻塞非阻塞, the function does not block the current thread until the result is not available, but returns immediately. > Whether the object is in blocking mode and the function is not blocking calls have a strong interest, but not one by one corresponding > blocking objects can have non-blocking invocation, can be through the API polling state, when appropriate call blocking function, you can avoid blocking. > For non-blocking objects, special calls can also enter blocking calls, such as the Select>csocket::receive function (synchronous) >recv (blocking)

#Windows下的异步通信模型由Winsock提供的异步通信模型, applications can receive network event notifications based on Windows messages on a socket. The biggest difference between the WSAAsyncSelect mode and the Select mode is that the Select mode needs to detect the socket continuously, to determine if there is no message, andWSAAsyncSelectnotifies the user when a user-defined message is received, and then handles the socket accordingly.

#WSAAsyncSelect functionWSAAsyncSelect (SOCKET S,
HWND hwnd,
Unsigned int umsg,
Long lEvent
This function is called after the socket is established to open the message notification.Levent is a combination of network events with the following values


CallWSAAsyncSelectwhen successful, the window that corresponds to the HWND receives the network event notification in the form of a Windows message.




From for notes (Wiz)

An efficient communication model--Asynchronous communication model

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.