Non-blocking network function encapsulation inconsistency

Source: Internet
Author: User
Tags network function

16 non-blocking network function encapsulation inconsistency

The parameter design of the non-blocking network function of ACE is unreasonable. The use of the ace_time_value * timeout parameter for the non-blocking call interfaces of ace_sock_stream and ace_sock_connector is inconsistent. One uses null, but the other uses ace_time_value: zero.

Ace_sock_stream: [note] when calling the send function without blocking. The timeout parameter must be set to null. It finally calls ACE: Send. It is not acceptable to enter ace_time_value as ace_time_value: zero (0, 0. If ace_time_value: Zero is entered, the non-blocking call performance is greatly reduced.

Ssize_t

ACE: Send (ace_handle handle,

Const void * Buf,

Size_t N,

Int flags,

Const ace_time_value * timeout)

{

If (timeout = 0)

Return ACE_ OS: send (handle, (const char *) buf, n, flags );

Else

{

............

}

}

Timeout );

 

 

Note that to use non-blocking IO, you must call the recv and send functions instead of the recv_n and send_n functions. If the timeout parameter is NULL, these function interfaces are blocked.

In addition, you need to set the Socket option for non-blocking IO.

However, ACE_SOCK_Connector uses another encapsulation method. It imports a NULL value to indicate blocking, while the input ACE_Time_Value: zero (0, 0) indicates non-blocking link operations.

* @ Param timeout Pointer to an @ c ACE_Time_Value object with amount

* Of time to wait to connect. If the pointer is 0

* Then the call blocks until the connection attempt

* Is complete, whether it succeeds or fails. If

** Timeout = {0, 0} then the connection is done

* Using nonblocking mode. In this case, if

* Connection can't be made immediately, this method

* Returns-1 and errno = ewouldblock.

Int connect (ace_sock_stream & new_stream,

Const ace_addr & remote_sap,

Const ace_time_value * timeout = 0,

Const ace_addr & local_sap = ace_addr: sap_any,

Int reuse_addr = 0,

Int flags = 0,

Int perms = 0,

Int protocol = 0 );

Be careful when handling these Io operations.

 

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.