From 758438289fc45829a8f6cef1b42afed0a1a8cb60 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期三, 03 二月 2021 15:59:58 +0800 Subject: [PATCH] uuid msg --- test_net_socket/test_net_mod_socket.cpp | 47 ++++++++++++++++++++++------------------------- 1 files changed, 22 insertions(+), 25 deletions(-) diff --git a/test_net_socket/test_net_mod_socket.cpp b/test_net_socket/test_net_mod_socket.cpp index 79f102a..568392d 100644 --- a/test_net_socket/test_net_mod_socket.cpp +++ b/test_net_socket/test_net_mod_socket.cpp @@ -133,21 +133,32 @@ -void start_reply(int key) { +void start_reply(int mkey) { printf("start reply\n"); void *ser = net_mod_socket_open(); - net_mod_socket_bind(ser, key); - int size; + net_mod_socket_bind(ser, mkey); + int recvsize; void *recvbuf; char sendbuf[512]; int rv; - int remote_port; - while ( (rv = net_mod_socket_recvfrom(ser, &recvbuf, &size, &remote_port) ) == 0) { - // printf( "server: RECEIVED REQUEST FROM PORT %d NAME %s\n", remote_port, recvbuf); + int key; + while(true) { + rv = net_mod_socket_recvandsend_timeout(ser, &recvbuf, &recvsize, &key, [&](void ** buf, int *size){ + printf( "server: RECEIVED REQUEST FROM %d : %s\n", key, recvbuf); sprintf(sendbuf, "%d RECEIVED %s", net_mod_socket_get_key(ser), (char *)recvbuf); - net_mod_socket_sendto(ser, sendbuf, strlen(sendbuf) + 1, remote_port); + // buf 鍜� size鏄繑鍥炲�� + *buf = sendbuf; + *size = strlen(sendbuf) + 1; free(recvbuf); + return; + }, 0, 2000000 ); } + // while ( (rv = net_mod_socket_recvfrom(ser, &recvbuf, &size, &key) ) == 0) { + // // printf( "server: RECEIVED REQUEST FROM %d NAME %s\n", key, recvbuf); + // sprintf(sendbuf, "%d RECEIVED %s", net_mod_socket_get_key(ser), (char *)recvbuf); + // net_mod_socket_sendto(ser, sendbuf, strlen(sendbuf) + 1, key); + // free(recvbuf); + // } } // 浜や簰寮忓鎴风 @@ -194,7 +205,7 @@ if (fgets(content, MAXLINE, stdin) != NULL) { // 鏀跺埌娑堟伅鐨勮妭鐐瑰嵆浣挎病鏈夊搴旂殑淇℃伅锛� 涔熻鍥炲涓�涓〃绀烘棤鐨勬秷鎭�,鍚﹀垯浼氫竴鐩寸瓑寰� // n = net_mod_socket_sendandrecv(client, node_arr, node_arr_size, content, strlen(content), &recv_arr, &recv_arr_size); - n = net_mod_socket_sendandrecv_timeout(client, node_arr, node_arr_size, content, strlen(content), &recv_arr, &recv_arr_size, 1000); + n = net_mod_socket_sendandrecv_timeout(client, node_arr, node_arr_size, content, strlen(content), &recv_arr, &recv_arr_size, 1); printf(" %d nodes reply\n", n); for(i=0; i<recv_arr_size; i++) { printf("reply from (host:%s, port: %d, key:%d) >> %s\n", @@ -272,11 +283,11 @@ sprintf(sendbuf, hello_format, net_mod_socket_get_key(client), l); // fprintf(fp, "requst:%s\n", sendbuf); // n = net_mod_socket_sendandrecv(client, node_arr, node_arr_size, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size); - n = net_mod_socket_sendandrecv_timeout(client, targ->node, 1, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 1000); + n = net_mod_socket_sendandrecv_timeout(client, targ->node, 1, sendbuf, strlen(sendbuf) + 1, &recv_arr, &recv_arr_size, 1); printf("%d: send %d nodes\n", l, n); for(j=0; j < recv_arr_size; j++) { - fprintf(fp, "%d send '%s' to %d. received from (host=%s, port= %d, key=%d) '%s'\n", + fprintf(stdout, "%d send '%s' to %d. received from (host=%s, port= %d, key=%d) '%s'\n", net_mod_socket_get_key(client), sendbuf, targ->node->key, @@ -386,21 +397,7 @@ ); - // printf( "%d send '%s' to %d. received from (host=%s, port= %d, key=%d) '%s'\n", - // net_mod_socket_get_key(client), - // sendbuf, - // targ->node->key, - // recv_arr[j].host, - // recv_arr[j].port, - // recv_arr[j].key, - // recv_arr[j].content - // ); - - - // assert(sscanf((const char *)recv_arr[j].content, reply_format, &rkey, &lkey, &rl) == 3); - // assert(targ->node->key == rkey); - // assert(net_mod_socket_get_key(client) == lkey); - // assert(rl == l); + assert(sscanf((const char *)recv_arr[j].content, reply_format, &remoteKey, &retPid, &retl) == 3); assert(retPid == pid); -- Gitblit v1.8.0