From 695953440565103964e816e7326c66f3d171c3e0 Mon Sep 17 00:00:00 2001
From: jimi-wzq <wangzhengquan85@gmail.com>
Date: 星期六, 01 八月 2020 10:48:18 +0800
Subject: [PATCH] fix conflict

---
 .gitignore                            |    2 
 src/queue/include/hashtable.h         |    2 
 src/queue/include/shm_mm.h            |    2 +
 test_socket/dgram_mod_bus.c           |   16 ++++----
 src/socket/dgram_mod_socket.c         |   17 +++++---
 src/queue/hashtable.c                 |    7 +--
 test/test.c                           |   12 -----
 src/socket/include/dgram_mod_socket.h |    5 ++
 demo/Makefile                         |    1 
 src/queue/shm_mm.c                    |    5 ++
 10 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/.gitignore b/.gitignore
index 608689c..9900498 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,7 +38,7 @@
 *.tar
 *.tar.gz
 .vscode/
-.idea
+.idea/
 
 build/
 *.tmp
diff --git a/demo/Makefile b/demo/Makefile
index a8b38ff..8fbd78f 100644
--- a/demo/Makefile
+++ b/demo/Makefile
@@ -15,6 +15,7 @@
 
 
 PROGS = dgram_mod_req_rep dgram_mod_survey dgram_mod_bus
+ 
 
 
 build: $(PROGS)
diff --git a/src/queue/hashtable.c b/src/queue/hashtable.c
index eaa3ca6..a7a82ed 100755
--- a/src/queue/hashtable.c
+++ b/src/queue/hashtable.c
@@ -231,7 +231,7 @@
 
 
 
-static inline void _hashtable_foreach(hashtable_t *hashtable, std::function<void(int, void *)> cb) {
+static inline void _hashtable_foreach(hashtable_t *hashtable, std::function<void(int, void *)>  cb) {
   tailq_entry_t *item;
   for (int i = 0; i < MAPSIZE; i++) {
     tailq_header_t *my_tailq_head = hashtable->array[i] ;
@@ -247,7 +247,7 @@
 }
 
 
-void hashtable_foreach(hashtable_t *hashtable, hashtable_foreach_cb cb) {
+void hashtable_foreach(hashtable_t *hashtable,  std::function<void(int, void *)>  cb) {
    SemUtil::dec(hashtable->mutex);
    hashtable->readcnt++;
    if (hashtable->readcnt == 1) {
@@ -273,7 +273,6 @@
    SemUtil::inc(hashtable->mutex);
 
 }
-
 
 
 std::set<int> * hashtable_keyset(hashtable_t *hashtable) {
@@ -306,5 +305,3 @@
   SemUtil::inc(hashtable->wlock);
   return key;
 }
-
-
diff --git a/src/queue/include/hashtable.h b/src/queue/include/hashtable.h
index c1fba98..b8edaa3 100755
--- a/src/queue/include/hashtable.h
+++ b/src/queue/include/hashtable.h
@@ -31,7 +31,7 @@
  * });
  * 
 */
-void hashtable_foreach(hashtable_t *hashtable, hashtable_foreach_cb cb);
+void hashtable_foreach(hashtable_t *hashtable, std::function<void(int, void *)>  cb);
 
 // void hashtable_printall(hashtable_t *hashtable);
 
diff --git a/src/queue/include/shm_mm.h b/src/queue/include/shm_mm.h
index 8aeb202..ec094ac 100644
--- a/src/queue/include/shm_mm.h
+++ b/src/queue/include/shm_mm.h
@@ -18,6 +18,8 @@
  */
 void shm_destroy();
 
+int shm_alloc_key();
+
 
 #ifdef __cplusplus
 }
diff --git a/src/queue/shm_mm.c b/src/queue/shm_mm.c
index 6eeae1a..c5009a9 100644
--- a/src/queue/shm_mm.c
+++ b/src/queue/shm_mm.c
@@ -10,4 +10,7 @@
 	mem_pool_destroy();
 }
 
-
+int shm_alloc_key() {
+	hashtable_t *hashtable = mm_get_hashtable();
+	return  hashtable_alloc_key(hashtable);
+}
diff --git a/src/socket/dgram_mod_socket.c b/src/socket/dgram_mod_socket.c
index f58e4bb..4c79df2 100644
--- a/src/socket/dgram_mod_socket.c
+++ b/src/socket/dgram_mod_socket.c
@@ -58,12 +58,15 @@
 	if(topic_sub_map != NULL) {
 		for (map_iter = topic_sub_map->begin(); map_iter != topic_sub_map->end(); map_iter++) {
 			subscripter_set = map_iter->second;
-			delete subscripter_set;
+			subscripter_set->clear();
+			mm_free((void *)subscripter_set);
+			//delete subscripter_set;
+			// printf("=============delete subscripter_set\n");
 		}
 		topic_sub_map->clear();
 		mem_pool_free_by_key(BUS_MAP_KEY);
 	}
-	
+	// printf("=============close socket\n");
 	shm_close_socket(socket->shm_socket);
 	free(_socket);
 }
@@ -121,8 +124,8 @@
 int  dgram_mod_start_bus(void * _socket) {
 	dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket;
 	socket->mod = BUS;
-// printf("mem_pool_malloc_by_key before\n");
 	socket->topic_sub_map =	mem_pool_attach<SHMTopicSubMap>(BUS_MAP_KEY);
+ 
 	run_pubsub_proxy(socket);
 	// pthread_t tid;
 	// pthread_create(&tid, NULL, run_accept_sub_request, _socket);
@@ -198,12 +201,12 @@
 		subscripter_set = map_iter->second;
 		for(set_iter = subscripter_set->begin(); set_iter != subscripter_set->end(); set_iter++) {
 			send_port = *set_iter;
- printf("_proxy_pub send before %d \n", send_port);
+ // printf("_proxy_pub send before %d \n", send_port);
 			if (shm_sendto(socket->shm_socket, buf+head_len, size-head_len, send_port, &timeout) !=0 ) {
 				//瀵规柟宸插叧闂殑杩炴帴鏀惧埌寰呭垹闄ら槦鍒楅噷銆傚鏋滅洿鎺ュ垹闄や細璁﹊ter鎸囬拡鍑虹幇閿欎贡
 				subscripter_to_del.push_back(send_port);
 			} else {
-printf("_proxy_pub send after: %d \n", send_port);
+// printf("_proxy_pub send after: %d \n", send_port);
 			}
 
 			
@@ -229,9 +232,9 @@
 	size_t head_len;
 
 	const char *topic_delim = ",";
-printf("run_pubsub_proxy server receive before\n");
+// printf("run_pubsub_proxy server receive before\n");
 	while(shm_recvfrom(socket->shm_socket, (void **)&buf, &size, &port) == 0) {
-printf("run_pubsub_proxy server recv after: %s \n", buf);
+// printf("run_pubsub_proxy server recv after: %s \n", buf);
 		if(parse_pubsub_topic(buf, size, &action, &topics, &head_len)) {
 			if(strcmp(action, "sub") == 0) {
 				// 璁㈤槄鏀寔澶氫富棰樿闃�
diff --git a/src/socket/include/dgram_mod_socket.h b/src/socket/include/dgram_mod_socket.h
index 1c12e53..21d0d20 100644
--- a/src/socket/include/dgram_mod_socket.h
+++ b/src/socket/include/dgram_mod_socket.h
@@ -25,7 +25,10 @@
 */
 int dgram_mod_bind(void * _socket, int port);
 
-
+/**
+ * 寮哄埗缁戝畾绔彛鍒皊ocket, 閫傜敤浜庣▼搴忛潪姝e父鍏抽棴鐨勬儏鍐典笅锛岄噸鍚▼搴忕粦瀹氬師鏉ヨ繕娌¢噴鏀剧殑key
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
 int dgram_mod_force_bind(void * _socket, int port);
 /**
  * 鍙戦�佷俊鎭�
diff --git a/test/test.c b/test/test.c
index 0aaa68e..b978ef2 100644
--- a/test/test.c
+++ b/test/test.c
@@ -1,15 +1,5 @@
 #include "usg_common.h"
 #include "usg_typedef.h"
-
-int test(char *src, int size) {
-	int i = strlen(src);
-	char dest[size];
-	strncpy(dest, src, size);
-	puts(dest);
-	return i;
-}
+ 
 int main() {
-	char *str = "hello";
-	int r = test(str, strlen(str));
-	printf("%d\n", r);
 }
\ No newline at end of file
diff --git a/test_socket/dgram_mod_bus.c b/test_socket/dgram_mod_bus.c
index 01a5ac6..70f09c4 100644
--- a/test_socket/dgram_mod_bus.c
+++ b/test_socket/dgram_mod_bus.c
@@ -10,15 +10,15 @@
 }
 
 void server(int port, bool restart) {
- // signal(SIGINT,  sigint_handler);
+  signal(SIGINT,  sigint_handler);
   server_socket = dgram_mod_open_socket();
-  dgram_mod_force_bind(server_socket, port);
-  
-  // if(restart) {
-   
-  // } else {
-  //   // dgram_mod_bind(server_socket, port);
-  // }
+
+
+  if(restart) {
+    dgram_mod_force_bind(server_socket, port);
+  } else {
+     dgram_mod_bind(server_socket, port);
+  }
  
    
   dgram_mod_start_bus(server_socket);

--
Gitblit v1.8.0