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


C++ ObPacket::setChannelId方法代码示例

本文整理汇总了C++中ObPacket::setChannelId方法的典型用法代码示例。如果您正苦于以下问题:C++ ObPacket::setChannelId方法的具体用法?C++ ObPacket::setChannelId怎么用?C++ ObPacket::setChannelId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObPacket的用法示例。


在下文中一共展示了ObPacket::setChannelId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: send_response

    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;
    }
开发者ID:CCoder123,项目名称:pproj,代码行数:52,代码来源:ob_base_server.cpp

示例2: do_post_request

    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;
    }
开发者ID:Abioy,项目名称:oceanbase,代码行数:47,代码来源:ob_client_manager.cpp

示例3: do_send_request

    int ObClientManager::do_send_request(
        const ObServer& server, const int32_t pcode, 
        const int32_t version, const int64_t timeout, 
        ObDataBuffer& in_buffer, ObPacket* &response) const
    {
      int rc = OB_SUCCESS;

      ObPacket* packet = new (std::nothrow) ObPacket();
      if (NULL == packet)
      {
        rc = OB_ALLOCATE_MEMORY_FAILED;
      }
      else
      {
        packet->set_packet_code(pcode);
        packet->setChannelId(0);
        packet->set_api_version(version);
        packet->set_data(in_buffer);
        packet->set_source_timeout(timeout);
      }

      if (OB_SUCCESS == rc)
      {
        rc = packet->serialize();
        if (OB_SUCCESS != rc)
          TBSYS_LOG(WARN, "packet serialize error");
      }

      // serialize failed
      if (OB_SUCCESS != rc && NULL != packet)
      {
        packet->free();
      }

      if (OB_SUCCESS == rc)
      {
        rc = do_send_packet(server, packet, timeout, response);
      }

      return rc;
    }
开发者ID:Abioy,项目名称:oceanbase,代码行数:41,代码来源:ob_client_manager.cpp

示例4: 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;
}
开发者ID:Alibaba-boonya,项目名称:oceanbase,代码行数:38,代码来源:ob_rpc_scan_test.cpp

示例5: get_next

    int ObClientManager::get_next(const ObServer& server, const int64_t session_id, 
        const int64_t timeout, ObDataBuffer& in_buffer, ObDataBuffer& out_buffer) const
    {
      int rc = OB_SUCCESS;

      ObPacket* response = NULL;
      //rc = send_request(server, pcode, version, timeout, in_buffer, response);
      ObPacket* packet = new (std::nothrow) ObPacket();
      if (NULL == packet)
      {
        rc = OB_ALLOCATE_MEMORY_FAILED;
      }
      else
      {
        packet->set_packet_code(OB_SESSION_NEXT_REQUEST);
        packet->setChannelId(0);
        packet->set_api_version(0);
        packet->set_data(in_buffer);
        packet->set_source_timeout(timeout);
        packet->set_session_id(session_id); //TODO
      }

      if (OB_SUCCESS == rc)
      {
        rc = packet->serialize();
        if (OB_SUCCESS != rc)
          TBSYS_LOG(WARN, "packet serialize error, code=%d", packet->get_packet_code());
      }

      // serialize failed
      if (OB_SUCCESS != rc && NULL != packet)
      {
        packet->free();
      }

      if (OB_SUCCESS == rc)
      {
        rc = do_send_packet(server, packet, timeout, response);
      }

      // deserialize response packet to out_buffer
      if (OB_SUCCESS == rc && NULL != response)
      {
        // 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;
    }
开发者ID:Abioy,项目名称:oceanbase,代码行数:64,代码来源:ob_client_manager.cpp


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