From 8b0a8c644f19e97606dfb06a865f56dbad15f95e Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 21 十二月 2020 14:44:45 +0800 Subject: [PATCH] update --- test_net_socket/test_net_mod_socket.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-) diff --git a/test_net_socket/test_net_mod_socket.c b/test_net_socket/test_net_mod_socket.c index dbebba5..1b6cf33 100644 --- a/test_net_socket/test_net_mod_socket.c +++ b/test_net_socket/test_net_mod_socket.c @@ -55,9 +55,35 @@ } +void *bus_handler(void *sockt) { + pthread_detach(pthread_self()); + + char action[512]; + while ( true) { + printf("Input action: Close?\n"); + if(scanf("%s",action) < 1) { + printf("Invalide action\n"); + continue; + } + + if(strcmp(action, "close") == 0) { + bus_server_socket_wrapper_close(sockt); + break; + } else { + printf("Invalide action\n"); + } + } + +} + + + void start_bus_server() { printf("Start bus server\n"); void * server_socket = bus_server_socket_wrapper_open(); + pthread_t tid; + // 鍒涘缓涓�涓嚎绋�,鍙互鍏抽棴bus + pthread_create(&tid, NULL, bus_handler, server_socket); if(bus_server_socket_wrapper_start_bus(server_socket) != 0) { printf("start bus failed\n"); exit(1); @@ -177,11 +203,6 @@ } - - - - - void *_run_sendandrecv_(void *arg) { Targ *targ = (Targ *)arg; @@ -349,6 +370,10 @@ // port = atoi(argv[2]); + if(opt.fun == NULL) { + usage(argv[0]); + exit(1); + } if (strcmp("start_net_proxy", opt.fun) == 0 ) { if(opt.port == 0) { @@ -359,10 +384,7 @@ } else if (strcmp("start_bus_server", opt.fun) == 0) { - if(opt.key == 0) { - usage(argv[0]); - exit(1); - } + start_bus_server(); } else if (strcmp("start_reply", opt.fun) == 0) { -- Gitblit v1.8.0