use the newest conn_pool_init_ex1 from libfastcommon

support_rdma
YuQing 2023-09-10 20:55:46 +08:00
parent 12637bf181
commit 2463725570
4 changed files with 52 additions and 29 deletions

View File

@ -522,6 +522,11 @@ int sf_connection_manager_init_ex(SFConnectionManager *cm,
const bool bg_thread_enabled)
{
const int socket_domain = AF_INET;
struct {
ConnectionExtraParams holder;
ConnectionExtraParams *ptr;
} extra_params;
FCServerGroupInfo *server_group;
int htable_init_capacity;
int result;
@ -529,11 +534,27 @@ int sf_connection_manager_init_ex(SFConnectionManager *cm,
if (htable_init_capacity < 256) {
htable_init_capacity = 256;
}
if ((server_group=fc_server_get_group_by_index(server_cfg,
server_group_index)) == NULL)
{
return ENOENT;
}
if (server_group->comm_type == fc_comm_type_sock) {
extra_params.ptr = NULL;
} else {
//TODO: fix me!!!
extra_params.holder.buffer_size = 256 * 1024;
extra_params.holder.pd = NULL;
extra_params.ptr = &extra_params.holder;
}
if ((result=conn_pool_init_ex1(&cm->cpool, common_cfg->connect_timeout,
max_count_per_entry, max_idle_time, socket_domain,
htable_init_capacity, connect_done_callback, args,
sf_cm_validate_connection_callback, cm,
sizeof(SFConnectionParameters))) != 0)
sizeof(SFConnectionParameters),
extra_params.ptr)) != 0)
{
return result;
}

View File

@ -415,17 +415,19 @@ int sf_load_config_ex(const char *server_name, SFContextIniConfig *config,
#define API_PREFIX_NAME "fast_rdma_"
#define LOAD_API(handler, fname) \
#define LOAD_API_EX(handler, prefix, fname) \
do { \
handler->fname = dlsym(dlhandle, API_PREFIX_NAME#fname); \
handler->fname = dlsym(dlhandle, API_PREFIX_NAME#prefix#fname); \
if (handler->fname == NULL) { \
logError("file: "__FILE__", line: %d, " \
"dlsym api %s fail, error info: %s", \
__LINE__, API_PREFIX_NAME#fname, dlerror()); \
__LINE__, API_PREFIX_NAME#prefix#fname, dlerror()); \
return ENOENT; \
} \
} while (0)
#define LOAD_API(handler, fname) LOAD_API_EX(handler, "server_", fname)
static int load_rdma_apis(SFNetworkHandler *handler)
{
const char *library = "libfastrdma.so";
@ -442,11 +444,11 @@ static int load_rdma_apis(SFNetworkHandler *handler)
LOAD_API(handler, get_connection_size);
LOAD_API(handler, init_connection);
LOAD_API(handler, alloc_pd);
LOAD_API(handler, create_server);
LOAD_API(handler, close_server);
LOAD_API_EX(handler, "", create_server);
LOAD_API_EX(handler, "", close_server);
LOAD_API(handler, accept_connection);
LOAD_API(handler, async_connect_server);
LOAD_API(handler, connect_server_done);
LOAD_API_EX(handler, "", async_connect_server);
LOAD_API_EX(handler, "", connect_server_done);
LOAD_API(handler, close_connection);
LOAD_API(handler, send_data);
LOAD_API(handler, recv_data);

View File

@ -99,7 +99,7 @@ static inline int sf_recv_response_header(ConnectionInfo *conn,
SFCommonProtoHeader header_proto;
if ((result=tcprecvdata_nb(conn->sock, &header_proto,
sizeof(SFCommonProtoHeader), network_timeout)) != 0)
sizeof(SFCommonProtoHeader), network_timeout)) != 0)
{
response->error.length = snprintf(response->error.message,
sizeof(response->error.message),
@ -108,18 +108,7 @@ static inline int sf_recv_response_header(ConnectionInfo *conn,
return result;
}
if (!SF_PROTO_CHECK_MAGIC(header_proto.magic)) {
response->error.length = snprintf(response->error.message,
sizeof(response->error.message),
"magic "SF_PROTO_MAGIC_FORMAT" is invalid, "
"expect: "SF_PROTO_MAGIC_FORMAT,
SF_PROTO_MAGIC_PARAMS(header_proto.magic),
SF_PROTO_MAGIC_EXPECT_PARAMS);
return EINVAL;
}
sf_proto_extract_header(&header_proto, &response->header);
return 0;
return sf_proto_parse_header(&header_proto, response);
}
int sf_send_and_recv_response_header(ConnectionInfo *conn, char *data,

View File

@ -535,16 +535,27 @@ int sf_send_and_recv_vary_response(ConnectionInfo *conn,
const int network_timeout, const unsigned char expect_cmd,
SFProtoRecvBuffer *buffer, const int min_body_len);
static inline void sf_proto_extract_header(const SFCommonProtoHeader
*header_proto, SFHeaderInfo *header_info)
static inline int sf_proto_parse_header(const SFCommonProtoHeader
*header_proto, SFResponseInfo *response)
{
header_info->cmd = header_proto->cmd;
header_info->body_len = buff2int(header_proto->body_len);
header_info->flags = buff2short(header_proto->flags);
header_info->status = buff2short(header_proto->status);
if (header_info->status > 255) {
header_info->status = sf_localize_errno(header_info->status);
if (!SF_PROTO_CHECK_MAGIC(header_proto->magic)) {
response->error.length = snprintf(response->error.message,
sizeof(response->error.message),
"magic "SF_PROTO_MAGIC_FORMAT" is invalid, "
"expect: "SF_PROTO_MAGIC_FORMAT,
SF_PROTO_MAGIC_PARAMS(header_proto->magic),
SF_PROTO_MAGIC_EXPECT_PARAMS);
return EINVAL;
}
response->header.cmd = header_proto->cmd;
response->header.body_len = buff2int(header_proto->body_len);
response->header.flags = buff2short(header_proto->flags);
response->header.status = buff2short(header_proto->status);
if (response->header.status > 255) {
response->header.status = sf_localize_errno(response->header.status);
}
return 0;
}
static inline void sf_proto_pack_limit(const SFListLimitInfo