From fb1289e6d069e1a0f14dd45ba07720f09e90ab56 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期二, 14 七月 2020 18:34:11 +0800
Subject: [PATCH] update

---
 queue/libshm_queue.a     |    0 
 test2/pub                |    0 
 test2/test_queue_wrapper |    0 
 test2/client.c           |    3 
 test2/server             |    0 
 test2/Makefile           |    6 +-
 test2/pub.c              |   62 ++++++++++++++++++++
 test2/sub.c              |   48 ++++++++++++++++
 queue/Makefile           |    5 +
 queue/libshm_queue.so    |    0 
 test2/client             |    0 
 test2/server.c           |    2 
 test2/sub                |    0 
 13 files changed, 118 insertions(+), 8 deletions(-)

diff --git a/queue/Makefile b/queue/Makefile
index c9a9e38..e26b381 100644
--- a/queue/Makefile
+++ b/queue/Makefile
@@ -29,13 +29,14 @@
 
 #static lib
 $(LIBSQUEUE): $(OBJS)
-	$(AR) rv $@ $? $(ROOT)/lib/libusgcommon.a
+	$(AR) rv $@ $?
 	$(RANLIB) $@
 
 #dynamic lib
 $(DLIBSQUEUE): $(SOURCES)
 	rm -f *.o
-	$(CC) -fPIC -shared $(CFLAGS) $^ -o $@ $(LDFLAGS) $(ROOT)/lib/libusgcommon.so
+	$(CC) -fPIC -shared $(CFLAGS) $^ -o $@ $(LDFLAGS)
+	#$(CC) -fPIC -shared $(CFLAGS) $(LDFLAGS)  -o $@ $^ -Wl,--whole-archive $(ROOT)/lib/libusgcommon.a -Wl,--no-whole-archive 
 
 
 #PREFIX is environment variable, but if it is not set, then set default value
diff --git a/queue/libshm_queue.a b/queue/libshm_queue.a
new file mode 100644
index 0000000..873f630
--- /dev/null
+++ b/queue/libshm_queue.a
Binary files differ
diff --git a/queue/libshm_queue.so b/queue/libshm_queue.so
index d050417..b0908e5 100755
--- a/queue/libshm_queue.so
+++ b/queue/libshm_queue.so
Binary files differ
diff --git a/test2/Makefile b/test2/Makefile
index 54c80cb..872f05d 100644
--- a/test2/Makefile
+++ b/test2/Makefile
@@ -2,11 +2,11 @@
 # Makefile for common library.
 #
 ROOT=..
-LDLIBS+=-Wl,-rpath=$(ROOT)/queue
+LDLIBS+=-Wl,-rpath=$(ROOT)/queue:$(ROOT)/lib
 # 寮�婧愬伐鍏峰寘璺緞
 LDDIR += -L$(ROOT)/queue
 # 寮�婧愬伐鍏峰寘
-LDLIBS += -lshm_queue -lpthread
+LDLIBS += -lshm_queue -lusgcommon -lpthread
 
 INCLUDE += -I$(ROOT)/queue/ -I$(ROOT)/queue/include
 
@@ -14,7 +14,7 @@
 include $(ROOT)/Make.defines.$(PLATFORM)
 
 
-PROGS =	test_queue_wrapper server client
+PROGS =	test_queue_wrapper server client pub sub
 
 
 build: $(PROGS)
diff --git a/test2/client b/test2/client
index 2e70d5e..9dab546 100755
--- a/test2/client
+++ b/test2/client
Binary files differ
diff --git a/test2/client.c b/test2/client.c
index 2d4746d..501c0fd 100644
--- a/test2/client.c
+++ b/test2/client.c
@@ -1,6 +1,5 @@
 #include "shm_queue_wrapper.h"
-#include "mm.h"
- 
+
 typedef struct msg_t
 {
 	int key;
diff --git a/test2/pub b/test2/pub
new file mode 100755
index 0000000..7ded9a2
--- /dev/null
+++ b/test2/pub
Binary files differ
diff --git a/test2/pub.c b/test2/pub.c
new file mode 100644
index 0000000..35f1c16
--- /dev/null
+++ b/test2/pub.c
@@ -0,0 +1,62 @@
+#include "shm_queue_wrapper.h"
+
+ 
+typedef struct msg_t
+{
+	int key;
+	char buf[100];
+	
+} msg_t;
+
+
+static void * remote_queues[100];
+static int remote_queues_len = 0;
+
+void *pub(void *) {
+	msg_t send_msg;
+	send_msg.key = 1;
+	while(true) {
+		for(int i = 0; i < remote_queues_len; i++ ) {
+			sprintf(send_msg.buf, "浠婃棩澶存潯脳脳脳脳");
+	    	shmqueue_push(remote_queues[i], (void *)&send_msg, sizeof(send_msg));
+		}
+		sleep(2);
+	}
+}
+
+void server() {
+ 	void * msg;
+ 	int msg_size;
+ 	
+ 	int key = 1;
+	size_t qsize = 16;
+	void * local_queue = shmqueue_create( &key, qsize);
+	
+
+	pthread_t tid;
+ 	pthread_create(&tid, NULL, pub, NULL);
+	
+	while(shmqueue_pop(local_queue, &msg, &msg_size) ) {
+		void * remote_queue = shmqueue_attach(((msg_t *)msg)->key);
+		remote_queues[remote_queues_len++] = remote_queue;
+	    printf("鏀跺埌璁㈤槄璇锋眰", ((msg_t *)msg)->buf);
+	   
+	   
+	    // shmqueue_drop(remote_queue);
+	   // cout <<  item.pic << endl;
+	    // i++;
+	}
+
+	//閿�姣侀槦鍒�
+	shmqueue_drop(local_queue);
+}
+
+ 
+int main () {
+	shm_init(512);
+	server();
+
+	//鏁翠釜杩涚▼閫�鍑烘椂闇�瑕佹墽琛岃繖涓柟娉曪紝璇ユ柟娉曢鍏堜細妫�鏌ユ槸鍚﹁繕鏈夊叾浠栬繘绋嬪湪浣跨敤璇ュ叡浜唴瀛橈紝濡傛灉杩樻湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ氨鍙槸detach,濡傛灉娌℃湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ垯閿�姣佹暣鍧楀唴瀛樸��
+	shm_destroy();
+	return 0;
+}
\ No newline at end of file
diff --git a/test2/server b/test2/server
index de8a68d..d1b9095 100755
--- a/test2/server
+++ b/test2/server
Binary files differ
diff --git a/test2/server.c b/test2/server.c
index f3fa3b5..d969c83 100644
--- a/test2/server.c
+++ b/test2/server.c
@@ -1,5 +1,5 @@
 #include "shm_queue_wrapper.h"
-#include "mm.h"
+
  
 typedef struct msg_t
 {
diff --git a/test2/sub b/test2/sub
new file mode 100755
index 0000000..ba91707
--- /dev/null
+++ b/test2/sub
Binary files differ
diff --git a/test2/sub.c b/test2/sub.c
new file mode 100644
index 0000000..d90928f
--- /dev/null
+++ b/test2/sub.c
@@ -0,0 +1,48 @@
+#include "shm_queue_wrapper.h"
+
+typedef struct msg_t
+{
+	int key;
+	char buf[100];
+	
+} msg_t;
+
+void client() {
+	int key = -1;
+	size_t qsize = 16;
+	void * remote_queue = shmqueue_attach( 1);
+	void * local_queue = shmqueue_create( &key, qsize);
+	// message_t item;
+	msg_t msg;
+	msg.key = key;
+
+	void * rec_msg;
+	int rec_msg_size;
+
+	sprintf(msg.buf, "鎴戣璁㈤槄浠婃棩澶存潯");
+	shmqueue_push(remote_queue, (void *)&msg, sizeof(msg));
+	//鍏ラ槦
+	while(true) {
+	  
+	  //printf("send: %s\n",  msg.buf);
+	  shmqueue_pop(local_queue, &rec_msg, &rec_msg_size);
+	  printf("鏀跺埌璁㈤槄娑堟伅: %s\n",  ((msg_t*)rec_msg)->buf);
+	  free(rec_msg);
+
+	  
+	}
+	 
+	//閿�姣侀槦鍒�
+	shmqueue_drop(local_queue);
+	shmqueue_drop(remote_queue);
+}
+
+ 
+int main () {
+	shm_init(512);
+	client();
+
+	//鏁翠釜杩涚▼閫�鍑烘椂闇�瑕佹墽琛岃繖涓柟娉曪紝璇ユ柟娉曢鍏堜細妫�鏌ユ槸鍚﹁繕鏈夊叾浠栬繘绋嬪湪浣跨敤璇ュ叡浜唴瀛橈紝濡傛灉杩樻湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ氨鍙槸detach,濡傛灉娌℃湁鍏朵粬杩涚▼鍦ㄤ娇鐢ㄥ垯閿�姣佹暣鍧楀唴瀛樸��
+	shm_destroy();
+	return 0;
+}
\ No newline at end of file
diff --git a/test2/test_queue_wrapper b/test2/test_queue_wrapper
index 1840703..c37f037 100755
--- a/test2/test_queue_wrapper
+++ b/test2/test_queue_wrapper
Binary files differ

--
Gitblit v1.8.0