当前位置: 首页>>代码示例>>C++>>正文


C++ PSockEvent类代码示例

本文整理汇总了C++中PSockEvent的典型用法代码示例。如果您正苦于以下问题:C++ PSockEvent类的具体用法?C++ PSockEvent怎么用?C++ PSockEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PSockEvent类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
	}
}
开发者ID:adobekan,项目名称:qminer,代码行数:27,代码来源:sock.cpp

示例2: IAssert

void TSockSys::OnTimeOut(uv_timer_t* TimerHnd, int Status) {
	// check we have timer
	IAssert(SockSys.IsTimer((uint64)TimerHnd));
	// get socket id
	const uint64 SockId = SockSys.TimerHndToSockIdH.GetDat((uint64)TimerHnd);
	IAssert(SockSys.IsSock(SockId));
	// get socket event
	const uint64 SockHnd = (uint64)SockSys.SockIdToHndH.GetDat(SockId);
	const uint64 SockEventId = SockSys.SockHndToEventIdH.GetDat((uint64)SockHnd);
	PSockEvent SockEvent;
	if (SockSys.IsSockEvent(SockEventId)) {
		SockEvent = SockSys.GetSockEvent(SockEventId);
		// execute callback
		if (Status == 0) {
			SockEvent->OnTimeOut(SockId);
		} else {
			TStr ErrMsg = (Status == -1) ? 
				"SockSys.OnTimeOut: " + SockSys.GetLastErr() : 
				"SockSys.OnTimeOut: Error in socket timeout";
			SockEvent->OnError(SockId, Status, ErrMsg);
		}
	} else {
		SaveToErrLog("SockSys.OnTimeOut: Socket without SockEvent");
	}
	// cleanup
	uv_close((uv_handle_t*)TimerHnd, NULL);
	// remove shortcuts
	SockSys.SockIdToTimerHndH.DelKey(SockId);
	SockSys.TimerHndToSockIdH.DelKey((uint64)TimerHnd);
}
开发者ID:davidd2k,项目名称:qminer,代码行数:30,代码来源:socksys.cpp

示例3: free

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);
}
开发者ID:davidd2k,项目名称:qminer,代码行数:56,代码来源:socksys.cpp

示例4: SockEventId

TSock::TSock(const PSockEvent& SockEvent): 
		SockId(++LastSockId), SockEventId(SockEvent->GetSockEventId()) {

	// make sure callbacks are registered
	IAssert(TSockEvent::IsReg(SockEvent));
	// initialize socket
	SockSys.NewSock(SockId, SockEventId);
}
开发者ID:adobekan,项目名称:qminer,代码行数:8,代码来源:sock.cpp

示例5: OnClose

void TSockSys::OnClose(uv_handle_t* SockHnd) {
	// check if we know about the socket
	if (SockSys.IsSockHnd((uint64)SockHnd)) {
		// get socket id
		const uint64 SockId = SockSys.SockHndToIdH.GetDat((uint64)SockHnd);
		// execute callback
		const uint64 SockEventId = SockSys.SockHndToEventIdH.GetDat((uint64)SockHnd);
		if (SockSys.IsSockEvent(SockEventId)) {
			PSockEvent SockEvent = SockSys.GetSockEvent(SockEventId);
			SockEvent->OnClose(SockId);
		}
		// delete socket shortcuts
		SockSys.DelIfSockTimer(SockId);
		SockSys.SockIdToHndH.DelKey(SockId);
		SockSys.SockHndToIdH.DelKey((uint64)SockHnd);
		SockSys.SockHndToEventIdH.DelKey((uint64)SockHnd);
		// marke note that it's already closed
		SockSys.ClosedSockIdSet.DelIfKey(SockId);
	}
}
开发者ID:davidd2k,项目名称:qminer,代码行数:20,代码来源:socksys.cpp

示例6: DelSockEvent

void TSockSys::DelSockEvent(const PSockEvent& SockEvent) {
	if (Active) {
		IdToSockEventH.DelIfKey(SockEvent->GetSockEventId());
	}
}
开发者ID:davidd2k,项目名称:qminer,代码行数:5,代码来源:socksys.cpp

示例7: AddSockEvent

void TSockSys::AddSockEvent(const PSockEvent& SockEvent) {
	// make sure we don't add empty stuff
	EAssert(!SockEvent.Empty());
	IdToSockEventH.AddDat(SockEvent->GetSockEventId(), SockEvent);
}
开发者ID:davidd2k,项目名称:qminer,代码行数:5,代码来源:socksys.cpp

示例8: IsSockEvent

bool TSockSys::IsSockEvent(const PSockEvent& SockEvent) const { 
	return Active ? IdToSockEventH.IsKey(SockEvent->GetSockEventId()) : false;
}
开发者ID:davidd2k,项目名称:qminer,代码行数:3,代码来源:socksys.cpp


注:本文中的PSockEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。