本文整理汇总了C++中BaseProtocol::GetFarEndpoint方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseProtocol::GetFarEndpoint方法的具体用法?C++ BaseProtocol::GetFarEndpoint怎么用?C++ BaseProtocol::GetFarEndpoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseProtocol
的用法示例。
在下文中一共展示了BaseProtocol::GetFarEndpoint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Accept
bool UnixDomainSocketAcceptor::Accept() {
struct sockaddr_un remoteAddress;
memset(&remoteAddress, 0, sizeof (struct sockaddr_un));
socklen_t len = sizeof (struct sockaddr_un);
int32_t fd;
int32_t error;
//1. Accept the connection
fd = accept(_inboundFd, (sockaddr *)&remoteAddress, &len);
error = LASTSOCKETERROR;
if (fd < 0) {
FATAL("Unable to accept UX client connection: %s (%d)", strerror(error), error);
return false;
}
if (!_enabled) {
CLOSE_SOCKET(fd);
_droppedCount++;
WARN("Acceptor is not enabled. UX Client dropped: %s", STR(_sockPath));
return true;
}
INFO("Client connected: %s", STR(_sockPath));
//if (!setFdOptions(fd, false)) {
// FATAL("Unable to set unix socket options");
// CLOSE_SOCKET(fd);
// return false;
//}
//2. Create the chain
BaseProtocol *pProtocol = ProtocolFactoryManager::CreateProtocolChain(
_protocolChain, _parameters);
if (pProtocol == NULL) {
FATAL("Unable to create protocol chain");
CLOSE_SOCKET(fd);
return false;
}
//3. Create the carrier and bind it
UnixDomainSocketCarrier *pUnixDomainSocketCarrier = new UnixDomainSocketCarrier(fd, _sockPath);
pUnixDomainSocketCarrier->SetProtocol(pProtocol->GetFarEndpoint());
pProtocol->GetFarEndpoint()->SetIOHandler(pUnixDomainSocketCarrier);
//4. Register protocol for thread access
UnixDomainSocketManager::RegisterUXThreadProtocol(pUnixDomainSocketCarrier->GetSocketName(),
(UnixDomainSocketProtocol *)pUnixDomainSocketCarrier->GetProtocol());
//5. Register the protocol stack with an application
if (_pApplication != NULL) {
pProtocol = pProtocol->GetNearEndpoint();
pProtocol->SetApplication(_pApplication);
}
if (pProtocol->GetNearEndpoint()->GetOutputBuffer() != NULL)
pProtocol->GetNearEndpoint()->EnqueueForOutbound();
_acceptedCount++;
return true;
}
示例2: EnvRun
//.........这里部分代码省略.........
if (chain.size() == 0) {
ASSERT("Invalid protocol chain: %s", STR(acceptorConfig[CONF_PROTOCOL]));
}
TCPAcceptor *pAcceptor = new TCPAcceptor(acceptorConfig[CONF_IP],
(uint16_t) acceptorConfig[CONF_PORT], acceptorConfig, chain);
if (!pAcceptor->StartAccept(pApp)) {
ASSERT("Unable to fire up acceptor");
}
//8. Create the bin variant acceptor
acceptorConfig[CONF_PORT] = (uint16_t) (port + 1);
acceptorConfig[CONF_PROTOCOL] = CONF_PROTOCOL_INBOUND_BIN_VARIANT;
chain = ProtocolFactoryManager::ResolveProtocolChain(acceptorConfig[CONF_PROTOCOL]);
if (chain.size() == 0) {
ASSERT("Invalid protocol chain: %s", STR(acceptorConfig[CONF_PROTOCOL]));
}
pAcceptor = new TCPAcceptor(acceptorConfig[CONF_IP], (uint16_t) acceptorConfig[CONF_PORT],
acceptorConfig, chain);
if (!pAcceptor->StartAccept(pApp)) {
ASSERT("Unable to fire up acceptor");
}
//9. Create the xml variant acceptor
acceptorConfig[CONF_PORT] = (uint16_t) (port + 2);
acceptorConfig[CONF_PROTOCOL] = CONF_PROTOCOL_INBOUND_XML_VARIANT;
chain = ProtocolFactoryManager::ResolveProtocolChain(acceptorConfig[CONF_PROTOCOL]);
if (chain.size() == 0) {
ASSERT("Invalid protocol chain: %s", STR(acceptorConfig[CONF_PROTOCOL]));
}
pAcceptor = new TCPAcceptor(acceptorConfig[CONF_IP], (uint16_t) acceptorConfig[CONF_PORT],
acceptorConfig, chain);
if (!pAcceptor->StartAccept(pApp)) {
ASSERT("Unable to fire up acceptor");
}
#ifdef HAS_PROTOCOL_RTMP
//9. Create the RTMP acceptor
acceptorConfig[CONF_PORT] = (uint16_t) (1935);
acceptorConfig[CONF_PROTOCOL] = CONF_PROTOCOL_INBOUND_RTMP;
chain = ProtocolFactoryManager::ResolveProtocolChain(acceptorConfig[CONF_PROTOCOL]);
if (chain.size() == 0) {
ASSERT("Invalid protocol chain: %s", STR(acceptorConfig[CONF_PROTOCOL]));
}
pAcceptor = new TCPAcceptor(acceptorConfig[CONF_IP], (uint16_t) acceptorConfig[CONF_PORT],
acceptorConfig, chain);
if (!pAcceptor->StartAccept(pApp)) {
ASSERT("Unable to fire up acceptor");
}
#endif /* HAS_PROTOCOL_RTMP */
//10. Create the timer UDP protocol
#ifdef HAS_MS_TIMER
acceptorConfig[CONF_PORT] = (uint16_t) (port + 3);
acceptorConfig[CONF_PROTOCOL] = "fineTimer";
acceptorConfig["FineTimerPeriod"] = 0.2;
chain = ProtocolFactoryManager::ResolveProtocolChain(acceptorConfig[CONF_PROTOCOL]);
if (chain.size() == 0) {
ASSERT("Invalid protocol chain: %s", STR(acceptorConfig[CONF_PROTOCOL]));
}
UDPCarrier *pUDPCarrier = UDPCarrier::Create(acceptorConfig[CONF_IP], (uint16_t) acceptorConfig[CONF_PORT]);
if (pUDPCarrier == NULL) {
ASSERT("Unable to bind on udp://%s:%hu", STR(acceptorConfig[CONF_IP]), (uint16_t) acceptorConfig[CONF_PORT]);
}
BaseProtocol *pTimer = ProtocolFactoryManager::CreateProtocolChain(chain, acceptorConfig);
pTimer->GetFarEndpoint()->SetIOHandler(pUDPCarrier);
pUDPCarrier->SetProtocol(pTimer->GetFarEndpoint());
pApp->SetFineTimerId(pTimer->GetId());
#endif /* HAS_MS_TIMER */
inet_aton("127.0.0.1", &gAddress.sin_addr);
memset(&gAddress, 0, sizeof (gAddress));
gAddress.sin_family = AF_INET;
gAddress.sin_port = EHTONS(port + 1);
//10. Run
while (IOHandlerManager::Pulse()) {
IOHandlerManager::DeleteDeadHandlers();
ProtocolManager::CleanupDeadProtocols();
}
//11. Shutting down protocols manager;
ProtocolManager::Shutdown();
ProtocolManager::CleanupDeadProtocols();
//12. Shutting down I/O handlers manager
IOHandlerManager::ShutdownIOHandlers();
IOHandlerManager::DeleteDeadHandlers();
IOHandlerManager::Shutdown();
//13. Unregister and delete default protocol handler
ProtocolFactoryManager::UnRegisterProtocolFactory(pFactory);
delete pFactory;
pFactory = NULL;
//14. Shutting down applications
ClientApplicationManager::Shutdown();
//15. Shutting down the logger leaving you in the dark. Bye bye
Logger::Free(true);
}