Commit 56cc6d14 authored by 黄振令's avatar 黄振令

Author: huang.zhenling

Root Cause: 优化api
How2Fix:
parent 84f4eea9
......@@ -14,6 +14,7 @@ typedef struct {
}Bloop_ctrl_t;
Bloop_ctrl_t Bloop_ctrl;
static struct ev_io g_watcher;
struct ev_loop* gloop;
ipc_cb* g_cb = NULL;
......@@ -103,28 +104,28 @@ int __nanomsg_init(Bloop_ctrl_t *Bloop_ctrl, ipc_type type)
*
==================================*/
void loop_thread(void *arg){
struct ev_loop* loop = __loop_init(&Bloop_ctrl);
if (NULL == loop) {
printf("loop init failed\r\n");
gloop = __loop_init(&Bloop_ctrl);
if (NULL == gloop) {
printf("gloop init failed\r\n");
return ;
}
ev_set_userdata(loop, &Bloop_ctrl);
ev_run (loop, 0);
ev_set_userdata(gloop, &Bloop_ctrl);
ev_run (gloop, 0);
}
void kk_ipc_init(ipc_type type, ipc_cb cb)
int kk_ipc_init(ipc_type type, ipc_cb cb)
{
pthread_t pb;
if (g_cb == NULL){
if (g_cb != NULL){
printf("ipc has been inited!\r\n");
return;
return -1;
}
if (__nanomsg_init(&Bloop_ctrl, type) < 0) {
printf("nanomsg init failed\r\n");
return ;
return -1;
}
if (0 != pthread_create(&pb, NULL, loop_thread, NULL)) {
......@@ -132,20 +133,21 @@ void kk_ipc_init(ipc_type type, ipc_cb cb)
return -1;
}
g_cb = cb;
return ;
return 0;
}
int kk_ipc_dinit()
{
#if 0
if (Bloop_ctrl.ba.n > -1){
nn_shutdown(Bloop_ctrl.ba.n, 0);
}
ev_io_stop(g_watcher);
ev_break(EV_A_ EVBREAK_ALL);
ev_io_stop(gloop, &g_watcher);
ev_break(gloop,EVBREAK_ALL);
g_cb = NULL;
#endif
return 0;
}
......@@ -160,4 +162,6 @@ int kk_ipc_send(void* data)
//printf("kk_ipc_send: RECEIVED \"%s\"\n", data);
}
return 0;
}
......@@ -27,7 +27,7 @@ typedef enum {
} ipc_type;
typedef void ipc_cb(void* data);
void kk_ipc_init(ipc_type type, ipc_cb cb);
int kk_ipc_init(ipc_type type, ipc_cb cb);
int kk_ipc_dinit();
int kk_ipc_send(void* data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment