65,186
社区成员




int ObClientManager::create_session(const ObServer& server,
const int32_t pcode, const int32_t version,
const int64_t timeout, const ObDataBuffer& in_buffer,
int64_t size, easy_session_t *& session) const
{
int ret = OB_SUCCESS;
easy_addr_t addr = convert_addr_from_server(&server);
session = easy_session_create(static_cast<int>(size));
if (NULL == session)
{
TBSYS_LOG(WARN, "create session failed");
ret = OB_LIBEASY_ERROR;
}
if (OB_SUCCESS == ret)
{
ObPacket* spacket = new(session+1)ObPacket();
//从线程局部中拿出该请求所对应的trace id
TraceId *trace_id = GET_TSI_MULT(TraceId, TSI_COMMON_PACKET_TRACE_ID_1);
if (NULL == trace_id)
{
ret = OB_ALLOCATE_MEMORY_FAILED;
TBSYS_LOG(ERROR, "no memory, alloc trace id failed, ret=%d", ret);
}
else
{
spacket->set_req_sign(ObPacket::tsi_req_sign());
ObPacket::tsi_req_sign() = 0;
/*
if (trace_id->is_invalid())
{
(trace_id->id).seq_ = atomic_inc(&(ObPacket::seq_generator_));
uint16_t *local_ip_suffix = GET_TSI_MULT(uint16_t, TSI_COMMON_IP_SUFFIX_1);
(trace_id->id).ip_ = *local_ip_suffix;
uint16_t *port = GET_TSI_MULT(uint16_t, TSI_COMMON_PORT_1);
(trace_id->id).port_ = *port;
}
*/
//else
//{
spacket->set_trace_id(trace_id->uval_);
//}
spacket->set_packet_code(pcode);
//为这个新的packet分配一个channel id
uint32_t new_chid = atomic_inc(&ObPacket::global_chid);
spacket->set_channel_id(new_chid);
spacket->set_api_version(version);
spacket->set_source_timeout(timeout);
spacket->set_data(in_buffer);
ObDataBuffer buffer(reinterpret_cast<char*>(spacket + 1), size - sizeof(ObPacket));
spacket->serialize(&buffer);
spacket->set_packet_buffer(buffer.get_data(), buffer.get_position());
spacket->get_inner_buffer()->get_position() = buffer.get_position();
session->status = EASY_CONNECT_SEND;//auto connect if there are no connection to addr
session->r.opacket = spacket;
session->addr = addr;
session->thread_ptr = handler_;
easy_session_set_timeout(session, static_cast<ev_tstamp>(timeout)/1000);
}
}
return ret;
}
#include <iostream>
using namespace std;
int main()
{
int *p = (int*)malloc(sizeof(int));
int *q = new(p)int(5);
cout<<*q<<endl;
free(p);
p = NULL;
system("pause");
return 0;
}