From 78c0c6d8cf0869f49323840517604387eaa7d9e5 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期一, 10 八月 2020 15:22:47 +0800
Subject: [PATCH] update
---
test_socket/dgram_mod_req_rep.c | 35 +++++++++++++++++++++++++++--------
1 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/test_socket/dgram_mod_req_rep.c b/test_socket/dgram_mod_req_rep.c
index 119b497..9a021a1 100644
--- a/test_socket/dgram_mod_req_rep.c
+++ b/test_socket/dgram_mod_req_rep.c
@@ -19,7 +19,7 @@
}Targ;
-LockFreeQueue<task_t, DM_Allocator> task_queue(100);
+LockFreeQueue<task_t, DM_Allocator> task_queue(128);
void *worker(void *socket) {
@@ -44,7 +44,7 @@
}
void server(int port) {
- void *socket = dgram_mod_open_socket(REQ_REP);
+ void *socket = dgram_mod_open_socket();
dgram_mod_bind(socket, port);
initThreadPool(socket);
@@ -58,13 +58,27 @@
}
void client(int port) {
- void *socket = dgram_mod_open_socket(REQ_REP);
+ void *socket = dgram_mod_open_socket();
int size;
void *recvbuf;
char sendbuf[512];
while (true) {
printf("request: ");
scanf("%s", sendbuf);
+ dgram_mod_sendandrecv(socket, sendbuf, strlen(sendbuf) + 1, port, &recvbuf, &size);
+ printf("reply: %s\n", (char *)recvbuf);
+ free(recvbuf);
+ }
+ dgram_mod_close_socket(socket);
+}
+
+void client2(int port) {
+ void *socket = dgram_mod_open_socket();
+ int size;
+ void *recvbuf;
+ char sendbuf[512];
+ while (true) {
+ sprintf(sendbuf, "hello\n" );
dgram_mod_sendandrecv(socket, sendbuf, strlen(sendbuf) + 1, port, &recvbuf, &size);
printf("reply: %s\n", (char *)recvbuf);
free(recvbuf);
@@ -80,10 +94,10 @@
char sendbuf[512];
int scale = 100000;
int i;
- void *socket = dgram_mod_open_socket(REQ_REP);
+ void *socket = dgram_mod_open_socket();
char filename[512];
- sprintf(filename, "test%d.txt", targ->id);
+ sprintf(filename, "test%d.tmp", targ->id);
FILE *fp = NULL;
fp = fopen(filename, "w+");
@@ -146,11 +160,16 @@
port = atoi(argv[2]);
if (strcmp("server", argv[1]) == 0) {
+ // int temp = shm_alloc_key();
+ // printf("tmp=%d\n", temp);
server(port);
- }
-
- if (strcmp("client", argv[1]) == 0)
+ } else if (strcmp("mclient", argv[1]) == 0) {
startClients(port);
+ } else if (strcmp("client", argv[1]) == 0) {
+ client(port);
+ } else {
+ printf("input invalidate arguments\n");
+ }
return 0;
--
Gitblit v1.8.0