move type SFNetworkType to libfastcommon as FCNetworkType

support_rdma
YuQing 2023-09-04 11:01:36 +08:00
parent 36e4922440
commit 2839183433
9 changed files with 41 additions and 36 deletions

View File

@ -31,11 +31,11 @@
#include "fastcommon/pthread_func.h"
#include "fastcommon/sched_thread.h"
#include "fastcommon/fc_queue.h"
#include "../../sf_util.h"
#include "../../sf_func.h"
#include "../../sf_nio.h"
#include "../../sf_global.h"
#include "../../sf_service.h"
#include "sf/sf_util.h"
#include "sf/sf_func.h"
#include "sf/sf_nio.h"
#include "sf/sf_global.h"
#include "sf/sf_service.h"
#include "client_channel.h"
typedef struct {
@ -171,13 +171,13 @@ void client_channel_destroy()
}
static struct fast_task_info *alloc_channel_task(IdempotencyClientChannel
*channel, const uint32_t hash_code, const SFNetworkType network_type,
*channel, const uint32_t hash_code, const FCNetworkType network_type,
const char *server_ip, const uint16_t port, int *err_no)
{
struct fast_task_info *task;
SFNetworkHandler *handler;
if (network_type == sf_network_type_sock) {
if (network_type == fc_network_type_sock) {
handler = g_sf_context.handlers + SF_SOCKET_NETWORK_HANDLER_INDEX;
} else {
handler = g_sf_context.handlers + SF_RDMACM_NETWORK_HANDLER_INDEX;
@ -232,7 +232,7 @@ int idempotency_client_channel_check_reconnect(
}
struct idempotency_client_channel *idempotency_client_channel_get(
const SFNetworkType network_type, const char *server_ip,
const FCNetworkType network_type, const char *server_ip,
const uint16_t server_port, const int timeout, int *err_no)
{
int r;

View File

@ -22,6 +22,7 @@
#include "fastcommon/pthread_func.h"
#include "fastcommon/sched_thread.h"
#include "fastcommon/fc_atomic.h"
#include "sf/sf_types.h"
#include "client_types.h"
#ifdef __cplusplus
@ -40,7 +41,7 @@ void idempotency_client_channel_config_to_string_ex(
char *output, const int size, const bool add_comma);
struct idempotency_client_channel *idempotency_client_channel_get(
const SFNetworkType network_type, const char *server_ip,
const FCNetworkType network_type, const char *server_ip,
const uint16_t server_port, const int timeout, int *err_no);
static inline uint64_t idempotency_client_channel_next_seq_id(

View File

@ -45,7 +45,7 @@ SFGlobalVariables g_sf_global_vars = {
};
SFContext g_sf_context = {{'\0'}, NULL, 0,
{{false, sf_network_type_sock}, {false, sf_network_type_rdma}},
{{true, fc_network_type_sock}, {false, fc_network_type_rdma}},
1, DEFAULT_WORK_THREADS, {'\0'}, {'\0'}, 0, true, true, NULL,
NULL, NULL, NULL, NULL, sf_task_finish_clean_up, NULL
};
@ -421,7 +421,7 @@ static int init_network_handler(SFNetworkHandler *handler,
handler->inner.is_inner = true;
handler->outer.is_inner = false;
if (handler->type == sf_network_type_sock) {
if (handler->type == fc_network_type_sock) {
handler->inner.sock = -1;
handler->outer.sock = -1;
handler->create_server = sf_create_socket_server;
@ -453,11 +453,10 @@ int sf_load_context_from_config_ex(SFContext *sf_context,
int i;
int result;
memset(sf_context->handlers, 0, sizeof(sf_context->handlers));
sock_handler = sf_context->handlers + SF_SOCKET_NETWORK_HANDLER_INDEX;
rdma_handler = sf_context->handlers + SF_RDMACM_NETWORK_HANDLER_INDEX;
sock_handler->type = sf_network_type_sock;
rdma_handler->type = sf_network_type_rdma;
sock_handler->type = fc_network_type_sock;
rdma_handler->type = fc_network_type_rdma;
for (i=0; i<SF_NETWORK_HANDLER_COUNT; i++) {
if ((result=init_network_handler(sf_context->handlers + i,
sf_context)) != 0)

View File

@ -85,8 +85,10 @@ extern SFContext g_sf_context;
#define SF_G_MAX_CONNECTIONS g_sf_global_vars.max_connections
#define SF_G_THREAD_STACK_SIZE g_sf_global_vars.thread_stack_size
#define SF_G_OUTER_PORT g_sf_context.outer_port
#define SF_G_INNER_PORT g_sf_context.inner_port
#define SF_G_SOCK_HANDLER (g_sf_context.handlers + \
SF_SOCKET_NETWORK_HANDLER_INDEX)
#define SF_G_OUTER_PORT SF_G_SOCK_HANDLER->outer.port
#define SF_G_INNER_PORT SF_G_SOCK_HANDLER->inner.port
#define SF_G_OUTER_BIND_ADDR g_sf_context.outer_bind_addr
#define SF_G_INNER_BIND_ADDR g_sf_context.inner_bind_addr

View File

@ -721,7 +721,7 @@ ssize_t sf_socket_recv_data(struct fast_task_info *task, SFCommAction *action)
*action = sf_comm_action_continue;
}
return 0;
return bytes;
}
int sf_client_sock_read(int sock, short event, void *arg)

View File

@ -589,7 +589,7 @@ void sf_proto_set_handler_context(const SFHandlerContext *ctx)
}
int sf_proto_deal_task_done(struct fast_task_info *task,
SFCommonTaskContext *ctx)
const char *service_name, SFCommonTaskContext *ctx)
{
SFCommonProtoHeader *proto_header;
int status;
@ -600,10 +600,10 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
if (ctx->log_level != LOG_NOTHING && ctx->response.error.length > 0) {
log_it_ex(&g_log_context, ctx->log_level,
"file: "__FILE__", line: %d, "
"file: "__FILE__", line: %d, %s "
"peer %s:%u, cmd: %d (%s), req body length: %d, "
"resp status: %d, %s", __LINE__, task->client_ip,
task->port, ctx->request.header.cmd,
"resp status: %d, %s", __LINE__, service_name,
task->client_ip, task->port, ctx->request.header.cmd,
GET_CMD_CAPTION(ctx->request.header.cmd),
ctx->request.header.body_len, ctx->response.header.status,
ctx->response.error.message);
@ -614,8 +614,8 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
time_used = get_current_time_us() - ctx->req_start_time;
log_level = GET_CMD_LOG_LEVEL(ctx->request.header.cmd);
log_it_ex(&g_log_context, log_level, "file: "__FILE__", line: %d, "
"client %s:%u, req cmd: %d (%s), req body_len: %d, "
"resp status: %d, time used: %s us", __LINE__,
"%s client %s:%u, req cmd: %d (%s), req body_len: %d, "
"resp status: %d, time used: %s us", __LINE__, service_name,
task->client_ip, task->port, ctx->request.header.cmd,
GET_CMD_CAPTION(ctx->request.header.cmd),
ctx->request.header.body_len, ctx->response.header.status,
@ -653,11 +653,11 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
char buff[256];
int blen;
blen = sprintf(buff, "timed used: %s us, client %s:%u, "
blen = sprintf(buff, "timed used: %s us, %s client %s:%u, "
"req cmd: %d (%s), req body len: %d, resp cmd: %d (%s), "
"status: %d, resp body len: %d", long_to_comma_str(time_used,
time_buff), task->client_ip, task->port, ctx->request.
header.cmd, GET_CMD_CAPTION(ctx->request.header.cmd),
time_buff), service_name, task->client_ip, task->port, ctx->
request.header.cmd, GET_CMD_CAPTION(ctx->request.header.cmd),
ctx->request.header.body_len, ctx->response.header.cmd,
GET_CMD_CAPTION(ctx->response.header.cmd),
ctx->response.header.status, ctx->response.header.body_len);
@ -667,9 +667,9 @@ int sf_proto_deal_task_done(struct fast_task_info *task,
if (sf_handler_ctx.callbacks.get_cmd_log_level != NULL) {
log_level = GET_CMD_LOG_LEVEL(ctx->request.header.cmd);
log_it_ex(&g_log_context, log_level, "file: "__FILE__", line: %d, "
"client %s:%u, req cmd: %d (%s), req body_len: %d, "
"%s client %s:%u, req cmd: %d (%s), req body_len: %d, "
"resp cmd: %d (%s), status: %d, resp body_len: %d, "
"time used: %s us", __LINE__,
"time used: %s us", __LINE__, service_name,
task->client_ip, task->port, ctx->request.header.cmd,
GET_CMD_CAPTION(ctx->request.header.cmd),
ctx->request.header.body_len, ctx->response.header.cmd,

View File

@ -280,7 +280,7 @@ int sf_proto_set_body_length(struct fast_task_info *task);
const char *sf_get_cmd_caption(const int cmd);
int sf_proto_deal_task_done(struct fast_task_info *task,
SFCommonTaskContext *ctx);
const char *service_name, SFCommonTaskContext *ctx);
static inline void sf_proto_init_task_context(struct fast_task_info *task,
SFCommonTaskContext *ctx)

View File

@ -423,6 +423,14 @@ int sf_socket_server_ex(SFContext *sf_context)
handler->inner.enabled = true;
handler->outer.enabled = true;
}
/*
logInfo("%p [%d] inner {port: %d, enabled: %d}, "
"outer {port: %d, enabled: %d}", sf_context,
(int)(handler-sf_context->handlers),
handler->inner.port, handler->inner.enabled,
handler->outer.port, handler->outer.enabled);
*/
}
return 0;
@ -533,7 +541,7 @@ static void *accept_thread_entrance(SFListener *listener)
{
char thread_name[32];
snprintf(thread_name, sizeof(thread_name), "%s-%s-listen",
listener->handler->type == sf_network_type_sock ?
listener->handler->type == fc_network_type_sock ?
"sock" : "rdma", listener->handler->ctx->name);
prctl(PR_SET_NAME, thread_name);
}

View File

@ -53,11 +53,6 @@ typedef void (*sf_release_buffer_callback)(struct fast_task_info *task);
typedef int (*sf_error_handler_callback)(const int errnum);
typedef enum {
sf_network_type_sock = 's',
sf_network_type_rdma = 'r'
} SFNetworkType;
typedef enum {
sf_comm_action_continue = 'c',
sf_comm_action_break = 'b',
@ -95,7 +90,7 @@ typedef struct sf_listener {
struct sf_context;
typedef struct sf_network_handler {
bool enabled;
SFNetworkType type;
FCNetworkType type;
struct sf_context *ctx;
SFListener inner;