本文整理汇总了C++中ACE_INET_Addr::set方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_INET_Addr::set方法的具体用法?C++ ACE_INET_Addr::set怎么用?C++ ACE_INET_Addr::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_INET_Addr
的用法示例。
在下文中一共展示了ACE_INET_Addr::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_tao_use
static bool test_tao_use (void)
{
char host[256];
if (::gethostname (host, 255) != 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Test TAO Use fail %p\n"),
ACE_TEXT ("gethostname")));
return false;
}
ACE_INET_Addr addr;
addr.set ((unsigned short)0, host);
ACE_CString full (host);
full += ":12345";
addr.set (full.c_str ());
u_short p = addr.get_port_number ();
if (p != 12345)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("Test TAO Use expected port 12345 got %d\n"),
p));
return false;
}
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Test TAO Use passed\n")));
return true;
}
示例2: AddListen
bool CControlListen::AddListen( const char* pListenIP, uint32 u4Port, uint8 u1IPType, int nPacketParseID)
{
bool blState = App_ConnectAcceptorManager::instance()->CheckIPInfo(pListenIP, u4Port);
if(true == blState)
{
//当前监听已经存在,不可以重复建设
OUR_DEBUG((LM_INFO, "[CServerManager::AddListen](%s:%d) is exist.\n", pListenIP, u4Port));
return false;
}
ACE_INET_Addr listenAddr;
//判断IPv4还是IPv6
int nErr = 0;
if (u1IPType == TYPE_IPV4)
{
nErr = listenAddr.set(u4Port, pListenIP);
}
else
{
nErr = listenAddr.set(u4Port, pListenIP, 1, PF_INET6);
}
if (nErr != 0)
{
OUR_DEBUG((LM_INFO, "[CControlListen::AddListen](%s:%d)set_address error[%d].\n", pListenIP, u4Port, errno));
return false;
}
//得到接收器
ConnectAcceptor* pConnectAcceptor = App_ConnectAcceptorManager::instance()->GetNewConnectAcceptor();
if (NULL == pConnectAcceptor)
{
OUR_DEBUG((LM_INFO, "[CControlListen::AddListen](%s:%d)pConnectAcceptor is NULL.\n", pListenIP, u4Port));
return false;
}
pConnectAcceptor->SetPacketParseInfoID(nPacketParseID);
int nRet = pConnectAcceptor->open2(listenAddr,
App_ReactorManager::instance()->GetAce_Reactor(REACTOR_CLIENTDEFINE),
ACE_NONBLOCK,
(int)GetXmlConfigAttribute(xmlNetWorkMode)->BackLog);
if (-1 == nRet)
{
OUR_DEBUG((LM_INFO, "[CControlListen::AddListen] Listen from [%s:%d] error(%d).\n",
listenAddr.get_host_addr(),
listenAddr.get_port_number(), errno));
return false;
}
OUR_DEBUG((LM_INFO, "[CControlListen::AddListen] Listen from [%s:%d] OK.\n", listenAddr.get_host_addr(), listenAddr.get_port_number()));
return true;
}
示例3: AddListen
bool CProControlListen::AddListen( const char* pListenIP, uint32 u4Port, uint8 u1IPType )
{
bool blState = App_ProConnectAcceptManager::instance()->CheckIPInfo(pListenIP, u4Port);
if(true == blState)
{
//当前监听已经存在,不可以重复建设
OUR_DEBUG((LM_INFO, "[CProControlListen::AddListen](%s:%d) is exist.\n", pListenIP, u4Port));
return false;
}
//创建一个新的accept对象
ProConnectAcceptor* pProConnectAcceptor = App_ProConnectAcceptManager::instance()->GetNewConnectAcceptor();
if(NULL == pProConnectAcceptor)
{
OUR_DEBUG((LM_INFO, "[CProControlListen::AddListen](%s:%d) new ConnectAcceptor error.\n", pListenIP, u4Port));
return false;
}
ACE_INET_Addr listenAddr;
//判断IPv4还是IPv6
int nErr = 0;
if(u1IPType == TYPE_IPV4)
{
nErr = listenAddr.set(u4Port, pListenIP);
}
else
{
nErr = listenAddr.set(u4Port, pListenIP, 1, PF_INET6);
}
if(nErr != 0)
{
OUR_DEBUG((LM_INFO, "[CProControlListen::AddListen](%s:%d)set_address error[%d].\n", pListenIP, u4Port, errno));
return false;
}
//创建新的监听
//设置监听IP信息
pProConnectAcceptor->SetListenInfo(pListenIP, u4Port);
ACE_Proactor* pProactor = App_ProactorManager::instance()->GetAce_Proactor(REACTOR_CLIENTDEFINE);
if(NULL == pProactor)
{
OUR_DEBUG((LM_INFO, "[CProControlListen::AddListen]App_ProactorManager::instance()->GetAce_Proactor(REACTOR_CLIENTDEFINE) is NULL.\n"));
return false;
}
int nRet = pProConnectAcceptor->open(listenAddr, 0, 1, App_MainConfig::instance()->GetBacklog(), 1, pProactor);
if(-1 == nRet)
{
OUR_DEBUG((LM_INFO, "[CProControlListen::AddListen] Listen from [%s:%d] error(%d).\n",listenAddr.get_host_addr(), listenAddr.get_port_number(), errno));
return false;
}
OUR_DEBUG((LM_INFO, "[CProControlListen::AddListen](%s:%d)Add Listen success.\n", pListenIP, u4Port));
return true;
}
示例4: str
template <class HANDLER> void
ACE_Asynch_Acceptor<HANDLER>::parse_address (const
ACE_Asynch_Accept::Result &result,
ACE_INET_Addr &remote_address,
ACE_INET_Addr &local_address)
{
ACE_TRACE ("ACE_Asynch_Acceptor<>::parse_address");
#if defined (ACE_HAS_AIO_CALLS)
// Use an ACE_SOCK to get the addresses - it knows how to deal with
// ACE_INET_Addr objects and get IPv4/v6 addresses.
ACE_SOCK_Stream str (result.accept_handle ());
str.get_local_addr (local_address);
str.get_remote_addr (remote_address);
#elif defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
ACE_Message_Block &message_block = result.message_block ();
sockaddr *local_addr = 0;
sockaddr *remote_addr = 0;
int local_size = 0;
int remote_size = 0;
// This matches setup in accept().
size_t addr_size = sizeof (sockaddr_in) + 16;
#if defined (ACE_HAS_IPV6)
if (this->addr_family_ == PF_INET6)
addr_size = sizeof (sockaddr_in6) + 16;
#endif /* ACE_HAS_IPV6 */
::GetAcceptExSockaddrs (message_block.rd_ptr (),
static_cast<DWORD> (this->bytes_to_read_),
static_cast<DWORD> (addr_size),
static_cast<DWORD> (addr_size),
&local_addr,
&local_size,
&remote_addr,
&remote_size);
local_address.set (reinterpret_cast<sockaddr_in *> (local_addr),
local_size);
remote_address.set (reinterpret_cast<sockaddr_in *> (remote_addr),
remote_size);
#else
// just in case
errno = ENOTSUP;
#endif /* defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0) */
return;
}
示例5: ConnectUDP
bool CClientReConnectManager::ConnectUDP(int nServerID, const char* pIP, int nPort, uint8 u1IPType, EM_UDP_TYPE emType, IClientUDPMessage* pClientUDPMessage)
{
ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
CReactorUDPClient* pReactorUDPClient = NULL;
//初始化连接动作
if (false == ConnectUdpInit(nServerID, pReactorUDPClient))
{
return false;
}
//初始化连接地址
ACE_INET_Addr AddrLocal;
int nErr = 0;
if (emType != UDP_BROADCAST)
{
if (u1IPType == TYPE_IPV4)
{
nErr = AddrLocal.set(nPort, pIP);
}
else
{
nErr = AddrLocal.set(nPort, pIP, 1, PF_INET6);
}
}
else
{
//如果是UDP广播
AddrLocal.set(nPort, (uint32)INADDR_ANY);
}
if (nErr != 0)
{
OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectUDP](%d)UDP set_address error[%d].\n", nServerID, errno));
SAFE_DELETE(pReactorUDPClient);
return false;
}
//开始连接
if (0 != pReactorUDPClient->OpenAddress(AddrLocal, emType, App_ReactorManager::instance()->GetAce_Reactor(REACTOR_UDPDEFINE), pClientUDPMessage))
{
OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectUDP](%d)UDP OpenAddress error.\n", nServerID));
SAFE_DELETE(pReactorUDPClient);
return false;
}
return true;
}
示例6: ConnectUDP
bool CClientReConnectManager::ConnectUDP(int nServerID, const char* pIP, int nPort, uint8 u1IPType, IClientUDPMessage* pClientUDPMessage)
{
ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_ThreadWritrLock);
mapReactorUDPConnectInfo::iterator f = m_mapReactorUDPConnectInfo.find(nServerID);
if (f != m_mapReactorUDPConnectInfo.end())
{
//如果这个链接已经存在,则不创建新的链接
OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::ConnectUDP]nServerID =(%d) is exist.\n", nServerID));
return false;
}
CReactorUDPClient* pReactorUDPClient = new CReactorUDPClient();
if (NULL == pReactorUDPClient)
{
OUR_DEBUG((LM_ERROR, "[CClientReConnectManager::ConnectUDP]nServerID =(%d) pProactorUDPClient is NULL.\n", nServerID));
return false;
}
m_mapReactorUDPConnectInfo[nServerID] = pReactorUDPClient;
ACE_INET_Addr AddrLocal;
int nErr = 0;
if (u1IPType == TYPE_IPV4)
{
nErr = AddrLocal.set(nPort, pIP);
}
else
{
nErr = AddrLocal.set(nPort, pIP, 1, PF_INET6);
}
if (nErr != 0)
{
OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectUDP](%d)UDP set_address error[%d].\n", nServerID, errno));
SAFE_DELETE(pReactorUDPClient);
return false;
}
if (0 != pReactorUDPClient->OpenAddress(AddrLocal, App_ReactorManager::instance()->GetAce_Reactor(REACTOR_UDPDEFINE), pClientUDPMessage))
{
OUR_DEBUG((LM_INFO, "[CClientReConnectManager::ConnectUDP](%d)UDP OpenAddress error.\n", nServerID));
SAFE_DELETE(pReactorUDPClient);
return false;
}
return true;
}
示例7: SendMessage
bool CProactorUDPClient::SendMessage(const char* pMessage, uint32 u4Len, const char* szIP, int nPort)
{
ACE_INET_Addr AddrRemote;
int nErr = AddrRemote.set(nPort, szIP);
if(nErr != 0)
{
OUR_DEBUG((LM_INFO, "[CProactorUDPClient::SendMessage]set_address error[%d].\n", errno));
SAFE_DELETE_ARRAY(pMessage);
return false;
}
int nSize = (int)m_skRemote.send(pMessage, u4Len, AddrRemote);
if((uint32)nSize == u4Len)
{
m_atvOutput = ACE_OS::gettimeofday();
m_u4SendSize += u4Len;
m_u4SendPacketCount++;
SAFE_DELETE_ARRAY(pMessage);
return true;
}
else
{
OUR_DEBUG((LM_ERROR, "[CProactorUDPClient::SendMessage]send error(%d).\n", errno));
SAFE_DELETE_ARRAY(pMessage);
return false;
}
}
示例8: registerTCPHandlers
int HandlersRegister::registerTCPHandlers ()
{
ACE_INET_Addr addr (BaseTCPPort);
if (-1 == acceptor_->open (addr, reactor_, 1))
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT (" (%P) %p\n"),
ACE_TEXT ("Cannot open acceptor port")),
-1);
int i;
addr.set (BaseTCPPort, ACE_TEXT ("127.0.0.1"));
for (i = 0; i < HandlersNo; ++i)
{
if (-1 == connectors_[ i ]->connect (
TCPClients_[ i ],
addr,
ACE_Synch_Options::asynch))
if (errno != EWOULDBLOCK )
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT (" (%P) %p (%d)\n"),
ACE_TEXT ("Cannot connect connector"),
i),
-1);
}
return 0;
}
示例9: connectGate
void ManageGateSession::connectGate()
{
const GateCfgVec_t & gate_cfg_vec = ManageConfig::instance()->getGateCfg();
ACE_SOCK_Connector connector;
ACE_INET_Addr addr;
for (GateCfgVec_t::const_iterator it = gate_cfg_vec.begin(); it != gate_cfg_vec.end(); )
{
addr.set(it->port, it->ip.c_str());
GateSession * gate_session = new GateSession();
if (connector.connect(gate_session->peer(), addr) == -1)
{
DEF_LOG_ERROR("Failed to connector gate, ip is <%s>, port is <%d>, last error is <%d>\n", it->ip.c_str(), it->port, ACE_OS::last_error());
ACE_OS::sleep(1);
continue;
}
else
{
gate_session->setPacketHandler(RouteGatePacket::instance());
gate_session->netConnected();
gate_session->peer().enable(ACE_NONBLOCK);
int flag = 1;
gate_session->peer().set_option(IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
m_reactor->register_handler(gate_session, ACE_Event_Handler::READ_MASK);
++it;
}
}
}
示例10: defined
template <class HANDLER> void
ACE_Asynch_Connector<HANDLER>::parse_address (const ACE_Asynch_Connect::Result &result,
ACE_INET_Addr &remote_address,
ACE_INET_Addr &local_address)
{
#if defined (ACE_HAS_IPV6)
// Getting the addresses.
sockaddr_in6 local_addr;
sockaddr_in6 remote_addr;
#else
// Getting the addresses.
sockaddr_in local_addr;
sockaddr_in remote_addr;
#endif /* ACE_HAS_IPV6 */
// Get the length.
int local_size = sizeof (local_addr);
int remote_size = sizeof (remote_addr);
// Get the local address.
if (ACE_OS::getsockname (result.connect_handle (),
reinterpret_cast<sockaddr *> (&local_addr),
&local_size) < 0)
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT("%p\n"),
ACE_TEXT("ACE_Asynch_Connector::<getsockname> failed")));
// Get the remote address.
if (ACE_OS::getpeername (result.connect_handle (),
reinterpret_cast<sockaddr *> (&remote_addr),
&remote_size) < 0)
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT("%p\n"),
ACE_TEXT("ACE_Asynch_Connector::<getpeername> failed")));
// Set the addresses.
local_address.set (reinterpret_cast<sockaddr_in *> (&local_addr),
local_size);
remote_address.set (reinterpret_cast<sockaddr_in *> (&remote_addr),
remote_size);
return;
}
示例11: check_in_udp
int YARPNameClient::check_in_udp(const YARPString &name, const ACE_INET_Addr ®_addr, ACE_INET_Addr &addr, NetInt32 *ports, NetInt32 n)
{
YNC("YNC %s:%d --> check in %s\n",__FILE__,__LINE__,name.c_str());
int ret = YARP_FAIL;
mutex_.Wait();
YARPString ip = reg_addr.get_host_addr();
ret = _checkInUdp(name, ip, ports, n);
addr.set (ports[0], ip.c_str());
mutex_.Post();
return ret;
}
示例12: binding
bool CACETrbNetAcceptorImpl::binding(const CDENET::SInetAddress& address)
{
ACE_INET_Addr aceAddr;
aceAddr.set(address.port, address.ip);
return TRB_Asynch_Acceptor<CACETrbNetConnectionImpl>::open(
aceAddr,
0,
1,
ACE_DEFAULT_ASYNCH_BACKLOG,
1,
TRB_Proactor::instance(),
1
) != -1;
}
示例13: Server_Manager_Common_Addr
bool Server_Manager_Common_Addr(uint8 u4IpType, const char* pIP, uint32 u4Port, ACE_INET_Addr& listenAddr)
{
//判断IPv4还是IPv6
int nErr = 0;
if (u4IpType == TYPE_IPV4)
{
if (ACE_OS::strcmp(pIP, "INADDR_ANY") == 0)
{
nErr = listenAddr.set(u4Port, (uint32)INADDR_ANY);
}
else
{
nErr = listenAddr.set(u4Port, pIP);
}
}
else
{
if (ACE_OS::strcmp(pIP, "INADDR_ANY") == 0)
{
nErr = listenAddr.set(u4Port, (uint32)INADDR_ANY);
}
else
{
nErr = listenAddr.set(u4Port, pIP, 1, PF_INET6);
}
}
if (nErr != 0)
{
OUR_DEBUG((LM_INFO, "[Server_Manager_Common_Addr](%d)set_address error[%s:%d].\n", pIP, u4Port, errno));
return false;
}
return true;
}
示例14: sa
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
// Register a signal handler.
ACE_Sig_Action sa ((ACE_SignalHandler) handler, SIGINT);
ACE_UNUSED_ARG (sa);
Logging_Acceptor *peer_acceptor;
ACE_NEW_RETURN (peer_acceptor,
Logging_Acceptor,
1);
ACE_INET_Addr addr (PORT);
ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:"));
for (int c; (c = get_opt ()) != -1; )
switch (c)
{
case 'p':
addr.set (ACE_OS::atoi (get_opt.opt_arg ()));
break;
default:
break;
}
if (peer_acceptor->open (addr) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("open")),
-1);
else if (REACTOR::instance ()->register_handler (peer_acceptor,
ACE_Event_Handler::ACCEPT_MASK) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("registering service with ACE_Reactor\n")),
-1);
// Run forever, performing the logging service.
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%P|%t) starting up server logging daemon\n")));
while (!finished)
REACTOR::instance ()->handle_events ();
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%P|%t) shutting down server logging daemon\n")));
return 0;
}
示例15:
int
TAO_AV_SCTP_SEQ_Acceptor::open_default (TAO_Base_StreamEndPoint *endpoint,
TAO_AV_Core *av_core,
TAO_FlowSpec_Entry *entry,
TAO_AV_Flow_Protocol_Factory *factory,
TAO_AV_Core::Flow_Component flow_comp)
{
this->flow_protocol_factory_ = factory;
this->av_core_ = av_core;
this->endpoint_ = endpoint;
this->entry_ = entry;
if (flow_comp == TAO_AV_Core::TAO_AV_CONTROL)
this->flowname_ = TAO_AV_Core::get_control_flowname (entry->flowname());
else
this->flowname_ = entry->flowname ();
ACE_INET_Addr *address;
ACE_NEW_RETURN (address,
ACE_INET_Addr ("0"),
-1);
int result = this->acceptor_.acceptor_open (this,
av_core->reactor (),
*address,
entry);
if (result < 0)
ORBSVCS_ERROR_RETURN ((LM_ERROR,
"TAO_AV_SCTP_SEQ_Acceptor::open failed"),
-1);
this->acceptor_.acceptor ().get_local_addr (*address);
address->set (address->get_port_number (),
address->get_host_name ());
char buf[BUFSIZ];
address->addr_to_string (buf,BUFSIZ);
if (TAO_debug_level > 0)
ORBSVCS_DEBUG ((LM_DEBUG,
"TAO_AV_SCTP_SEQ_Acceptor::open_default: %s\n",
buf));
entry->set_local_addr (address);
return 0;
}