本文整理汇总了C++中network::EndPoint::setnonblocking方法的典型用法代码示例。如果您正苦于以下问题:C++ EndPoint::setnonblocking方法的具体用法?C++ EndPoint::setnonblocking怎么用?C++ EndPoint::setnonblocking使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network::EndPoint
的用法示例。
在下文中一共展示了EndPoint::setnonblocking方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initCreate
//-------------------------------------------------------------------------------------
bool ClientObject::initCreate()
{
Network::EndPoint* pEndpoint = new Network::EndPoint();
pEndpoint->socket(SOCK_STREAM);
if (!pEndpoint->good())
{
ERROR_MSG("ClientObject::initNetwork: couldn't create a socket\n");
delete pEndpoint;
error_ = C_ERROR_INIT_NETWORK_FAILED;
return false;
}
ENGINE_COMPONENT_INFO& infos = g_kbeSrvConfig.getBots();
u_int32_t address;
pEndpoint->convertAddress(infos.login_ip, address);
if(pEndpoint->connect(htons(infos.login_port), address) == -1)
{
ERROR_MSG(fmt::format("ClientObject::initNetwork({1}): connect server({2}:{3}) is error({0})!\n",
kbe_strerror(), name_, infos.login_ip, infos.login_port));
delete pEndpoint;
// error_ = C_ERROR_INIT_NETWORK_FAILED;
state_ = C_STATE_INIT;
return false;
}
Network::Address addr(infos.login_ip, infos.login_port);
pEndpoint->addr(addr);
pServerChannel_->endpoint(pEndpoint);
pEndpoint->setnonblocking(true);
pEndpoint->setnodelay(true);
pServerChannel_->pMsgHandlers(&ClientInterface::messageHandlers);
Bots::getSingleton().pEventPoller()->registerForRead((*pEndpoint), this);
Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject();
(*pBundle).newMessage(LoginappInterface::hello);
(*pBundle) << KBEVersion::versionString() << KBEVersion::scriptVersionString();
if(Network::g_channelExternalEncryptType == 1)
{
pBlowfishFilter_ = new Network::BlowfishFilter();
(*pBundle).appendBlob(pBlowfishFilter_->key());
}
else
{
std::string key = "";
(*pBundle).appendBlob(key);
}
pServerChannel_->pushBundle(pBundle);
this->pEndpoint_ = pEndpoint;
return true;
}
示例2: initLoginGateWay
//-------------------------------------------------------------------------------------
bool ClientObject::initLoginGateWay()
{
Bots::getSingleton().pEventPoller()->deregisterForRead(*pServerChannel_->endpoint());
Network::EndPoint* pEndpoint = new Network::EndPoint();
pEndpoint->socket(SOCK_STREAM);
if (!pEndpoint->good())
{
ERROR_MSG("ClientObject::initLogin: couldn't create a socket\n");
delete pEndpoint;
error_ = C_ERROR_INIT_NETWORK_FAILED;
return false;
}
u_int32_t address;
pEndpoint->convertAddress(ip_.c_str(), address);
if(pEndpoint->connect(htons(port_), address) == -1)
{
ERROR_MSG(fmt::format("ClientObject::initLogin({}): connect server is error({})!\n",
kbe_strerror(), name_));
delete pEndpoint;
// error_ = C_ERROR_INIT_NETWORK_FAILED;
state_ = C_STATE_LOGIN_GATEWAY_CREATE;
return false;
}
Network::Address addr(ip_.c_str(), port_);
pEndpoint->addr(addr);
pServerChannel_->endpoint(pEndpoint);
pEndpoint->setnonblocking(true);
pEndpoint->setnodelay(true);
Bots::getSingleton().pEventPoller()->registerForRead((*pEndpoint), this);
connectedGateway_ = true;
Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject();
(*pBundle).newMessage(BaseappInterface::hello);
(*pBundle) << KBEVersion::versionString() << KBEVersion::scriptVersionString();
if(Network::g_channelExternalEncryptType == 1)
{
pBlowfishFilter_ = new Network::BlowfishFilter();
(*pBundle).appendBlob(pBlowfishFilter_->key());
pServerChannel_->pFilter(NULL);
}
else
{
std::string key = "";
(*pBundle).appendBlob(key);
}
pServerChannel_->pushBundle(pBundle);
return true;
}
示例3: updateComponentInfos
//-------------------------------------------------------------------------------------
bool Components::updateComponentInfos(const Components::ComponentInfos* info)
{
// 不对其他machine做处理
if(info->componentType == MACHINE_TYPE)
{
return true;
}
if (!lookupLocalComponentRunning(info->pid))
return false;
Network::EndPoint epListen;
epListen.socket(SOCK_STREAM);
if (!epListen.good())
{
ERROR_MSG("Components::updateComponentInfos: couldn't create a socket\n");
return true;
}
epListen.setnonblocking(true);
while(true)
{
fd_set frds, fwds;
struct timeval tv = { 0, 300000 }; // 100ms
FD_ZERO( &frds );
FD_ZERO( &fwds );
FD_SET((int)epListen, &frds);
FD_SET((int)epListen, &fwds);
if(epListen.connect(info->pIntAddr->port, info->pIntAddr->ip) == -1)
{
int selgot = select(epListen+1, &frds, &fwds, NULL, &tv);
if(selgot > 0)
{
break;
}
WARNING_MSG(fmt::format("Components::updateComponentInfos: couldn't connect to:{}\n",
info->pIntAddr->c_str()));
return false;
}
}
epListen.setnodelay(true);
Network::Bundle* pBundle = Network::Bundle::createPoolObject();
// 由于COMMON_NETWORK_MESSAGE不包含client, 如果是bots, 我们需要单独处理
if(info->componentType != BOTS_TYPE)
{
COMMON_NETWORK_MESSAGE(info->componentType, (*pBundle), lookApp);
}
else
{
(*pBundle).newMessage(BotsInterface::lookApp);
}
epListen.send(pBundle->pCurrPacket()->data(), pBundle->pCurrPacket()->wpos());
Network::Bundle::reclaimPoolObject(pBundle);
fd_set fds;
struct timeval tv = { 0, 300000 }; // 100ms
FD_ZERO( &fds );
FD_SET((int)epListen, &fds);
int selgot = select(epListen+1, &fds, NULL, NULL, &tv);
if(selgot == 0)
{
// 超时, 可能对方繁忙
return true;
}
else if(selgot == -1)
{
return true;
}
else
{
COMPONENT_TYPE ctype;
COMPONENT_ID cid;
int8 istate = 0;
ArraySize entitySize = 0, cellSize = 0;
int32 clientsSize = 0, proxicesSize = 0;
uint32 telnet_port = 0;
Network::TCPPacket packet;
packet.resize(255);
int recvsize = sizeof(ctype) + sizeof(cid) + sizeof(istate);
if(info->componentType == CELLAPP_TYPE)
{
recvsize += sizeof(entitySize) + sizeof(cellSize) + sizeof(telnet_port);
}
if(info->componentType == BASEAPP_TYPE)
{
//.........这里部分代码省略.........
示例4: initLoginGateWay
//-------------------------------------------------------------------------------------
bool ClientObject::initLoginGateWay()
{
Bots::getSingleton().networkInterface().dispatcher().deregisterReadFileDescriptor(*pTCPPacketReceiverEx_->pEndPoint());
pServerChannel_->stopSend();
pServerChannel_->pPacketSender(NULL);
SAFE_RELEASE(pTCPPacketSenderEx_);
SAFE_RELEASE(pTCPPacketReceiverEx_);
Network::EndPoint* pEndpoint = Network::EndPoint::ObjPool().createObject();
pEndpoint->socket(SOCK_STREAM);
if (!pEndpoint->good())
{
ERROR_MSG("ClientObject::initLogin: couldn't create a socket\n");
Network::EndPoint::ObjPool().reclaimObject(pEndpoint);
error_ = C_ERROR_INIT_NETWORK_FAILED;
return false;
}
u_int32_t address;
Network::Address::string2ip(ip_.c_str(), address);
if(pEndpoint->connect(htons(port_), address) == -1)
{
ERROR_MSG(fmt::format("ClientObject::initLogin({}): connect server is error({})!\n",
kbe_strerror(), name_));
Network::EndPoint::ObjPool().reclaimObject(pEndpoint);
// error_ = C_ERROR_INIT_NETWORK_FAILED;
state_ = C_STATE_LOGIN_GATEWAY_CREATE;
return false;
}
Network::Address addr(ip_.c_str(), port_);
pEndpoint->addr(addr);
pServerChannel_->pEndPoint(pEndpoint);
pEndpoint->setnonblocking(true);
pEndpoint->setnodelay(true);
pTCPPacketSenderEx_ = new Network::TCPPacketSenderEx(*pEndpoint, this->networkInterface_, this);
pTCPPacketReceiverEx_ = new Network::TCPPacketReceiverEx(*pEndpoint, this->networkInterface_, this);
Bots::getSingleton().networkInterface().dispatcher().registerReadFileDescriptor((*pEndpoint), pTCPPacketReceiverEx_);
//²»ÔÚÕâÀï×¢²á
//Bots::getSingleton().networkInterface().dispatcher().registerWriteFileDescriptor((*pEndpoint), pTCPPacketSenderEx_);
pServerChannel_->pPacketSender(pTCPPacketSenderEx_);
connectedGateway_ = true;
Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject();
(*pBundle).newMessage(BaseappInterface::hello);
(*pBundle) << KBEVersion::versionString() << KBEVersion::scriptVersionString();
if(Network::g_channelExternalEncryptType == 1)
{
pBlowfishFilter_ = new Network::BlowfishFilter();
(*pBundle).appendBlob(pBlowfishFilter_->key());
pServerChannel_->pFilter(NULL);
}
else
{
std::string key = "";
(*pBundle).appendBlob(key);
}
pEndpoint->send(pBundle);
Network::Bundle::ObjPool().reclaimObject(pBundle);
return true;
}
示例5: initCreate
//-------------------------------------------------------------------------------------
bool ClientObject::initCreate()
{
Network::EndPoint* pEndpoint = Network::EndPoint::ObjPool().createObject();
pEndpoint->socket(SOCK_STREAM);
if (!pEndpoint->good())
{
ERROR_MSG("ClientObject::initNetwork: couldn't create a socket\n");
Network::EndPoint::ObjPool().reclaimObject(pEndpoint);
error_ = C_ERROR_INIT_NETWORK_FAILED;
return false;
}
ENGINE_COMPONENT_INFO& infos = g_kbeSrvConfig.getBots();
u_int32_t address;
Network::Address::string2ip(infos.login_ip, address);
if(pEndpoint->connect(htons(infos.login_port), address) == -1)
{
ERROR_MSG(fmt::format("ClientObject::initNetwork({1}): connect server({2}:{3}) is error({0})!\n",
kbe_strerror(), name_, infos.login_ip, infos.login_port));
Network::EndPoint::ObjPool().reclaimObject(pEndpoint);
// error_ = C_ERROR_INIT_NETWORK_FAILED;
state_ = C_STATE_INIT;
return false;
}
Network::Address addr(infos.login_ip, infos.login_port);
pEndpoint->addr(addr);
pServerChannel_->pEndPoint(pEndpoint);
pEndpoint->setnonblocking(true);
pEndpoint->setnodelay(true);
pServerChannel_->pMsgHandlers(&ClientInterface::messageHandlers);
pTCPPacketSenderEx_ = new Network::TCPPacketSenderEx(*pEndpoint, this->networkInterface_, this);
pTCPPacketReceiverEx_ = new Network::TCPPacketReceiverEx(*pEndpoint, this->networkInterface_, this);
Bots::getSingleton().networkInterface().dispatcher().registerReadFileDescriptor((*pEndpoint), pTCPPacketReceiverEx_);
//²»ÔÚÕâÀï×¢²á
//Bots::getSingleton().networkInterface().dispatcher().registerWriteFileDescriptor((*pEndpoint), pTCPPacketSenderEx_);
pServerChannel_->pPacketSender(pTCPPacketSenderEx_);
Network::Bundle* pBundle = Network::Bundle::ObjPool().createObject();
(*pBundle).newMessage(LoginappInterface::hello);
(*pBundle) << KBEVersion::versionString() << KBEVersion::scriptVersionString();
if(Network::g_channelExternalEncryptType == 1)
{
pBlowfishFilter_ = new Network::BlowfishFilter();
(*pBundle).appendBlob(pBlowfishFilter_->key());
}
else
{
std::string key = "";
(*pBundle).appendBlob(key);
}
pEndpoint->send(pBundle);
Network::Bundle::ObjPool().reclaimObject(pBundle);
return true;
}
示例6: handleInputNotification
//-------------------------------------------------------------------------------------
int HTTPCBHandler::handleInputNotification(int fd)
{
if(fd == *pEndPoint_)
{
u_int16_t port;
u_int32_t addr;
Network::EndPoint* newclient = pEndPoint_->accept(&port, &addr);
if(newclient == NULL)
{
ERROR_MSG(fmt::format("HTTPCBHandler::handleInputNotification: accept is error:{}.\n", kbe_strerror()));
return 0;
}
INFO_MSG(fmt::format("HTTPCBHandler:handleInputNotification: newclient = {}\n",
newclient->c_str()));
newclient->setnonblocking(true);
CLIENT& client = clients_[*newclient];
client.endpoint = KBEShared_ptr< Network::EndPoint >(newclient);
client.state = 0;
Loginapp::getSingleton().networkInterface().dispatcher().registerReadFileDescriptor(*newclient, this);
}
else
{
std::map< int, CLIENT >::iterator iter = clients_.find(fd);
if(iter == clients_.end())
{
ERROR_MSG(fmt::format("HTTPCBHandler:handleInputNotification: fd({}) not found!\n",
fd));
return 0;
}
CLIENT& client = iter->second;
Network::EndPoint* newclient = iter->second.endpoint.get();
char buffer[1024];
int len = newclient->recv(&buffer, 1024);
if(len <= 0)
{
ERROR_MSG(fmt::format("HTTPCBHandler:handleInputNotification: recv error, newclient = {}, recv={}.\n",
newclient->c_str(), len));
if(len == 0)
{
Loginapp::getSingleton().networkInterface().dispatcher().deregisterReadFileDescriptor(*newclient);
clients_.erase(iter);
}
return 0;
}
if(client.state == 1)
{
Loginapp::getSingleton().networkInterface().dispatcher().deregisterReadFileDescriptor(*newclient);
clients_.erase(iter);
}
int type = 0;
std::string s = buffer;
std::string keys = "<policy-file-request/>";
std::string::size_type fi0 = s.find(keys);
if(fi0 != std::string::npos)
{
if(client.state != 1)
{
std::string response = "<?xml version='1.0'?><cross-domain-policy><allow-access-from domain=""*"" to-ports=""*"" /></cross-domain-policy>";
iter->second.endpoint->send(response.c_str(), response.size());
Loginapp::getSingleton().networkInterface().dispatcher().deregisterReadFileDescriptor(*newclient);
clients_.erase(iter);
}
return 0;
}
keys = "accountactivate_";
std::string::size_type fi1 = s.find(keys);
if(fi1 == std::string::npos)
{
keys = "resetpassword_";
fi1 = s.find(keys);
if(fi1 == std::string::npos)
{
keys = "bindmail_";
fi1 = s.find(keys);
if(fi1 != std::string::npos)
{
type = 3;
}
}
else
{
type = 2;
}
}
else
{
//.........这里部分代码省略.........
示例7: reconnect
//-------------------------------------------------------------------------------------
bool InterfacesHandler_Interfaces::reconnect()
{
Network::Channel* pInterfacesChannel = Dbmgr::getSingleton().networkInterface().findChannel(g_kbeSrvConfig.interfacesAddr());
if(pInterfacesChannel)
{
if(!pInterfacesChannel->isDestroyed())
Dbmgr::getSingleton().networkInterface().deregisterChannel(pInterfacesChannel);
pInterfacesChannel->destroy();
Network::Channel::reclaimPoolObject(pInterfacesChannel);
}
Network::Address addr = g_kbeSrvConfig.interfacesAddr();
Network::EndPoint* pEndPoint = Network::EndPoint::createPoolObject();
pEndPoint->addr(addr);
pEndPoint->socket(SOCK_STREAM);
if (!pEndPoint->good())
{
ERROR_MSG("InterfacesHandler_Interfaces::initialize: couldn't create a socket\n");
return true;
}
pEndPoint->setnonblocking(true);
pEndPoint->setnodelay(true);
pInterfacesChannel = Network::Channel::createPoolObject();
bool ret = pInterfacesChannel->initialize(Dbmgr::getSingleton().networkInterface(), pEndPoint, Network::Channel::INTERNAL);
if(!ret)
{
ERROR_MSG(fmt::format("InterfacesHandler_Interfaces::initialize: initialize({}) is failed!\n",
pInterfacesChannel->c_str()));
pInterfacesChannel->destroy();
Network::Channel::reclaimPoolObject(pInterfacesChannel);
return 0;
}
if(pInterfacesChannel->pEndPoint()->connect() == -1)
{
struct timeval tv = { 0, 1000000 }; // 1000ms
fd_set fds;
FD_ZERO(&fds);
FD_SET((int)(*pInterfacesChannel->pEndPoint()), &fds);
bool connected = false;
int selgot = select((*pInterfacesChannel->pEndPoint())+1, &fds, &fds, NULL, &tv);
if(selgot > 0)
{
int error;
socklen_t len = sizeof(error);
#if KBE_PLATFORM == PLATFORM_WIN32
getsockopt(int(*pInterfacesChannel->pEndPoint()), SOL_SOCKET, SO_ERROR, (char*)&error, &len);
#else
getsockopt(int(*pInterfacesChannel->pEndPoint()), SOL_SOCKET, SO_ERROR, &error, &len);
#endif
if(0 == error)
connected = true;
}
if(!connected)
{
ERROR_MSG(fmt::format("InterfacesHandler_Interfaces::reconnect(): couldn't connect to:{}\n",
pInterfacesChannel->pEndPoint()->addr().c_str()));
pInterfacesChannel->destroy();
Network::Channel::reclaimPoolObject(pInterfacesChannel);
return false;
}
}
// 不检查超时
pInterfacesChannel->stopInactivityDetection();
Dbmgr::getSingleton().networkInterface().registerChannel(pInterfacesChannel);
return true;
}
示例8: reconnect
//-------------------------------------------------------------------------------------
bool BillingHandler_ThirdParty::reconnect()
{
if(pBillingChannel_)
{
if(!pBillingChannel_->isDestroyed())
Dbmgr::getSingleton().networkInterface().deregisterChannel(pBillingChannel_);
pBillingChannel_->decRef();
}
Network::Address addr = g_kbeSrvConfig.billingSystemAddr();
Network::EndPoint* pEndPoint = new Network::EndPoint(addr);
pEndPoint->socket(SOCK_STREAM);
if (!pEndPoint->good())
{
ERROR_MSG("BillingHandler_ThirdParty::initialize: couldn't create a socket\n");
return true;
}
pEndPoint->setnonblocking(true);
pEndPoint->setnodelay(true);
pBillingChannel_ = new Network::Channel(Dbmgr::getSingleton().networkInterface(), pEndPoint, Network::Channel::INTERNAL);
pBillingChannel_->incRef();
int trycount = 0;
while(true)
{
fd_set frds, fwds;
struct timeval tv = { 0, 100000 }; // 100ms
FD_ZERO( &frds );
FD_ZERO( &fwds );
FD_SET((int)(*pBillingChannel_->endpoint()), &frds);
FD_SET((int)(*pBillingChannel_->endpoint()), &fwds);
if(pBillingChannel_->endpoint()->connect() == -1)
{
int selgot = select((*pBillingChannel_->endpoint())+1, &frds, &fwds, NULL, &tv);
if(selgot > 0)
{
break;
}
trycount++;
if(trycount > 3)
{
ERROR_MSG(fmt::format("BillingHandler_ThirdParty::reconnect(): couldn't connect to:{}\n",
pBillingChannel_->endpoint()->addr().c_str()));
pBillingChannel_->destroy();
return false;
}
}
}
// 不检查超时
pBillingChannel_->stopInactivityDetection();
Dbmgr::getSingleton().networkInterface().registerChannel(pBillingChannel_);
return true;
}