From 0cb4f2b1acb16c1ee1bd86a40116300ea2e2cdaa Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期二, 26 一月 2021 10:18:30 +0800
Subject: [PATCH] update
---
test_net_socket/CMakeLists.txt | 6 +-
src/socket/bus_server_socket.cpp | 104 +++-------------------------------
src/queue/lock_free_queue.h | 20 +++---
3 files changed, 23 insertions(+), 107 deletions(-)
diff --git a/src/queue/lock_free_queue.h b/src/queue/lock_free_queue.h
index 70549d4..56eac66 100644
--- a/src/queue/lock_free_queue.h
+++ b/src/queue/lock_free_queue.h
@@ -211,10 +211,10 @@
template<typename T, typename AT> class Q_TYPE>
int LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push(const ELEM_T &a_data, const struct timespec *timeout, int flag) {
// LoggerFactory::getLogger()->debug("==================LockFreeQueue push before\n");
- sigset_t mask_all, pre;
- sigfillset(&mask_all);
+ // sigset_t mask_all, pre;
+ // sigfillset(&mask_all);
- sigprocmask(SIG_BLOCK, &mask_all, &pre);
+ // sigprocmask(SIG_BLOCK, &mask_all, &pre);
if ((flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) {
if (psem_trywait(&slots) == -1) {
@@ -233,13 +233,13 @@
if (m_qImpl.push(a_data)) {
psem_post(&items);
- sigprocmask(SIG_SETMASK, &pre, NULL);
+ // sigprocmask(SIG_SETMASK, &pre, NULL);
LoggerFactory::getLogger()->debug("==================LockFreeQueue push after\n");
return 0;
}
LABEL_FAILTURE:
- sigprocmask(SIG_SETMASK, &pre, NULL);
+ // sigprocmask(SIG_SETMASK, &pre, NULL);
return errno;
}
@@ -249,10 +249,10 @@
int LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::pop(ELEM_T &a_data, const struct timespec *timeout, int flag) {
// LoggerFactory::getLogger()->debug("==================LockFreeQueue pop before....");
- sigset_t mask_all, pre;
- sigfillset(&mask_all);
+ // sigset_t mask_all, pre;
+ // sigfillset(&mask_all);
- sigprocmask(SIG_BLOCK, &mask_all, &pre);
+ // sigprocmask(SIG_BLOCK, &mask_all, &pre);
if ((flag & BUS_NOWAIT_FLAG) == BUS_NOWAIT_FLAG) {
if (psem_trywait(&items) == -1) {
@@ -272,13 +272,13 @@
if (m_qImpl.pop(a_data)) {
psem_post(&slots);
- sigprocmask(SIG_SETMASK, &pre, NULL);
+ // sigprocmask(SIG_SETMASK, &pre, NULL);
// LoggerFactory::getLogger()->debug("==================LockFreeQueue pop after\n");
return 0;
}
LABEL_FAILTURE:
- sigprocmask(SIG_SETMASK, &pre, NULL);
+ // sigprocmask(SIG_SETMASK, &pre, NULL);
return errno;
}
diff --git a/src/socket/bus_server_socket.cpp b/src/socket/bus_server_socket.cpp
index e66a709..462fd9d 100644
--- a/src/socket/bus_server_socket.cpp
+++ b/src/socket/bus_server_socket.cpp
@@ -22,17 +22,7 @@
}
}
}
-
-// bool BusServerSocket::include_in_keys(int key, int keys[], size_t length) {
-// if(length == 0) {
-// return false;
-// }
-// for(int i = 0; i < length; i++) {
-// if(keys[i] == key)
-// return true;
-// }
-// return false;
-// }
+
size_t BusServerSocket::remove_subscripters(int keys[], size_t length) {
size_t count = 0;
@@ -71,9 +61,7 @@
SHMKeySet *subscripter_set;
SHMTopicSubMap::iterator map_iter;
- logger->debug("BusServerSocket destory 1");
stop();
- logger->debug("BusServerSocket destory 2");
if(topic_sub_map != NULL) {
for (map_iter = topic_sub_map->begin(); map_iter != topic_sub_map->end(); map_iter++) {
@@ -121,7 +109,6 @@
int BusServerSocket::stop(){
int ret;
- logger->debug("====>stopping");
if( shm_socket->key <= 0) {
return -1;
}
@@ -132,10 +119,11 @@
head.topic_size = 0;
head.content_size = 0;
+ ShmModSocket client;
void *buf;
int size = ShmModSocket::get_bus_sendbuf(head, NULL, 0, NULL, 0, &buf);
if(size > 0) {
- ret = shm_sendandrecv_unsafe(shm_socket, buf, size, shm_socket->key, NULL, NULL);
+ ret = client.sendandrecv_unsafe( buf, size, shm_socket->key, NULL, NULL);
free(buf);
return ret;
} else {
@@ -212,12 +200,12 @@
subscripter_set = map_iter->second;
for(set_iter = subscripter_set->begin(); set_iter != subscripter_set->end(); set_iter++) {
send_key = *set_iter;
- printf("_proxy_pub send before %d \n", send_key);
+ // printf("_proxy_pub send before %d \n", send_key);
if (shm_sendto(shm_socket, buf, size, send_key, &timeout) == EBUS_CLOSED ) {
//瀵规柟宸插叧闂殑杩炴帴鏀惧埌寰呭垹闄ら槦鍒楅噷銆傚鏋滅洿鎺ュ垹闄や細璁﹊ter鎸囬拡鍑虹幇閿欎贡
subscripter_to_del.push_back(send_key);
} else {
-printf("_proxy_pub send after: %d \n", send_key);
+// printf("_proxy_pub send after: %d \n", send_key);
}
@@ -247,15 +235,15 @@
const char *topic_delim = ",";
// printf("run_pubsub_proxy server receive before\n");
while(shm_recvfrom(shm_socket, (void **)&buf, &size, &key) == 0) {
-printf("run_pubsub_proxy server recvfrom %d after: %s \n", key, buf);
+// printf("run_pubsub_proxy server recvfrom %d after: %s \n", key, buf);
head = ShmModSocket::decode_bus_head(buf);
topics = buf + BUS_HEAD_SIZE;
action = head.action;
- printf("run_pubsub_proxy : %s, %s \n", action, topics);
+ // printf("run_pubsub_proxy : %s\n", action);
if(strcmp(action, "sub") == 0) {
// 璁㈤槄鏀寔澶氫富棰樿闃�
topic = strtok(topics, topic_delim);
-printf("run_pubsub_proxy topic = %s\n", topic);
+// printf("run_pubsub_proxy topic = %s\n", topic);
while(topic) {
_proxy_sub(trim(topic, 0), key);
topic = strtok(NULL, topic_delim);
@@ -283,89 +271,17 @@
}
else if(strcmp(action, "stop") == 0) {
-
+ logger->info( "Stopping Bus...");
free(buf);
break;
} else {
logger->error( "BusServerSocket::run_pubsub_proxy : unrecognized action %s", action);
}
-
free(buf);
}
- logger->info( "Stopping Bus...");
+
shm_sendto(shm_socket, "stop_finished", strlen( "stop_finished") +1, key);
return NULL;
}
-
-
-
-// /**
-// * deprecate
-// * @str "<**sub**>{缁忔祹}"
-// */
-
-// int BusServerSocket::parse_pubsub_topic(char *str, size_t size, char **_action, char **_topic, size_t *head_len ) {
-// char *ptr = str;
-// char *str_end_ptr = str + size;
-// char *action_start_ptr;
-// char *action_end_ptr;
-// size_t action_len = 0;
-
-// char *topic_start_ptr;
-// char *topic_end_ptr;
-// size_t topic_len = 0;
-
-// // if (strlen(identifier) > strlen(str)) {
-// // return 0;
-// // }
-
-// if (strncmp(ptr, ACTION_LIDENTIFIER, strlen(ACTION_LIDENTIFIER)) == 0) {
-// ptr += strlen(ACTION_LIDENTIFIER);
-// action_start_ptr = ptr;
-// while(strncmp(++ptr, ACTION_RIDENTIFIER, strlen(ACTION_RIDENTIFIER)) != 0) {
-// if(ptr >= str_end_ptr) {
-// return 0;
-// }
-// }
-// // printf("%s\n", ptr);
-// action_end_ptr = ptr;
-// action_len = action_end_ptr - action_start_ptr;
-// ptr += strlen(ACTION_RIDENTIFIER);
-// // printf("%s\n", ptr);
-// // printf("%s\n", str_end_ptr-1);
-// if(strncmp(ptr, TOPIC_LIDENTIFIER, strlen(TOPIC_LIDENTIFIER)) == 0 ) {
-// topic_start_ptr = ptr+strlen(TOPIC_LIDENTIFIER);
-
-
-// while(strncmp(++ptr, TOPIC_RIDENTIFIER, strlen(TOPIC_RIDENTIFIER)) != 0) {
-// if(ptr >= str_end_ptr) {
-// return 0;
-// }
-// }
-// topic_end_ptr = ptr;
-// topic_len = topic_end_ptr - topic_start_ptr;
-
-// ptr += strlen(TOPIC_RIDENTIFIER);
-
-// } else {
-// return 0;
-// }
-// } else {
-// return 0;
-// }
-
-// char *topic = (char *)malloc(topic_len+1);
-// strncpy(topic, topic_start_ptr, topic_len);
-// *(topic+topic_len) = '\0';
-// *_topic = topic;
-
-// char *action = (char *)malloc(action_len+1);
-// strncpy(action, action_start_ptr, action_len);
-// *(action+action_len) = '\0';
-// *_action = action;
-// *head_len = ptr-str;
-
-// return 1;
-// }
\ No newline at end of file
diff --git a/test_net_socket/CMakeLists.txt b/test_net_socket/CMakeLists.txt
index a08cf09..574fcaf 100644
--- a/test_net_socket/CMakeLists.txt
+++ b/test_net_socket/CMakeLists.txt
@@ -16,12 +16,12 @@
target_link_libraries(test_net_mod_socket PRIVATE shm_queue ${EXTRA_LIBS} )
-
add_executable(heart_beat heart_beat.cpp ${CMAKE_CURRENT_BINARY_DIR}/heart_beat.sh)
-target_link_libraries(heart_beat PRIVATE shm_queue )
-# target_link_libraries(heart_beat PRIVATE shm_queue ${EXTRA_LIBS} )
+target_link_libraries(heart_beat PRIVATE shm_queue ${EXTRA_LIBS} )
+add_executable(test_bus_stop test_bus_stop.cpp)
+target_link_libraries(test_bus_stop PRIVATE shm_queue ${EXTRA_LIBS} )
--
Gitblit v1.8.0