本文整理汇总了C++中ObServer::get_ipv4_server_id方法的典型用法代码示例。如果您正苦于以下问题:C++ ObServer::get_ipv4_server_id方法的具体用法?C++ ObServer::get_ipv4_server_id怎么用?C++ ObServer::get_ipv4_server_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObServer
的用法示例。
在下文中一共展示了ObServer::get_ipv4_server_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_post_packet
/**
* post_packet is async version of send_packet. donot wait for response packet.
*/
int ObClientManager::do_post_packet(const ObServer& server, ObPacket* packet,
tbnet::IPacketHandler* handler, void* args) const
{
int rc = OB_SUCCESS;
if (NULL == packet)
{
rc = OB_INVALID_ARGUMENT;
}
else if (!inited_)
{
rc = OB_NOT_INIT;
TBSYS_LOG(ERROR, "cannot post packet, ClientManager not initialized.");
packet->free();
}
else
{
bool send_ok = connmgr_->sendPacket(server.get_ipv4_server_id(), packet, handler, args);
if (!send_ok)
{
rc = OB_PACKET_NOT_SENT;
TBSYS_LOG(WARN, "cannot post packet, maybe send queue is full or disconnect.dest_server:%s",
server.to_cstring());
packet->free();
}
}
return rc;
}
示例2: do_send_packet
/*
* send a packet to server %server and wait response packet
* @param server send to server
* @param packet send packet object, must be allocate on heap,
* if send_packet failed, packet will be free by send_packet.
* @param timeout max wait time interval
* @param [out] response response packet from remote server, allocated on heap,
* must be free by user who call the send_packet. response not NULL when return success.
* @return OB_SUCCESS on success or other on failure.
*/
int ObClientManager::do_send_packet(const ObServer & server,
ObPacket* packet, const int64_t timeout, ObPacket* &response) const
{
response = NULL;
int rc = OB_SUCCESS;
if (NULL == packet)
{
rc = OB_INVALID_ARGUMENT;
}
else if (!inited_)
{
rc = OB_NOT_INIT;
TBSYS_LOG(ERROR, "cannot send packet, ClientManager not initialized.");
packet->free();
packet = NULL;
}
else if (OB_SUCCESS != error_)
{
rc = error_;
packet->free();
TBSYS_LOG(ERROR, "prev_error=%d", error_);
}
common::WaitObject* wait_object = NULL;
if (OB_SUCCESS == rc)
{
wait_object = waitmgr_->create_wait_object();
if (NULL == wait_object)
{
TBSYS_LOG(ERROR, "cannot send packet, cannot create wait object");
rc = OB_ERROR;
}
}
if (OB_SUCCESS == rc)
{
if (timeout > max_request_timeout_)
{
max_request_timeout_ = timeout;
connmgr_->setDefaultQueueTimeout(0, static_cast<int32_t>(max_request_timeout_ / 1000));
}
// caution! wait_object set no free, it means response packet
// not be free by wait_object, must be handled by user who call send_packet.
// MODIFY: wait_object need free the response packet not handled.
// wait_object->set_no_free();
int packet_code = packet->get_packet_code();
bool send_ok = connmgr_->sendPacket(server.get_ipv4_server_id(), packet, NULL,
reinterpret_cast<void*>(wait_object->get_id()));
if (send_ok)
{
send_ok = wait_object->wait(timeout);
if (!send_ok)
{
TBSYS_LOG(ERROR, "wait packet(%d) response timeout, timeout=%ld, dest_server=%s",
packet_code, timeout, server.to_cstring());
rc = OB_RESPONSE_TIME_OUT;
}
else
{
response = dynamic_cast<ObPacket*>(wait_object->get_response());
// there's two situation on here.
// 1. connect remote server failed, ControlPacket(timeout) raise up.
// 2. timeout parameter of this function greater than default timeout
// of ConnectManager(5000ms), Packet timeout raise up.
// TODO, maybe need a new error code.
rc = (NULL != response) ? OB_SUCCESS : OB_RESPONSE_TIME_OUT;
}
}
else
{
packet->free();
rc = OB_PACKET_NOT_SENT;
TBSYS_LOG(WARN, "cannot send packet, maybe send queue is full or disconnect.");
}
// do not free the response packet.
waitmgr_->destroy_wait_object(wait_object);
wait_object = NULL;
if (OB_SUCCESS == rc && NULL != response)
{
rc = response->deserialize();
if (OB_SUCCESS != rc)
{
TBSYS_LOG(ERROR, "response packet deserialize failed.");
// cannot free response packet, allocate on thread specific memeory.
response = NULL;
}
}
//.........这里部分代码省略.........