本文整理汇总了C++中ACE_INET_Addr::get_host_addr方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_INET_Addr::get_host_addr方法的具体用法?C++ ACE_INET_Addr::get_host_addr怎么用?C++ ACE_INET_Addr::get_host_addr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_INET_Addr
的用法示例。
在下文中一共展示了ACE_INET_Addr::get_host_addr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: handleConnection
int MyAcceptor::handleConnection()
{
int newConnSock = acceptConnection();
if (newConnSock <= 0)
{
PAS_ERROR2( "MyAcceptor:: accept ERROR %s. new sock fd = %d", ACE_OS::strerror(ACE_OS::last_error()), newConnSock);
usleep(100000);
return -1;
}
/// 단말기의 IP 주소를 구하기.
ACE_SOCK_STREAM sock(newConnSock);
ACE_INET_Addr peer;
sock.get_remote_addr( peer );
PAS_INFO4( "Accept %s:%d sock=%d conn[%d] ", peer.get_host_addr(), peer.get_port_number(), newConnSock, numAccepts);
numAccepts++;
if (numAccepts > 10000 * 10000 * 10)
numAccepts = 0;
// L4 Health check ignore
Config *conf = Config::instance();
if( !strcmp(peer.get_host_addr(), conf->network.L4Addr1.toStr()) ||
!strcmp(peer.get_host_addr(), conf->network.L4Addr2.toStr()) )
{
#if 0
// set SO_LINGER - 2 sec. WIGCS 로부터 받은 팁. 2007.1.12
linger lingtime;
lingtime.l_onoff = 1;
lingtime.l_linger = 2;
sock.set_option( SOL_SOCKET, SO_LINGER, (void*)&lingtime, sizeof(linger) );
#endif
sock.close_writer();
sock.close();
PAS_INFO3( "Close L4 %s:%d sock=%d", peer.get_host_addr(), peer.get_port_number(), newConnSock);
return 0;
}
ReactorInfo* rInfo = ReactorPool::instance()->workerReactor();
ClientHandler* pClientEH = new ClientHandler(rInfo);
pClientEH->init(newConnSock);
// reactor에 새로운 client 등록
// pClientEH 는 소켓이 종료될때 스스로 자신을 메모리에서 삭제한다.
rInfo->pReactor->register_handler(pClientEH, READ_MASK);
return 0;
}
示例3: _checkInMcast
int YARPNameClient::_checkInMcast(const YARPString &s, ACE_INET_Addr &addr)
{
YNC("YNC %s:%d --> _checkIn %s\n",__FILE__,__LINE__,s.c_str());
YARPNameServiceCmd tmpCmd;
YARPNameTCP tmpRqst;
if (connect_to_server()!=0)
return YARP_FAIL;
tmpRqst.setName(s);
tmpRqst.setIp(addr.get_host_addr());
tmpCmd.cmd = YARPNSRegister;
tmpCmd.type = YARP_MCAST;
tmpCmd.length = tmpRqst.length();
// send message length
ACE_OS::memcpy(data_buf_,&tmpCmd, sizeof(YARPNameServiceCmd));
ACE_OS::memcpy(data_buf_+sizeof(YARPNameServiceCmd), &tmpRqst, tmpRqst.length());
iovec iov[1];
iov[0].iov_base = data_buf_;
iov[0].iov_len = sizeof(YARPNameServiceCmd)+tmpRqst.length();
int sent = client_stream_.sendv_n (iov, 1);
if (sent == -1)
ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n","send_n"),0);
//////////////////////////////////////////
unsigned int byte_count = 0;
int res = 0;
ACE_OS::memset(data_buf_, 0, SIZE_BUF);
iov[0].iov_len = sizeof(YARPNameServiceCmd);
res = client_stream_.recvv_n(iov, 1, 0, &byte_count);
iov[0].iov_len = tmpCmd.length;
res = client_stream_.recvv_n(iov, 1, 0, &byte_count);
YARPNameTCP *tmpRpl = (YARPNameTCP *)data_buf_;
tmpRpl->getAddr(addr);
NAME_CLIENT_DEBUG(("Received %s(%s):%d\n", addr.get_host_addr(), servicetypeConverter(tmpCmd.type), addr.get_port_number()));
// close the connection
close();
return YARP_OK;
}
示例4: assert
bool P2pEndpoint::readMessage(ACE_INET_Addr& peerAddr,
ACE_Message_Block& mblock)
{
assert(mblock.size() >= P2pConfig::defaultMtu);
const ssize_t recvSize =
udp_->recv(mblock.wr_ptr(), mblock.space(), peerAddr);
if (recvSize == 0) {
return false;
}
if (recvSize < 0) {
const int error = ACE_OS::last_error();
if (error == EWOULDBLOCK) {
return false;
}
//if (error == ECONNRESET) {
// return false;
//}
NSRPC_LOG_ERROR4(
ACE_TEXT("P2pEndpoint::readMessage(from: %s:%d) FAILED!!!(%d,%m)"),
peerAddr.get_host_addr(), peerAddr.get_port_number(),
ACE_OS::last_error());
return false;
}
mblock.wr_ptr(recvSize);
return true;
}
示例5: open
int RealmSocket::open(void * arg)
{
ACE_INET_Addr addr;
if (peer().get_remote_addr(addr) == -1)
{
sLog->outError(LOG_FILTER_AUTHSERVER, "Error %s while opening realm socket!", ACE_OS::strerror(errno));
return -1;
}
_remoteAddress = addr.get_host_addr();
_remotePort = addr.get_port_number();
// Register with ACE Reactor
if (Base::open(arg) == -1)
return -1;
if (session_)
session_->OnAccept();
// reactor takes care of the socket from now on
remove_reference();
return 0;
}
示例6: sizeof
int
TAO_SCIOP_Endpoint::set (const ACE_INET_Addr &addr,
int use_dotted_decimal_addresses)
{
char tmp_host[MAXHOSTNAMELEN + 1];
if (use_dotted_decimal_addresses
|| addr.get_host_name (tmp_host, sizeof (tmp_host)) != 0)
{
const char *tmp = addr.get_host_addr ();
if (tmp == 0)
{
if (TAO_debug_level > 0)
TAOLIB_DEBUG ((LM_DEBUG,
ACE_TEXT ("\n\nTAO (%P|%t) ")
ACE_TEXT ("SCIOP_Endpoint::set ")
ACE_TEXT ("- %p\n\n"),
ACE_TEXT ("cannot determine hostname")));
return -1;
}
else
this->host_ = tmp;
}
else
this->host_ = CORBA::string_dup (tmp_host);
this->port_ = addr.get_port_number();
return 0;
}
示例7: send_dgram
int send_dgram (ACE_SOCK_Dgram &socket, ACE_INET_Addr addr, int done = 0)
{
// Send each message twice, once to the right port, and once to the "wrong"
// port. This helps generate noise and lets us see if port filtering is
// working properly.
const char *address = addr.get_host_addr ();
int port = addr.get_port_number ();
for (int i = 0; i < 2; ++i)
{
char buf[MAX_STRING_SIZE];
if (done)
buf[0] = 0;
else
ACE_OS::sprintf (buf, "%s/%d", address, port);
if (socket.send (buf, ACE_OS::strlen (buf),addr) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Send to %C, %p\n"),
address,
ACE_TEXT ("send_dgram - error calling send on ")
ACE_TEXT ("ACE_SOCK_Dgram.")), -1);
addr.set_port_number (++port);
}
return 0;
}
示例8: guard
/*virtual*/ int RealmSocket::open(void * arg)
{
if(Base::open(arg) == -1)
return -1;
ACE_INET_Addr addr;
if(peer().get_remote_addr(addr) == -1)
return -1;
char address[1024];
addr.get_host_addr(address, 1024);
this->remote_address_ = address;
if(this->session_ != NULL)
{
// Prepare for upcall
this->add_reference();
ACE_Event_Handler_var guard(this);
this->session_->OnAccept();
}
this->remove_reference();
return 0;
}
示例9: _query
int YARPNameClient::_query(const YARPString &s, ACE_INET_Addr &addr, int *type)
{
YNC("YNC %s:%d --> _query %s\n",__FILE__,__LINE__,s.c_str());
YARPNameServiceCmd tmpCmd;
YARPNameTCP tmpRqst;
if (alt_client.isActive()) {
return alt_client.queryName(s.c_str(),addr,type);
}
if (connect_to_server()!=0)
return YARP_FAIL;
tmpRqst.setName(s);
tmpCmd.cmd = YARPNSQuery;
tmpCmd.type = YARP_TCP; // TCP, UDP, MCAST queries are handled in the same way
tmpCmd.length = tmpRqst.length();
// send message length
ACE_OS::memcpy(data_buf_,&tmpCmd, sizeof(YARPNameServiceCmd));
ACE_OS::memcpy(data_buf_+sizeof(YARPNameServiceCmd), &tmpRqst, tmpRqst.length());
iovec iov[1];
iov[0].iov_base = data_buf_;
iov[0].iov_len = sizeof(YARPNameServiceCmd)+tmpRqst.length();
int sent = client_stream_.sendv_n (iov, 1);
if (sent == -1)
ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n","send_n"),0);
//////////////////////////////////////////
unsigned int byte_count = 0;
int res = 0;
ACE_OS::memset(data_buf_, 0, SIZE_BUF);
iov[0].iov_len = sizeof(YARPNameServiceCmd);
res = client_stream_.recvv_n(iov, 1, 0, &byte_count);
YARPNameServiceCmd *srvCmd = (YARPNameServiceCmd *)data_buf_;
*type = srvCmd->type; // get address type
iov[0].iov_len = srvCmd->length;
res = client_stream_.recvv_n(iov, 1, 0, &byte_count);
YARPNameTCP *srvRpl = (YARPNameTCP *)data_buf_;
srvRpl->getAddr(addr);
NAME_CLIENT_DEBUG(("underlying ip %s port %d\n",
srvRpl->_ip, srvRpl->_port));
NAME_CLIENT_DEBUG(("Received %s(%s):%d\n", addr.get_host_addr(), servicetypeConverter(*type), addr.get_port_number()));
// close the connection
close();
return YARP_OK;
}
示例10: open
int open (void)
{
ACE_INET_Addr ClientaddrRemote;
this->peer().get_remote_addr(ClientaddrRemote);
ACE_OS::printf("[CConnectHandler::open] Connection from [%s:%d]\n", ClientaddrRemote.get_host_addr(), ClientaddrRemote.get_port_number());
//注册读就绪回调函数
return this->reactor ()->register_handler(this, ACE_Event_Handler::READ_MASK);
}
示例11:
void
TAO_UIPMC_Endpoint::object_addr (const ACE_INET_Addr &addr)
{
this->port_ = addr.get_port_number();
char tmp[INET6_ADDRSTRLEN];
addr.get_host_addr (tmp, sizeof tmp);
this->host_ = CORBA::string_dup (tmp);
this->object_addr_.set (addr);
this->uint_ip_addr (addr.get_ip_address ());
}
示例12: 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;
}
示例13:
/*virtual*/ int BufferedSocket::open(void* arg)
{
if (Base::open(arg) == -1)
return -1;
ACE_INET_Addr addr;
if (peer().get_remote_addr(addr) == -1)
return -1;
char address[1024];
addr.get_host_addr(address, 1024);
_remoteAddress = addr.get_host_addr();
this->OnAccept();
return 0;
}
示例14: Make_Common_Dispose_Client_WorkTread_Message
int Make_Common_Dispose_Client_WorkTread_Message(uint16 u2CommandID, uint32 u4ServerID, ACE_Message_Block* pmblk, ACE_INET_Addr& AddrRemote)
{
//组织数据
CMessage* pMessage = App_MessageServiceGroup::instance()->CreateMessage(u4ServerID, CONNECT_IO_TCP);
if (NULL == pMessage)
{
//放入消息框架失败
OUR_DEBUG((LM_ERROR, "[CConnectClient::SendMessageGroup] ConnectID = %d CreateMessage fail.\n", u4ServerID));
App_MessageBlockManager::instance()->Close(pmblk);
return -1;
}
else
{
ACE_Message_Block* pMBBHead = App_MessageBlockManager::instance()->Create(sizeof(uint32));
if (NULL == pMBBHead)
{
OUR_DEBUG((LM_ERROR, "[CConnectClient::SendMessageGroup] ConnectID = %d pMBBHead fail.\n", u4ServerID));
App_MessageBlockManager::instance()->Close(pmblk);
return -1;
}
//添加消息包头
uint32 u4PacketLen = (uint32)pmblk->length();
memcpy_safe((char*)&u4PacketLen, sizeof(uint32), pMBBHead->wr_ptr(), sizeof(uint32));
pMBBHead->wr_ptr(sizeof(uint32));
sprintf_safe(pMessage->GetMessageBase()->m_szListenIP, MAX_BUFF_20, "%s", AddrRemote.get_host_addr());
sprintf_safe(pMessage->GetMessageBase()->m_szIP, MAX_BUFF_20, "127.0.0.1");
pMessage->GetMessageBase()->m_u2Cmd = u2CommandID;
pMessage->GetMessageBase()->m_u4ConnectID = u4ServerID;
pMessage->GetMessageBase()->m_u4ListenPort = (uint32)AddrRemote.get_port_number();
pMessage->GetMessageBase()->m_tvRecvTime = ACE_OS::gettimeofday();
pMessage->GetMessageBase()->m_u1ResouceType = RESOUCE_FROM_SERVER;
pMessage->GetMessageBase()->m_u4HeadSrcSize = sizeof(uint32);
pMessage->GetMessageBase()->m_u4BodySrcSize = u4PacketLen;
pMessage->SetPacketHead(pMBBHead);
pMessage->SetPacketBody(pmblk);
//将要处理的消息放入消息处理线程
if (false == App_MessageServiceGroup::instance()->PutMessage(pMessage))
{
OUR_DEBUG((LM_ERROR, "[CConnectClient::SendMessageGroup] App_MessageServiceGroup::instance()->PutMessage Error.\n"));
App_MessageServiceGroup::instance()->DeleteMessage(u4ServerID, pMessage);
return -1;
}
}
return 0;
}
示例15: open
int RASocket::open(void *)
{
ACE_INET_Addr remoteAddress;
if (peer().get_remote_addr(remoteAddress) == -1)
{
sLog->outError("RASocket::open: peer().get_remote_addr error is %s", ACE_OS::strerror(errno));
return -1;
}
sLog->outRemote("Incoming connection from %s", remoteAddress.get_host_addr());
return activate();
}