From 0182d4f033f2ef736005ec300c2b330614d10cad Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 25 一月 2021 17:50:24 +0800 Subject: [PATCH] fix kill -9 --- test_socket/bus_test.cpp | 41 ++++++++++++++++++++++++++++++----------- 1 files changed, 30 insertions(+), 11 deletions(-) diff --git a/test_socket/bus_test.cpp b/test_socket/bus_test.cpp index 3d3b776..1cc4ffd 100644 --- a/test_socket/bus_test.cpp +++ b/test_socket/bus_test.cpp @@ -4,8 +4,10 @@ #include "usg_common.h" #include "mm.h" #include "logger_factory.h" -static Logger *logger = LoggerFactory::getLogger(); + +#include "bus_error.h" +static Logger *logger = LoggerFactory::getLogger(); BusServerSocket * server_socket; void sigint_handler(int sig) { @@ -27,14 +29,24 @@ void *recvbuf; int size; int key; - struct timespec timeout = {2, 0}; + + int rv; ShmModSocket *sk = (ShmModSocket *)skptr; - while ( true) { - logger->debug("=========run_recv====="); - sk->recvfrom_timeout( &recvbuf, &size, &key, &timeout); - printf("鏀跺埌璁㈤槄娑堟伅:%s\n", recvbuf); - free(recvbuf); + struct timespec timeout = {2, 0}; + while (true) { + printf("run_recv before\n"); + + // rv = sk->recvfrom_timeout( &recvbuf, &size, &key, &timeout); + rv = sk->recvfrom( &recvbuf, &size, &key); + if(rv == 0) { + printf("鏀跺埌璁㈤槄娑堟伅:%s\n", recvbuf); + free(recvbuf); + } else { + printf("recvfrom error %d\n", rv); + } + } + return NULL; } @@ -42,18 +54,25 @@ ShmModSocket *sk = new ShmModSocket(); pthread_t tid; - pthread_create(&tid, NULL, run_recv, (void *)sk); + + int size; char action[512]; char topic[512]; char content[512]; long i = 0; + + + pthread_create(&tid, NULL, run_recv, (void *)sk); + while (true) { //printf("Usage: pub <topic> [content] or sub <topic>\n"); - printf("Can I help you? sub, pub, desub or quit\n"); - scanf("%s",action); - + printf("Can I help you? sub, pub, desub or quit %d\n", i++); + printf("client 1\n"); + // scanf("%s", action); + std::cin >> action; + printf("client 2\n"); if(strcmp(action, "sub") == 0) { printf("Please input topic!\n"); scanf("%s", topic); -- Gitblit v1.8.0