From f52f2c2828047c2f30d30fc1fe2b54d8db146d49 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期四, 25 二月 2021 15:56:35 +0800
Subject: [PATCH] update
---
test_net_socket/shm_util.cpp | 50 ++++++++++++++++++++++++++++++++++++++------------
src/socket/shm_socket.cpp | 2 +-
2 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/src/socket/shm_socket.cpp b/src/socket/shm_socket.cpp
index 38bbd8f..2b3e626 100644
--- a/src/socket/shm_socket.cpp
+++ b/src/socket/shm_socket.cpp
@@ -52,7 +52,7 @@
return queue;
} else if(force) {
hashtable_unlock(hashtable);
- return (LockFreeQueue<shm_packet_t> *) queue;
+ return (LockFreeQueue<shm_packet_t> *) tmp_ptr;
}
hashtable_unlock(hashtable);
diff --git a/test_net_socket/shm_util.cpp b/test_net_socket/shm_util.cpp
index c441930..549e29f 100644
--- a/test_net_socket/shm_util.cpp
+++ b/test_net_socket/shm_util.cpp
@@ -21,6 +21,8 @@
struct argument_t {
bool interactive;
+ bool force;
+ int bind;
int port;
int key;
char *sendlist;
@@ -147,13 +149,18 @@
}
}
-void start_reply(int mkey) {
+void start_recvfrom(int mkey, bool force) {
logger->debug("start reply\n");
signal(SIGINT, stop_replyserver_handler);
signal(SIGTERM, stop_replyserver_handler);
serverSockt = net_mod_socket_open();
- net_mod_socket_bind(serverSockt, mkey);
+ if(force) {
+ net_mod_socket_force_bind(serverSockt, mkey);
+ } else {
+ net_mod_socket_bind(serverSockt, mkey);
+ }
+
int rv = 0 ;
while( true) {
@@ -163,6 +170,9 @@
if(rv == EBUS_STOPED) {
logger->debug("Stopping\n");
break;
+ } else if(rv == EBUS_KEY_INUSED){
+ printf("key宸茬粡琚崰鐢╘n");
+ exit(1);
}
logger->debug("net_mod_socket_recvandsend error.%s\n", bus_strerror(rv));
@@ -528,14 +538,18 @@
void list () {
LockFreeQueue<shm_packet_t> * mqueue;
hashtable_t *hashtable = mm_get_hashtable();
- printf("%10s \t %10s\n", "KEY", "LENGTH");
+ printf("%10s \t %-10s \t %10s\n", "KEY", "LENGTH", "STATUS");
hashtable_foreach(hashtable, [&](int key, void * value){
if(key >= 100 ) {
mqueue = (LockFreeQueue<shm_packet_t> *)hashtable_get(hashtable, key);
- printf("%d\n", key);
- printf("%10d \t %10d\n", key, mqueue->size());
+ if((long)mqueue == 0x1) {
+ printf("%10d \t %-10s\n", key, "Not In Used");
+ } else {
+ printf("%10d \t %-10d\n", key, mqueue->size());
+ }
+
} else {
- printf("%10d \t %10s\n", key, "");
+ printf("%10d\n", key);
}
});
@@ -571,7 +585,7 @@
net_node_t node_arr[] = {NULL, 0, key};
void * client = net_mod_socket_open();
- n = net_mod_socket_sendandrecv_timeout(client, node_arr, 1, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 5);
+ n = net_mod_socket_sendandrecv_timeout(client, node_arr, 1, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 5000);
if(n == 0) {
printf("send failed\n");
return;
@@ -617,6 +631,7 @@
fpe("# remove key 1001\n");
fpe("./shm_util rm 1001\n");
fpe("./shm_util info 1002\n");
+ fpe("./shm_util recvfrom --bind 1002 [--force]\n")
fpe("\n");
}
@@ -648,6 +663,8 @@
{"key", required_argument, 0, 'k'},
{"port", required_argument, 0, 'p'},
{"interactive", no_argument, 0, 'i'},
+ {"force", no_argument, 0, 'f'},
+ {"bind", required_argument, (int *)mopt.bind, 0},
{"sendlist", required_argument, (int *)mopt.sendlist, 0},
{"publist", required_argument, (int *)mopt.publist, 0},
{0, 0, 0, 0}
@@ -658,7 +675,7 @@
{
- c = getopt_long (argc, argv, "+f:k:p:i", long_options, &option_index);
+ c = getopt_long (argc, argv, "+fk:p:i", long_options, &option_index);
/* Detect the end of the options. */
if (c == -1)
@@ -677,6 +694,9 @@
else if(strcmp(long_options[option_index].name, "publist") == 0) {
mopt.publist = optarg;
}
+ else if(strcmp(long_options[option_index].name, "bind") == 0) {
+ mopt.bind = atoi(optarg);
+ }
else {
printf ("option %s", long_options[option_index].name);
if (optarg)
@@ -692,6 +712,10 @@
case 'i':
mopt.interactive = true;
+ break;
+
+ case 'f':
+ mopt.force = true;
break;
case 'p':
@@ -781,7 +805,7 @@
int i;
char *prog;
char * fun;
- argument_t opt;
+ argument_t opt = {};
shm_mm_wrapper_init(512);
@@ -853,13 +877,15 @@
}
- else if (strcmp("start_reply", fun) == 0) {
+ else if (strcmp("recvfrom", fun) == 0) {
opt = parse_args(argc, argv);
- if(opt.key == 0) {
+ if(opt.bind == 0) {
usage(argv[0]);
exit(1);
+ } else {
+ start_recvfrom(opt.bind, opt.force);
}
- start_reply(opt.key);
+
}
else if (strcmp("start_net_client", fun) == 0) {
opt = parse_args(argc, argv);
--
Gitblit v1.8.0