ConnectionCallbacks struct changed
parent
d24023aee7
commit
c9687df03a
|
|
@ -23,10 +23,9 @@
|
||||||
#include "sched_thread.h"
|
#include "sched_thread.h"
|
||||||
#include "connection_pool.h"
|
#include "connection_pool.h"
|
||||||
|
|
||||||
ConnectionCallbacks g_connection_callbacks[2] = {
|
ConnectionCallbacks g_connection_callbacks = {
|
||||||
{NULL, NULL, NULL, conn_pool_connect_server_ex1,
|
{{conn_pool_connect_server_ex1, conn_pool_disconnect_server},
|
||||||
conn_pool_disconnect_server, NULL},
|
{NULL, NULL}}, {NULL}
|
||||||
{NULL, NULL, NULL, NULL, NULL, NULL}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int node_init_for_socket(ConnectionNode *node,
|
static int node_init_for_socket(ConnectionNode *node,
|
||||||
|
|
@ -119,7 +118,7 @@ static int coon_pool_close_connections(const int index,
|
||||||
deleted = node;
|
deleted = node;
|
||||||
node = node->next;
|
node = node->next;
|
||||||
|
|
||||||
g_connection_callbacks[deleted->conn->comm_type].
|
G_COMMON_CONNECTION_CALLBACKS[deleted->conn->comm_type].
|
||||||
close_connection(deleted->conn);
|
close_connection(deleted->conn);
|
||||||
fast_mblock_free_object(&cp->node_allocator, deleted);
|
fast_mblock_free_object(&cp->node_allocator, deleted);
|
||||||
}
|
}
|
||||||
|
|
@ -307,7 +306,7 @@ ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp,
|
||||||
node->conn->socket_domain = cp->socket_domain;
|
node->conn->socket_domain = cp->socket_domain;
|
||||||
node->conn->sock = -1;
|
node->conn->sock = -1;
|
||||||
node->conn->validate_flag = false;
|
node->conn->validate_flag = false;
|
||||||
*err_no = g_connection_callbacks[conn->comm_type].
|
*err_no = G_COMMON_CONNECTION_CALLBACKS[conn->comm_type].
|
||||||
make_connection(node->conn, service_name,
|
make_connection(node->conn, service_name,
|
||||||
cp->connect_timeout, NULL, true);
|
cp->connect_timeout, NULL, true);
|
||||||
if (*err_no == 0 && cp->connect_done_callback.func != NULL)
|
if (*err_no == 0 && cp->connect_done_callback.func != NULL)
|
||||||
|
|
@ -317,7 +316,7 @@ ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp,
|
||||||
}
|
}
|
||||||
if (*err_no != 0)
|
if (*err_no != 0)
|
||||||
{
|
{
|
||||||
g_connection_callbacks[conn->comm_type].
|
G_COMMON_CONNECTION_CALLBACKS[conn->comm_type].
|
||||||
close_connection(node->conn);
|
close_connection(node->conn);
|
||||||
pthread_mutex_lock(&cm->lock);
|
pthread_mutex_lock(&cm->lock);
|
||||||
cm->total_count--; //rollback
|
cm->total_count--; //rollback
|
||||||
|
|
@ -383,7 +382,8 @@ ConnectionInfo *conn_pool_get_connection_ex(ConnectionPool *cp,
|
||||||
(current_time - node->atime), cp->max_idle_time,
|
(current_time - node->atime), cp->max_idle_time,
|
||||||
cm->total_count, cm->free_count);
|
cm->total_count, cm->free_count);
|
||||||
|
|
||||||
g_connection_callbacks[ci->comm_type].close_connection(ci);
|
G_COMMON_CONNECTION_CALLBACKS[ci->comm_type].
|
||||||
|
close_connection(ci);
|
||||||
fast_mblock_free_object(&cp->node_allocator, node);
|
fast_mblock_free_object(&cp->node_allocator, node);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -441,7 +441,8 @@ int conn_pool_close_connection_ex(ConnectionPool *cp, ConnectionInfo *conn,
|
||||||
__LINE__, conn->ip_addr, conn->port,
|
__LINE__, conn->ip_addr, conn->port,
|
||||||
conn->sock, cm->total_count, cm->free_count);
|
conn->sock, cm->total_count, cm->free_count);
|
||||||
|
|
||||||
g_connection_callbacks[conn->comm_type].close_connection(conn);
|
G_COMMON_CONNECTION_CALLBACKS[conn->comm_type].
|
||||||
|
close_connection(conn);
|
||||||
fast_mblock_free_object(&cp->node_allocator, node);
|
fast_mblock_free_object(&cp->node_allocator, node);
|
||||||
|
|
||||||
node = cm->head;
|
node = cm->head;
|
||||||
|
|
@ -571,8 +572,8 @@ int conn_pool_load_server_info(IniContext *pIniContext, const char *filename,
|
||||||
|
|
||||||
#define LOAD_API(callbacks, fname) \
|
#define LOAD_API(callbacks, fname) \
|
||||||
do { \
|
do { \
|
||||||
callbacks->fname = dlsym(dlhandle, API_PREFIX_NAME#fname); \
|
callbacks.fname = dlsym(dlhandle, API_PREFIX_NAME#fname); \
|
||||||
if (callbacks->fname == NULL) { \
|
if (callbacks.fname == NULL) { \
|
||||||
logError("file: "__FILE__", line: %d, " \
|
logError("file: "__FILE__", line: %d, " \
|
||||||
"dlsym api %s fail, error info: %s", \
|
"dlsym api %s fail, error info: %s", \
|
||||||
__LINE__, API_PREFIX_NAME#fname, dlerror()); \
|
__LINE__, API_PREFIX_NAME#fname, dlerror()); \
|
||||||
|
|
@ -583,7 +584,6 @@ int conn_pool_load_server_info(IniContext *pIniContext, const char *filename,
|
||||||
int conn_pool_global_init_for_rdma()
|
int conn_pool_global_init_for_rdma()
|
||||||
{
|
{
|
||||||
const char *library = "libfastrdma.so";
|
const char *library = "libfastrdma.so";
|
||||||
ConnectionCallbacks *callbacks;
|
|
||||||
void *dlhandle;
|
void *dlhandle;
|
||||||
|
|
||||||
dlhandle = dlopen(library, RTLD_LAZY);
|
dlhandle = dlopen(library, RTLD_LAZY);
|
||||||
|
|
@ -594,13 +594,22 @@ int conn_pool_global_init_for_rdma()
|
||||||
return EFAULT;
|
return EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
callbacks = g_connection_callbacks + fc_comm_type_rdma;
|
LOAD_API(G_COMMON_CONNECTION_CALLBACKS[fc_comm_type_rdma],
|
||||||
LOAD_API(callbacks, alloc_pd);
|
make_connection);
|
||||||
LOAD_API(callbacks, get_connection_size);
|
LOAD_API(G_COMMON_CONNECTION_CALLBACKS[fc_comm_type_rdma],
|
||||||
LOAD_API(callbacks, init_connection);
|
close_connection);
|
||||||
LOAD_API(callbacks, make_connection);
|
|
||||||
LOAD_API(callbacks, close_connection);
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, alloc_pd);
|
||||||
LOAD_API(callbacks, destroy_connection);
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, get_connection_size);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, init_connection);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, make_connection);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, close_connection);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, destroy_connection);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, get_buffer);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, request_by_buf1);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, request_by_buf2);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, request_by_iov);
|
||||||
|
LOAD_API(G_RDMA_CONNECTION_CALLBACKS, request_by_mix);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,24 @@ typedef int (*fc_make_connection_callback)(ConnectionInfo *conn,
|
||||||
typedef void (*fc_close_connection_callback)(ConnectionInfo *conn);
|
typedef void (*fc_close_connection_callback)(ConnectionInfo *conn);
|
||||||
typedef void (*fc_destroy_connection_callback)(ConnectionInfo *conn);
|
typedef void (*fc_destroy_connection_callback)(ConnectionInfo *conn);
|
||||||
|
|
||||||
|
typedef BufferInfo *(*fc_rdma_get_buffer_callback)(ConnectionInfo *conn);
|
||||||
|
typedef int (*fc_rdma_request_by_buf1_callback)(ConnectionInfo *conn,
|
||||||
|
const char *data, const int length, const int timeout_ms);
|
||||||
|
typedef int (*fc_rdma_request_by_buf2_callback)(ConnectionInfo *conn,
|
||||||
|
const char *data1, const int length1, const char *data2,
|
||||||
|
const int length2, const int timeout_ms);
|
||||||
|
typedef int (*fc_rdma_request_by_iov_callback)(ConnectionInfo *conn,
|
||||||
|
const struct iovec *iov, const int iovcnt,
|
||||||
|
const int timeout_ms);
|
||||||
|
typedef int (*fc_rdma_request_by_mix_callback)(ConnectionInfo *conn,
|
||||||
|
const char *data, const int length, const struct iovec *iov,
|
||||||
|
const int iovcnt, const int timeout_ms);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
fc_make_connection_callback make_connection;
|
||||||
|
fc_close_connection_callback close_connection;
|
||||||
|
} CommonConnectionCallbacks;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
fc_alloc_pd_callback alloc_pd;
|
fc_alloc_pd_callback alloc_pd;
|
||||||
fc_get_connection_size_callback get_connection_size;
|
fc_get_connection_size_callback get_connection_size;
|
||||||
|
|
@ -76,6 +94,17 @@ typedef struct {
|
||||||
fc_make_connection_callback make_connection;
|
fc_make_connection_callback make_connection;
|
||||||
fc_close_connection_callback close_connection;
|
fc_close_connection_callback close_connection;
|
||||||
fc_destroy_connection_callback destroy_connection;
|
fc_destroy_connection_callback destroy_connection;
|
||||||
|
|
||||||
|
fc_rdma_get_buffer_callback get_buffer;
|
||||||
|
fc_rdma_request_by_buf1_callback request_by_buf1;
|
||||||
|
fc_rdma_request_by_buf2_callback request_by_buf2;
|
||||||
|
fc_rdma_request_by_iov_callback request_by_iov;
|
||||||
|
fc_rdma_request_by_mix_callback request_by_mix;
|
||||||
|
} RDMAConnectionCallbacks;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CommonConnectionCallbacks common_callbacks[2];
|
||||||
|
RDMAConnectionCallbacks rdma_callbacks;
|
||||||
} ConnectionCallbacks;
|
} ConnectionCallbacks;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
@ -131,11 +160,12 @@ typedef struct tagConnectionPool {
|
||||||
ConnectionExtraParams extra_params;
|
ConnectionExtraParams extra_params;
|
||||||
} ConnectionPool;
|
} ConnectionPool;
|
||||||
|
|
||||||
extern ConnectionCallbacks g_connection_callbacks[2];
|
extern ConnectionCallbacks g_connection_callbacks;
|
||||||
|
|
||||||
int conn_pool_global_init_for_rdma();
|
int conn_pool_global_init_for_rdma();
|
||||||
|
|
||||||
#define G_RDMA_CONNECTION_CALLBACKS g_connection_callbacks[fc_comm_type_rdma]
|
#define G_COMMON_CONNECTION_CALLBACKS g_connection_callbacks.common_callbacks
|
||||||
|
#define G_RDMA_CONNECTION_CALLBACKS g_connection_callbacks.rdma_callbacks
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init ex function
|
* init ex function
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue