MOD aaa-12 封装rpc调用接口,提供二次发送接口
SOL 封装rpc调用接口,提供二次发送接口 修改人:zhangliang 检视人:zhangliang
This commit is contained in:
parent
58ccc75349
commit
70b7da42e8
|
@ -33,7 +33,7 @@ ret_code rpc_client_call(rpc_client* client, char* service_name,
|
||||||
char* method_name, pointer input, int input_len, pointer* output,
|
char* method_name, pointer input, int input_len, pointer* output,
|
||||||
int* output_len);
|
int* output_len);
|
||||||
|
|
||||||
ret_code rpc_client_recall(rpc_client**pclient, char* service_name,
|
ret_code rpc_client_recall(rpc_client**pclient, char* mod_name, char* service_name,
|
||||||
char* method_name, pointer input, int input_len,
|
char* method_name, pointer input, int input_len,
|
||||||
pointer* output, int* output_len);
|
pointer* output, int* output_len);
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ ret_code rpc_client_call_async(rpc_client* client, char* service_name,
|
||||||
char* method_name, pointer input, int input_len,
|
char* method_name, pointer input, int input_len,
|
||||||
rpc_callback callback, pointer data);
|
rpc_callback callback, pointer data);
|
||||||
|
|
||||||
ret_code rpc_client_recall_async(rpc_client**pclient, char* service_name,
|
ret_code rpc_client_recall_async(rpc_client**pclient, char* mod_name, char* service_name,
|
||||||
char* method_name, pointer input, int input_len,
|
char* method_name, pointer input, int input_len,
|
||||||
rpc_callback callback, pointer data);
|
rpc_callback callback, pointer data);
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,9 @@ ret_code web_config_exec_sync(uint config_type, uint64 config_id,
|
||||||
config_len, &config_msg, &msg_len);
|
config_len, &config_msg, &msg_len);
|
||||||
ASSERT_RET(code);
|
ASSERT_RET(code);
|
||||||
|
|
||||||
code = rpc_client_recall(&g_config_client, "ConfigManger#0", "cm_config_process",
|
code = rpc_client_recall(&g_config_client, "ConfigManger#0", "ConfigManger#0",
|
||||||
config_msg, msg_len, (pointer)output, output_len);
|
"cm_config_process", config_msg, msg_len,
|
||||||
|
(pointer)output, output_len);
|
||||||
ASSERT_RET_NO(code);
|
ASSERT_RET_NO(code);
|
||||||
|
|
||||||
config_destroy_msg(config_msg, msg_len);
|
config_destroy_msg(config_msg, msg_len);
|
||||||
|
@ -106,8 +107,8 @@ ret_code web_config_exec_async(uint config_type, uint64 config_id,
|
||||||
config_len, &config_msg, &msg_len);
|
config_len, &config_msg, &msg_len);
|
||||||
ASSERT_RET(ret);
|
ASSERT_RET(ret);
|
||||||
|
|
||||||
ret = rpc_client_recall_async(&g_config_client, "ConfigManger#0", "cm_config_process",
|
ret = rpc_client_recall_async(&g_config_client, "ConfigManger#0", "ConfigManger#0",
|
||||||
config_msg, msg_len, callback, data);
|
"cm_config_process", config_msg, msg_len, callback, data);
|
||||||
ASSERT_RET_NO(ret);
|
ASSERT_RET_NO(ret);
|
||||||
|
|
||||||
config_destroy_msg(config_msg, msg_len);
|
config_destroy_msg(config_msg, msg_len);
|
||||||
|
|
|
@ -189,7 +189,7 @@ ret_code rpc_client_call(rpc_client* client, char* service_name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_code rpc_client_recall(rpc_client**pclient, char* service_name,
|
ret_code rpc_client_recall(rpc_client**pclient, char* mod_name, char* service_name,
|
||||||
char* method_name, pointer input, int input_len,
|
char* method_name, pointer input, int input_len,
|
||||||
pointer* output, int* output_len)
|
pointer* output, int* output_len)
|
||||||
{
|
{
|
||||||
|
@ -211,7 +211,7 @@ ret_code rpc_client_recall(rpc_client**pclient, char* service_name,
|
||||||
|
|
||||||
if(client == NULL)
|
if(client == NULL)
|
||||||
{
|
{
|
||||||
client = rpc_client_connect_ex(service_name);
|
client = rpc_client_connect_ex(mod_name);
|
||||||
if(client)
|
if(client)
|
||||||
{
|
{
|
||||||
*pclient = client;
|
*pclient = client;
|
||||||
|
@ -304,7 +304,7 @@ ret_code rpc_client_call_async(rpc_client* client, char* service_name,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret_code rpc_client_recall_async(rpc_client**pclient, char* service_name,
|
ret_code rpc_client_recall_async(rpc_client**pclient, char* mod_name, char* service_name,
|
||||||
char* method_name, pointer input, int input_len,
|
char* method_name, pointer input, int input_len,
|
||||||
rpc_callback callback, pointer data)
|
rpc_callback callback, pointer data)
|
||||||
{
|
{
|
||||||
|
@ -326,7 +326,7 @@ ret_code rpc_client_recall_async(rpc_client**pclient, char* service_name,
|
||||||
|
|
||||||
if(client == NULL)
|
if(client == NULL)
|
||||||
{
|
{
|
||||||
client = rpc_client_connect_ex(service_name);
|
client = rpc_client_connect_ex(mod_name);
|
||||||
if(client)
|
if(client)
|
||||||
{
|
{
|
||||||
*pclient = client;
|
*pclient = client;
|
||||||
|
|
|
@ -57,7 +57,7 @@ static void cb_dispatch_conn(struct ev_loop *l, struct ev_io *watcher,
|
||||||
int cfd;
|
int cfd;
|
||||||
if ((cfd = accept(th->sock_fd, NULL, NULL)) == -1) {
|
if ((cfd = accept(th->sock_fd, NULL, NULL)) == -1) {
|
||||||
//check errno
|
//check errno
|
||||||
rpc_log_error("accept conn error");
|
rpc_log_error("accept conn error\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rpc_log_dbg("socket %d accept %d\r\n",th->sock_fd, cfd);
|
rpc_log_dbg("socket %d accept %d\r\n",th->sock_fd, cfd);
|
||||||
|
@ -118,7 +118,7 @@ void rpc_get_unix_socket_dir(char* socket_dir)
|
||||||
|
|
||||||
if(mkdir(dir_path, 0777) != 0)
|
if(mkdir(dir_path, 0777) != 0)
|
||||||
{
|
{
|
||||||
rpc_log_error("create recovery file error");
|
rpc_log_error("create recovery file error\n");
|
||||||
strcpy(socket_dir, "");
|
strcpy(socket_dir, "");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -147,7 +147,7 @@ boolean rpc_unix_sockets_get(int port, int *psfd)
|
||||||
|
|
||||||
if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||||
{
|
{
|
||||||
rpc_log_error("socket error");
|
rpc_log_error("socket error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,13 +168,13 @@ boolean rpc_unix_sockets_get(int port, int *psfd)
|
||||||
|
|
||||||
if (bind(listenfd, (struct sockaddr *)&serun, size) < 0)
|
if (bind(listenfd, (struct sockaddr *)&serun, size) < 0)
|
||||||
{
|
{
|
||||||
rpc_log_error("bind error");
|
rpc_log_error("bind error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(listenfd, BACKLOG) < 0)
|
if (listen(listenfd, BACKLOG) < 0)
|
||||||
{
|
{
|
||||||
rpc_log_error("listen error");
|
rpc_log_error("listen error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ boolean rpc_unix_socketc_get(char *host, int port, int*pcfd)
|
||||||
|
|
||||||
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||||
{
|
{
|
||||||
rpc_log_error("client socket error");
|
rpc_log_error("client socket error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ boolean rpc_unix_socketc_get(char *host, int port, int*pcfd)
|
||||||
len = offsetof(struct sockaddr_un, sun_path) + strlen(cliun.sun_path);
|
len = offsetof(struct sockaddr_un, sun_path) + strlen(cliun.sun_path);
|
||||||
if (connect(sockfd, (struct sockaddr *)&cliun, len) < 0)
|
if (connect(sockfd, (struct sockaddr *)&cliun, len) < 0)
|
||||||
{
|
{
|
||||||
rpc_log_error("connect error");
|
rpc_log_error("connect error\n");
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -249,13 +249,13 @@ boolean rpc_tcp_sockets_get(int port, int *psfd)
|
||||||
|
|
||||||
if (bind(sfd, (struct sockaddr*) &addr, sizeof(addr)) == -1)
|
if (bind(sfd, (struct sockaddr*) &addr, sizeof(addr)) == -1)
|
||||||
{
|
{
|
||||||
rpc_log_error("bind error");
|
rpc_log_error("bind error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(sfd, BACKLOG) == -1)
|
if (listen(sfd, BACKLOG) == -1)
|
||||||
{
|
{
|
||||||
rpc_log_error("accept error");
|
rpc_log_error("accept error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ int rpc_tcp_socketc_get(char *host, int port, int*pcfd)
|
||||||
|
|
||||||
if (connect(cfd, (struct sockaddr*) &addr, sizeof(addr)) == -1)
|
if (connect(cfd, (struct sockaddr*) &addr, sizeof(addr)) == -1)
|
||||||
{
|
{
|
||||||
rpc_log_error("connect error");
|
rpc_log_error("connect error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
rpc_set_non_block(cfd);
|
rpc_set_non_block(cfd);
|
||||||
|
@ -301,7 +301,7 @@ boolean rpc_dispatch_init(rpc_dispatch_thread *th) {
|
||||||
|
|
||||||
if(rpc_unix_sockets_get(th->server->port, &sfd) != TRUE)
|
if(rpc_unix_sockets_get(th->server->port, &sfd) != TRUE)
|
||||||
{
|
{
|
||||||
rpc_log_error("unix sockets get error");
|
rpc_log_error("unix sockets get error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ boolean rpc_dispatch_start(rpc_dispatch_thread *th) {
|
||||||
pthread_t pid;
|
pthread_t pid;
|
||||||
int ret = pthread_create(&pid, NULL, thread_dispatch_handler, th);
|
int ret = pthread_create(&pid, NULL, thread_dispatch_handler, th);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
rpc_log_error("create dispatch thread error");
|
rpc_log_error("create dispatch thread error\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -332,7 +332,7 @@ rpc_conn *rpc_req_conns_new(rpc_client *client, rpc_client_thread *th)
|
||||||
int cfd = -1;
|
int cfd = -1;
|
||||||
if(rpc_unix_socketc_get(client->host, client->port, &cfd) != TRUE)
|
if(rpc_unix_socketc_get(client->host, client->port, &cfd) != TRUE)
|
||||||
{
|
{
|
||||||
rpc_log_error("connect error");
|
rpc_log_error("connect error\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
c = rpc_conn_client_new(cfd, th->loop);
|
c = rpc_conn_client_new(cfd, th->loop);
|
||||||
|
|
Loading…
Reference in New Issue