本文整理汇总了C++中PSockEvent::OnGetHost方法的典型用法代码示例。如果您正苦于以下问题:C++ PSockEvent::OnGetHost方法的具体用法?C++ PSockEvent::OnGetHost怎么用?C++ PSockEvent::OnGetHost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PSockEvent
的用法示例。
在下文中一共展示了PSockEvent::OnGetHost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetAsyncSockHost
void TSockHost::GetAsyncSockHost(const TStr& HostNm, const PSockEvent& SockEvent) {
PSockHost SockHost = TSockHost::New(SockEvent);
// check if there is need for DNS resovling or not
if (HostNm == TSock::LocalhostNm) {
// no need, just return loopback IP
SockHost->Status = shsOk;
SockHost->IpNumV.Add(TIpNum(TSock::LoopbackIpNum, shivIpv4));
// we do the callback from here already
SockEvent->OnGetHost(SockHost);
} else if (TUInt::IsIpStr(HostNm)) {
// no need, just need to parse out IPv4
SockHost->Status = shsOk;
SockHost->IpNumV.Add(TIpNum(HostNm, shivIpv4));
// we do the callback from here already
SockEvent->OnGetHost(SockHost);
} else if (TUInt::IsIpv6Str(HostNm)) {
// no need, just need to parse out IPv4
SockHost->Status = shsOk;
SockHost->IpNumV.Add(TIpNum(HostNm, shivIpv6));
// we do the callback from here already
SockEvent->OnGetHost(SockHost);
} else {
SockHost->HostNm = HostNm;
// we need to resolve hostname to IP
SockSys.GetAsyncSockHost(HostNm, SockHost);
}
}
示例2: OnGetHost
void TSockSys::OnGetHost(uv_getaddrinfo_t* RequestHnd, int Status, struct addrinfo* AddrInfo) {
// get SockHost
PSockHost SockHost;
if (SockSys.HndToSockHostH.IsKey((uint64)RequestHnd)) {
SockHost = SockSys.HndToSockHostH.GetDat((uint64)RequestHnd);
SockSys.HndToSockHostH.DelKey((uint64)RequestHnd);
} else {
free(RequestHnd); uv_freeaddrinfo(AddrInfo);
SaveToErrLog("SockSys.OnGetHost: unkown RequestId");
return;
}
// get SockEvent
PSockEvent SockEvent;
if (SockHost->IsSockEvent()) {
SockEvent = SockHost->GetSockEvent();
} else {
free(RequestHnd); uv_freeaddrinfo(AddrInfo);
SaveToErrLog("SockSys.OnGetHost: SockHost without SockEvent");
return;
}
// parse results
if (Status == 0) {
SockHost->Status = shsOk;
// temporary buffer for storing IPs
char _addr[64] = {'\0'};
// iterate over all the resolved IPs
struct addrinfo* AddrInfoIter = AddrInfo;
while (AddrInfoIter != NULL) {
//if (AddrInfoIter->ai_family
//AF_INET6
// get IP as string
if (AddrInfoIter->ai_family == AF_INET) {
uv_ip4_name((struct sockaddr_in*)AddrInfoIter->ai_addr, _addr, sizeof(_addr));
} else if (AddrInfoIter->ai_family == AF_INET6) {
uv_ip6_name((struct sockaddr_in6*)AddrInfoIter->ai_addr, _addr, sizeof(_addr));
}
TStr IpNum(_addr);
// add to SockHost
SockHost->AddIpNum(IpNum);
// go to the next IP on the list
AddrInfoIter = AddrInfoIter->ai_next;
}
} else if (Status == -1) {
// something went wrong
SockHost->Status = shsError;
SockHost->ErrMsg = "SockSys.OnGetHost: " + SockSys.GetLastErr();
} else {
// unkown status
SockHost->Status = shsError;
SockHost->ErrMsg = TStr::Fmt("SockSys.OnGetHost: unkown status %d", Status);
}
// clean up
free(RequestHnd); uv_freeaddrinfo(AddrInfo);
// callback
SockEvent->OnGetHost(SockHost);
}