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.