From 9052085027b66a7a6e69405834e36981b201618b Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期一, 20 七月 2020 11:34:25 +0800
Subject: [PATCH] update
---
test/communication.c | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/test/communication.c b/test/communication.c
index 16a9b05..eae99d4 100644
--- a/test/communication.c
+++ b/test/communication.c
@@ -1,4 +1,6 @@
-#include "socket.h"
+#include "shm_socket.h"
+#include "usg_common.h"
+#include "shm_mm.h"
typedef struct Targ {
int port;
int id;
@@ -14,7 +16,7 @@
sprintf(sendbuf, "SERVER RECEIVED: %s", recvbuf);
puts(sendbuf);
shm_send(socket, sendbuf, strlen(sendbuf)+1);
- shm_free(recvbuf);
+ free(recvbuf);
}
shm_close_socket(socket);
}
@@ -22,12 +24,12 @@
void server(int port) {
pthread_t tid;
shm_socket_t *socket = shm_open_socket();
- shm_bind(socket, port);
+ shm_socket_bind(socket, port);
shm_listen(socket);
shm_socket_t *client_socket;
while(true) {
client_socket = shm_accept(socket);
-printf("server messageQueue = %p\n", client_socket->messageQueue);
+// printf("server messageQueue = %p\n", client_socket->messageQueue);
pthread_create(&tid, NULL, precess_client , (void *)client_socket);
}
@@ -46,7 +48,7 @@
shm_send(socket, sendbuf, strlen(sendbuf)+1) ;
shm_recv(socket, &recvbuf, &size);
printf("reply: %s\n", (char *)recvbuf);
- shm_free(recvbuf);
+ free(recvbuf);
}
shm_close_socket(socket);
@@ -56,10 +58,11 @@
int size;
void *recvbuf;
+ printf("requst:%s\n", sendbuf);
shm_send(socket, sendbuf, strlen(sendbuf)+1) ;
shm_recv(socket, &recvbuf, &size);
printf("reply: %s\n", (char *)recvbuf);
- shm_free(recvbuf);
+ free(recvbuf);
}
@@ -103,10 +106,10 @@
int scale = 100000;
int i;
shm_socket_t *socket = shm_open_socket();
-
shm_connect(socket, port);
for( i = 0; i<scale; i++) {
- sprintf(sendbuf, "processor(%d) %d", targ->id, i);
+ sprintf(sendbuf, "thread(%d) %d", targ->id, i);
+
client_send(socket, sendbuf);
}
shm_close_socket(socket);
@@ -115,7 +118,7 @@
void multyThreadClient(int port) {
- int status, i = 0, processors = 2;
+ int status, i = 0, processors = 4;
void *res[processors];
Targ *targs= (Targ*)calloc(processors, sizeof(Targ));
pthread_t tids[processors];
@@ -157,7 +160,8 @@
if (strcmp("mclient", argv[1]) == 0)
multyThreadClient(port);
- shm_destroy();
+
+ shm_destroy();
// fprintf(stderr, "Usage: reqrep %s|%s <URL> ...\n", "server", "client");
return 0;
}
\ No newline at end of file
--
Gitblit v1.8.0