本文整理汇总了C++中ObPacket类的典型用法代码示例。如果您正苦于以下问题:C++ ObPacket类的具体用法?C++ ObPacket怎么用?C++ ObPacket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObPacket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send_request
int ObClientManager::send_request(const ObServer& server, const int32_t pcode, const int32_t version,
const int64_t timeout, ObDataBuffer& in_buffer, ObDataBuffer& out_buffer, int64_t& session_id) const
{
int rc = OB_SUCCESS;
ObPacket* response = NULL;
rc = do_send_request(server, pcode, version, timeout, in_buffer, response);
// deserialize response packet to out_buffer
if (OB_SUCCESS == rc && NULL != response)
{
session_id = response->get_session_id() ; // TODO
// copy response's inner_buffer to out_buffer.
int64_t data_length = response->get_data_length();
ObDataBuffer* response_buffer = response->get_buffer();
if (out_buffer.get_remain() < data_length)
{
TBSYS_LOG(ERROR, "insufficient memory in out_buffer, remain:%ld, length=%ld",
out_buffer.get_remain(), data_length);
rc = OB_ERROR;
}
else
{
memcpy(out_buffer.get_data() + out_buffer.get_position(),
response_buffer->get_data() + response_buffer->get_position(),
data_length);
out_buffer.get_position() += data_length;
}
}
return rc;
}
示例2: process
static int process(easy_request_t *r)
{
int ret = EASY_OK;
if (NULL == r)
{
TBSYS_LOG(WARN, "request is NULL, r = %p", r);
ret = EASY_BREAK;
}
else if (NULL == r->ipacket)
{
TBSYS_LOG(WARN, "request is NULL, r->ipacket = %p", r->ipacket);
ret = EASY_BREAK;
}
else
{
ObFileServer* server = (ObFileServer*)r->ms->c->handler->user_data;
ObPacket* packet = (ObPacket*)r->ipacket;
packet->set_request(r);
r->ms->c->pool->ref++;
easy_atomic_inc(&r->ms->pool->ref);
easy_pool_set_lock(r->ms->pool);
if (OB_REQUIRE_HEARTBEAT == packet->get_packet_code())
{
server->handle_request(packet);
}
else
{
server->handlePacket(packet);
}
ret = EASY_AGAIN;
}
return ret;
}
示例3: TBSYS_LOG
int ObTbnetCallback::shadow_process(easy_request_t* r)
{
int ret = EASY_OK;
if (NULL == r || NULL == r->ipacket)
{
TBSYS_LOG(ERROR, "request is empty, r = %p, r->ipacket = %p", r, r->ipacket);
ret = EASY_BREAK;
}
else
{
ObShadowServer *server = (ObShadowServer*)r->ms->c->handler->user_data;
ObPacket *req = (ObPacket*) r->ipacket;
req->set_request(r);
ret = server->handlePacket(req);
if (OB_SUCCESS == ret)
{
r->ms->c->pool->ref++;
easy_atomic_inc(&r->ms->pool->ref);
easy_pool_set_lock(r->ms->pool);
ret = EASY_AGAIN;
}
else
{
ret = EASY_OK;
TBSYS_LOG(WARN, "can not push packet(src is %s, pcode is %u) to packet queue",
inet_ntoa_r(r->ms->c->addr), req->get_packet_code());
}
}
return ret;
}
示例4: TBSYS_LOG
tbnet::IPacketHandler::HPRetCode MockNodeServer::handlePacket(tbnet::Connection* connection, tbnet::Packet *packet)
{
tbnet::IPacketHandler::HPRetCode rc = tbnet::IPacketHandler::FREE_CHANNEL;
if (!packet->isRegularPacket())
{
TBSYS_LOG(WARN, "control packet, packet code: %d", ((tbnet::ControlPacket*)packet)->getCommand());
}
else
{
ObPacket* req = (ObPacket*) packet;
req->set_connection(connection);
int packet_code = req->get_packet_code();
bool ps = false;
switch(packet_code)
{
case OB_MMS_HEART_BEAT:
case OB_MMS_STOP_SLAVE:
case OB_MMS_SLAVE_DOWN:
case OB_MMS_TRANSFER_2_MASTER:
ps = node_.handlePacket(req);
break;
default:
ps = MockServer::handlePacket(connection, packet);
break;
}
if (!ps)
{
TBSYS_LOG(WARN, "overflow packet dropped, packet code: %d", req->getPCode());
rc = tbnet::IPacketHandler::KEEP_CHANNEL;
}
}
return rc;
}
示例5: do_request
int MockNodeServer::do_request(ObPacket* base_packet)
{
int err = OB_SUCCESS;
ObPacket* req = static_cast<ObPacket*>(base_packet);
int packet_code = req->get_packet_code();
err = req->deserialize();
if(OB_SUCCESS == err)
{
switch(packet_code)
{
case OB_MMS_HEART_BEAT:
case OB_MMS_STOP_SLAVE:
case OB_MMS_SLAVE_DOWN:
case OB_MMS_TRANSFER_2_MASTER:
err = node_.handlePacket(req);
break;
default:
err = OB_ERROR;
TBSYS_LOG(ERROR, "wrong packet code:packet[%d]", packet_code);
break;
}
}
if(err != OB_SUCCESS)
{
TBSYS_LOG(WARN, "check handle failed:ret[%d]", err);
}
return err;
}
示例6: deserialize_packet
int ObMsSqlRpcEvent::deserialize_packet(ObPacket & packet, ObNewScanner & result)
{
ObDataBuffer * data_buff = NULL;
int ret = packet.deserialize();
if (ret != OB_SUCCESS)
{
TBSYS_LOG(WARN, "deserialize the packet failed:ret[%d]", ret);
}
else
{
data_buff = packet.get_buffer();
if (NULL == data_buff)
{
ret = OB_INNER_STAT_ERROR;
TBSYS_LOG(WARN, "check packet data buff failed:buff[%p]", data_buff);
}
if (packet.get_packet_code() == OB_SESSION_END)
{
/// when session end, set session id to 0
set_session_end();
}
else
{
set_session_id(packet.get_session_id());
}
}
ObResultCode code;
if (OB_SUCCESS == ret)
{
ret = code.deserialize(data_buff->get_data(), data_buff->get_capacity(),
data_buff->get_position());
if (OB_SUCCESS != ret)
{
TBSYS_LOG(ERROR, "deserialize result failed:pos[%ld], ret[%d]",
data_buff->get_position(), ret);
}
else
{
ObCommonSqlRpcEvent::set_result_code(code.result_code_);
}
}
///
result.clear();
if ((OB_SUCCESS == ret) && (OB_SUCCESS == code.result_code_))
{
ret = result.deserialize(data_buff->get_data(), data_buff->get_capacity(),
data_buff->get_position());
if (ret != OB_SUCCESS)
{
TBSYS_LOG(WARN, "deserialize scanner failed:pos[%ld], ret[%d]",
data_buff->get_position(), ret);
}
}
return ret;
}
示例7: new
int ObClientManager::do_post_request(const ObServer& server,
const int32_t pcode, const int32_t version,
const int64_t session_id, const int64_t timeout,
const ObDataBuffer& in_buffer,
tbnet::IPacketHandler* handler, void* args) const
{
int rc = OB_SUCCESS;
ObPacket* packet = new (std::nothrow) ObPacket();
if (NULL == packet)
{
rc = OB_ALLOCATE_MEMORY_FAILED;
}
else if (OB_SUCCESS != error_)
{
packet->free();
rc = error_;
TBSYS_LOG(ERROR, "prev_error=%d", error_);
}
else
{
packet->set_packet_code(pcode);
packet->setChannelId(0);
packet->set_source_timeout(timeout);
packet->set_session_id(session_id);
packet->set_api_version(version);
packet->set_data(in_buffer);
if (timeout > max_request_timeout_)
{
max_request_timeout_ = timeout;
connmgr_->setDefaultQueueTimeout(0, static_cast<int32_t>(max_request_timeout_ / 1000));
}
rc = packet->serialize();
if (OB_SUCCESS != rc)
{
TBSYS_LOG(WARN, "packet serialize error");
packet->free();
packet = NULL;
}
else
{
rc = do_post_packet(server, packet, handler, args);
}
}
return rc;
}
示例8: TBSYS_LOG
int ObProxyCallback::process(easy_request_t *r)
{
int ret = EASY_OK;
if (NULL == r)
{
TBSYS_LOG(WARN, "request is NULL, r = %p", r);
ret = EASY_BREAK;
}
else if (NULL == r->ipacket)
{
TBSYS_LOG(WARN, "request is NULL, r->ipacket = %p", r->ipacket);
ret = EASY_BREAK;
}
else
{
ObProxyServer* server = (ObProxyServer*)r->ms->c->handler->user_data;
ObPacket* packet = (ObPacket*)r->ipacket;
packet->set_request(r);
//handle_request will send response
if (OB_REQUIRE_HEARTBEAT == packet->get_packet_code())
{
server->handle_request(packet);
ret = EASY_OK;
}
else
{
ret = server->handlePacket(packet);
if (OB_SUCCESS == ret)
{
r->ms->c->pool->ref++;
easy_atomic_inc(&r->ms->pool->ref);
easy_pool_set_lock(r->ms->pool);
ret = EASY_AGAIN;
}
else
{
ret = EASY_OK;
TBSYS_LOG(WARN, "can not push packet(src is %s, pcode is %u) to packet queue",
inet_ntoa_r(r->ms->c->addr), packet->get_packet_code());
}
}
}
return ret;
}
示例9: TBSYS_LOG
int ObUpdateCallback::process(easy_request_t* r)
{
int ret = EASY_OK;
if (NULL == r)
{
TBSYS_LOG(ERROR, "request is empty, r = %p", r);
ret = EASY_BREAK;
}
else if (NULL == r->ipacket)
{
TBSYS_LOG(ERROR, "request is empty, r->ipacket = %p", r->ipacket);
ret = EASY_BREAK;
}
else
{
ObUpdateServer *server = reinterpret_cast<ObUpdateServer*>(r->ms->c->handler->user_data);
ObPacket *req = reinterpret_cast<ObPacket*>(r->ipacket);
req->set_request(r);
r->ms->c->pool->ref ++;
easy_atomic_inc(&r->ms->pool->ref);
easy_pool_set_lock(r->ms->pool);
ret = server->handlePacket(req);
if (OB_SUCCESS == ret)
{
// enqueue success
ret = EASY_AGAIN;
}
else if (OB_ENQUEUE_FAILED == ret)
{
TBSYS_LOG(WARN, "can not push packet(src is %s, pcode is %u) to packet queue",
inet_ntoa_r(r->ms->c->addr), req->get_packet_code());
r->ms->c->pool->ref --;
easy_atomic_dec(&r->ms->pool->ref);
ret = EASY_OK;
}
else /* OB_ERROR */
{
ret = EASY_AGAIN;
}
}
return ret;
}
示例10: TBSYS_LOG
ObPacket* ObPacketQueue::pop()
{
if (head_ == NULL)
{
return NULL;
}
ObPacket* packet = head_;
ObPacket* ret_packet = NULL;
head_ = (ObPacket*)head_->_next;
if (head_ == NULL)
{
tail_ = NULL;
}
size_ --;
int err = ring_buffer_.pop_task(packet);
if (err == OB_SUCCESS)
{
ThreadSpecificBuffer::Buffer* tb = thread_buffer_->get_buffer();
if (tb == NULL)
{
TBSYS_LOG(ERROR, "get packet thread buffer failed, return NULL");
}
else
{
int64_t total_size = sizeof(ObPacket) + packet->get_packet_buffer()->get_capacity();
char* buf = tb->current();
memcpy(buf, packet, total_size);
ret_packet = (ObPacket*)buf;
buf += sizeof(ObPacket);
ret_packet->set_packet_buffer(buf, packet->get_packet_buffer()->get_capacity());
}
}
else
{
TBSYS_LOG(ERROR, "pop task from ring buffer failed, task: %p, err: %d", packet, err);
}
return ret_packet;
}
示例11: TBSYS_LOG
int ObBaseServer::send_response(const int32_t pcode, const int32_t version, const ObDataBuffer& buffer, tbnet::Connection* connection, const int32_t channel_id)
{
int rc = OB_SUCCESS;
if (connection == NULL)
{
rc = OB_ERROR;
TBSYS_LOG(WARN, "connection is NULL");
}
ObPacket* packet = new(std::nothrow) ObPacket();
if (packet == NULL)
{
rc = OB_ALLOCATE_MEMORY_FAILED;
TBSYS_LOG(ERROR, "create packet failed");
}
else
{
packet->set_packet_code(pcode);
packet->setChannelId(channel_id);
packet->set_api_version(version);
packet->set_data(buffer);
}
if (rc == OB_SUCCESS)
{
rc = packet->serialize();
if (rc != OB_SUCCESS)
TBSYS_LOG(WARN, "packet serialize error, error: %d", rc);
}
if (rc == OB_SUCCESS)
{
if (!connection->postPacket(packet))
{
uint64_t peer_id = connection->getPeerId();
TBSYS_LOG(WARN, "send packet to [%s] failed", tbsys::CNetUtil::addrToString(peer_id).c_str());
rc = OB_ERROR;
}
}
if (rc != OB_SUCCESS)
{
if (NULL != packet)
{
packet->free();
packet = NULL;
}
}
return rc;
}
示例12: guard
bool WaitObjectManager::wakeup_wait_object(const int64_t id, tbnet::Packet* response)
{
bool ret = true;
tbsys::CThreadGuard guard(&mutex_);
WaitObject* wait_object = NULL;
if (wait_objects_map_.get(id, wait_object) != hash::HASH_EXIST)
{
TBSYS_LOG(INFO, "wait object not found, id: [%ld]", id);
}
else
{
if (response != NULL && response->isRegularPacket())
{
ObPacket* packet = dynamic_cast<ObPacket*>(response);
if (packet != NULL)
{
int64_t total_size = sizeof(ObPacket) + packet->get_packet_buffer()->get_position();
char* res_buf = wait_object->response_buffer_;
memcpy(res_buf, packet, total_size);
wait_object->response_ = (ObPacket*)res_buf;
res_buf += sizeof(ObPacket);
wait_object->response_->set_packet_buffer(res_buf, packet->get_packet_buffer()->get_position());
}
else
{
TBSYS_LOG(WARN, "receive packet is not ObPacket, pcode: %d", response->getPCode());
ret = false;
}
}
// always add the done count
wait_object->wakeup();
}
return ret;
}
示例13: do_request
int MockMergeServer::do_request(ObPacket * base_packet)
{
ObPacket * packet = base_packet;
int32_t packet_code = packet->get_packet_code();
int ret = OB_SUCCESS;
ret = packet->deserialize();
int64_t receive_time = packet->get_receive_ts();
int32_t version = packet->get_api_version();
int32_t channelId = packet->getChannelId();
tbnet::Connection *connection = packet->get_connection();
ObDataBuffer *in_buff = packet->get_buffer();
ThreadSpecificBuffer::Buffer *thread_buff = response_packet_buffer_.get_buffer();
//貌似刨去了网络时间?
int64_t timeout_us = packet->get_source_timeout() - (tbsys::CTimeUtil::getTime() - packet->get_receive_ts());
if (NULL != thread_buff)
{
thread_buff->reset();
ObDataBuffer out_buff(thread_buff->current(), thread_buff->remain());
if (OB_SUCCESS == ret)
{
switch(packet_code)
{
case OB_SCAN_REQUEST:
ret = ms_scan(receive_time, version, channelId, connection, *in_buff, out_buff, timeout_us);
if (ret != OB_SUCCESS)
{
TBSYS_LOG(WARN, "ms_scan failed");
}
break;
}
}
}
return ret;
}
示例14: handle_async_request
int handle_async_request(ObMsSqlRpcEvent & result)
{
int rc = OB_SUCCESS;
ObPacket* packet = new (std::nothrow) ObPacket();
if (NULL == packet)
{
rc = OB_ALLOCATE_MEMORY_FAILED;
}
else
{
ObDataBuffer in_buffer;
int64_t data_len = 2 * 1024 * 1024;
char *data = (char *)ob_malloc(data_len);
const int32_t pcode = OB_SCAN_RESPONSE;
const int32_t version = 1;
const int64_t session_id = 0;
const int64_t timeout = 1000000;
in_buffer.set_data(data, data_len);
// fill scanner to buffer
handle_scan_table(in_buffer);
packet->set_packet_code(pcode);
packet->setChannelId(0);
packet->set_source_timeout(timeout);
packet->set_session_id(session_id);
packet->set_api_version(version);
packet->set_data(in_buffer);
rc = packet->serialize();
result.set_req_type(ObMergerRpcEvent::SCAN_RPC);
result.set_result_code(OB_SUCCESS);
if (rc != OB_SUCCESS)
{
TBSYS_LOG(WARN, "packet serialize error, error: %d", rc);
}
handler.push(&result, packet);
//result.handlePacket(packet, NULL);
}
return OB_SUCCESS;
}
示例15: sizeof
int ObTbnetCallback::encode(easy_request_t *r, void *data)
{
int ret = EASY_OK;
easy_buf_t* b = NULL;
char* buff = NULL;
ObPacket* packet = reinterpret_cast<ObPacket*>(data);
int64_t header_size = 0;
uint16_t ob_packet_header_size = 0;
#if !defined(_OB_VERSION) || _OB_VERSION<=300
/* 0.3 ObPacket 头格式: 16 bytes */
/* 2 bytes 2 bytes 8 bytes 4 bytes
*----------------------------------------------------------------------
*| ob_packet_header_size_== 0 | api_version_ | session_id_ | timeout_ |
*----------------------------------------------------------------------
*/
ob_packet_header_size = 0;
header_size = sizeof(uint16_t)/* ob_packet_header_size_ */ + sizeof(int16_t) /* api_version_ */+ sizeof(int64_t) /* session_id_ */+ sizeof(int32_t)/* timeout_ */;
#elif _OB_VERSION>300
/* 0.4 ObPacket 头格式: 24 bytes */
/* 2 bytes 2 bytes 8 bytes 4 bytes 8 bytes 8 bytes
*--------------------------------------------------------------------------------------
*| ob_packet_header_size_ | api_version_ | session_id_ | timeout_ |trace_id_|req_sign_|
*--------------------------------------------------------------------------------------
*/
ob_packet_header_size = (uint16_t)(sizeof(ob_packet_header_size) + sizeof(int16_t)/* api_version_ */ + sizeof(int64_t) /* session_id_ */ + sizeof(int32_t)/* timeout_ */ + sizeof(uint64_t)/* trace_id_ */ + sizeof(uint64_t) /* req_sign_ */);
header_size = ob_packet_header_size;
#endif
packet->set_ob_packet_header_size(ob_packet_header_size);
int64_t size = packet->get_inner_buffer()->get_position() + OB_TBNET_HEADER_LENGTH + header_size;
b = reinterpret_cast<easy_buf_t *>(easy_pool_alloc(r->ms->pool,
static_cast<uint32_t>(sizeof(easy_buf_t) + size)));
if (NULL == b)
{
TBSYS_LOG(WARN, "alloc mem for send buffer failed buf=%p size is %lu", b,
sizeof(easy_buf_t) + size);
ret = EASY_ERROR;
}
else
{
//skip sizeof(easy_buf_t) bytes
buff = reinterpret_cast<char *>(b + 1);
//b->pos = buff;
//b->end = buff + size;
//set packet length
init_easy_buf(b, buff, r, size);
packet->set_packet_len(static_cast<int>(
packet->get_inner_buffer()->get_position() + header_size));
if (false == packet->encode(buff, size))
{
ret = EASY_ERROR;
TBSYS_LOG(WARN, "encode failed packet is %p, buff is %p, size is %ld", packet, buff, size);
}
if (EASY_OK == ret)
{
easy_buf_set_data(r->ms->pool, b, buff, static_cast<uint32_t>(size));
easy_request_addbuf(r, b);
//add rpc bytes out statistics
OB_STAT_INC(COMMON, RPC_BYTES_OUT, size);
TBSYS_LOG(DEBUG, "encode packet success packet code is %d, c is %s",packet->get_packet_code(),
easy_connection_str(r->ms->c));
}
}
return ret;
}