I don't know if you have encountered such a problem, the code is as follows: ACE_ASYNCH_ACCEPTOR
First, I tried to take the port number through the Winsocket API direct operation, because the Acceptor object provides a get_handler () method
sockaddr_in addr1; int addr1len = sizeof (struct sockaddr); if (! ACE_OS :: getsockname (acceptor.get_handle (), (sockaddr *) & addr1, & addr1len) = 0) {ACE_DEBUG ((LM_DEBUG, "Error!")); } ACE_DEBUG ((LM_Debug, "Port:% D /N", ADDR1.SIN_PORT));
The code is running correctly, the port number also appears in the console, but an invalid port number, that is, the above code is wrong.
Looking for N for a long time online until a class comes with a class comes with a class comes with a class that comes with the ACE, it is finally calculated as follows: ACE_SOCK_SEQPACK_ASSOCIATION A = ACE_SOCK_SEQPACK_ASSOCIATION (Acceptor.get_Handle ()); size_t Addr_size = 1; A.GET_LOCAL_ADDRS (& addr, addr_size); ACE_DEBUG ((LM_DEBUG, "Port:% D / N", addr.get_port_number ()));
This is the true port number in the listener.
I wanted to give up, but I still didn't give up.