From a1dfe6a4dcc21a04b4ac03de39ab1c829a9be1ae Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期一, 12 十月 2020 18:15:35 +0800 Subject: [PATCH] req_rep --- test_net_socket/net_mod_req_rep.sh | 40 ++++++++++++++++++++ test/is_little_endian.c | 40 ++++++++++++++++++++ 2 files changed, 80 insertions(+), 0 deletions(-) diff --git a/test/is_little_endian.c b/test/is_little_endian.c new file mode 100644 index 0000000..bea3d53 --- /dev/null +++ b/test/is_little_endian.c @@ -0,0 +1,40 @@ +/* + * is-little-endian.c + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <inttypes.h> +#include <byteswap.h> + +typedef unsigned char* byte_pointer; + +int is_little_endian() { + int test_num = 0xff; + byte_pointer byte_start = (byte_pointer) &test_num; + + if (byte_start[0] == 0xff) { + return 1; + } + return 0; +} + + + int + main(int argc, char *argv[]) + { + uint64_t x; + + if (argc != 2) { + fprintf(stderr, "Usage: %s <num>\n", argv[0]); + exit(EXIT_FAILURE); + } + + x = strtoul(argv[1], NULL, 0); + printf("0x%" PRIx64 " ==> 0x%" PRIx64 "\n", x, bswap_64(x)); + + exit(EXIT_SUCCESS); + } + + diff --git a/test_net_socket/net_mod_req_rep.sh b/test_net_socket/net_mod_req_rep.sh new file mode 100755 index 0000000..7661f88 --- /dev/null +++ b/test_net_socket/net_mod_req_rep.sh @@ -0,0 +1,40 @@ +function server() { + ipcrm -a + ./dgram_mod_req_rep server 11 & + ./dgram_mod_req_rep server 12 & + ./dgram_mod_req_rep server 13 & + ./dgram_mod_req_rep server 14 & + + ./net_mod_req_rep server 5000 & + +} + +function client() { + ./net_mod_req_rep client 5000 +} + +function clean() { + ps -ef | grep -e "dgram_mod_req_rep" -e "net_mod_req_rep" | awk '{print $2}' | xargs -i kill -9 {} + ipcrm -a +} + +case ${1} in + "server") + server + ;; + "client") + client + ;; + "clean") + clean + ;; + "") + clean + server + client + ;; + *) + echo "error input" + exit 1 + ;; +esac -- Gitblit v1.8.0