Proactor模式的ACE_Service_Handler中如何得到对方IP
我需要在ACE_Service_Handler的open函数(virtual void open(ACE_HANDLE h, ACE_Message_Block& mb))中得到对方IP,即如何通过已知的socket连接句柄(ACE_HANDLE h)得到对方的IP? 不同的os有不同的api,这个跟ace无关 看一下ACE_Service_Handle的address挂钩方法,重载即可 Each networked application service class in the ACE Proactor framework derives from ACE_Service_Handler. Its key methods are shown in the following table:Method
Description
open()
Hook method called to initialize the service after establishing a new connection
addresses()
Hook method to capture the local and remote addresses for the service connection
As mentioned above, ACE_Asynch_Acceptor and ACE_Asynch_Connector both call the ACE_Service_Handler::open() hook method for each new connection established. The handle argument is the handle for the connected socket. The ACE_Message_Block argument may contain data from the peer if the bytes_to_read parameter to ACE_Asynch_Acceptor::open() was greater than 0. Since this Windows-specific facility is often used with non-IP protocols (e.g., X.25), we don't discuss its use here. The ACE Proactor framework manages the ACE_Message_Block, so the service need not be concerned with it.
If the service handler requires either the local or peer addresses on the new connection, it must implement the addresses() hook method to capture them when the connection is established. The ACE Proactor framework calls this method if the pass_address argument to the asynchronous connection factory was 1. This method is more significant on Windows because the connection addresses cannot be obtained any other way when asynchronous connection establishment is used.
页:
[1]