做食品的采购员常用网站网站之前没备案

web/2025/10/7 16:51:47/文章来源:
做食品的采购员常用网站,网站之前没备案,新闻资讯到底是哪个公司的,木方东莞网站建设技术支持RDMA编程实践 本文描述了RDMA编程过程中的SEND-RECEIVE双边原语的代码实现。包含多个版本#xff0c;1、client向server发送消息#xff0c;server回复client收到消息(ACK)#xff0c;然后两边断开连接。2、server端循环等待客户端建立连接#xff0c;client发送一次消息后…RDMA编程实践 本文描述了RDMA编程过程中的SEND-RECEIVE双边原语的代码实现。包含多个版本1、client向server发送消息server回复client收到消息(ACK)然后两边断开连接。2、server端循环等待客户端建立连接client发送一次消息后双方断开连接。3、server端循环等待客户端建立连接一旦建立client端可以一直向server端发送消息直到发送消息为disconnectserver和client断开链接但是server此时仍然可以等待别的client发送消息。 代码基于代码基于send-receive样例实现。关于代码注释可以参考代码解释 Makefile文件、会编译当前目录下的所有.c文件 .PHONY: all cleanCC : gcc CFLAGS : -Wall -g LDLIBS : -lrdmacm -libverbs -lpthread -gSRCS : $(wildcard *.c) APPS : $(SRCS:.c)all: $(APPS)%: %.c$(CC) $(CFLAGS) $ -o $ $(LDLIBS)clean:rm -f $(APPS)version1 客户端-服务端消息一次传递 在这个阶段我们希望能实现下面这样一个场景。client与server端相连接client端能够发送一条消息给serverserver收到该条消息之后恢复一条消息给client端表示我已经确认收到。之后两者断开连接。 代码 // client1.c #include stdio.h #include stdlib.h #include string.h #include netdb.h #include errno.h #include getopt.h #include rdma/rdma_cma.h #include rdma/rdma_verbs.hstatic const char *server 10.10.10.1; static const char *port 7471;static struct rdma_cm_id *id; static struct ibv_mr *mr, *send_mr; static int send_flags; static uint8_t send_msg[16]; static uint8_t recv_msg[16];static int run(void) {struct rdma_addrinfo hints, *res;struct ibv_qp_init_attr attr;struct ibv_wc wc;int ret;memset(hints, 0, sizeof hints);hints.ai_port_space RDMA_PS_TCP;ret rdma_getaddrinfo(server, port, hints, res);if (ret) {printf(rdma_getaddrinfo: %s\n, gai_strerror(ret));goto out;}memset(attr, 0, sizeof attr);attr.cap.max_send_wr attr.cap.max_recv_wr 1;attr.cap.max_send_sge attr.cap.max_recv_sge 1;attr.cap.max_inline_data 16;attr.qp_context id;attr.sq_sig_all 1;ret rdma_create_ep(id, res, NULL, attr);// Check to see if we got inline data allowed or notif (attr.cap.max_inline_data 16)send_flags IBV_SEND_INLINE;elseprintf(rdma_client: device doesnt support IBV_SEND_INLINE, using sge sends\n);if (ret) {perror(rdma_create_ep);goto out_free_addrinfo;}mr rdma_reg_msgs(id, recv_msg, 16);if (!mr) {perror(rdma_reg_msgs for recv_msg);ret -1;goto out_destroy_ep;}if ((send_flags IBV_SEND_INLINE) 0) {send_mr rdma_reg_msgs(id, send_msg, 16);if (!send_mr) {perror(rdma_reg_msgs for send_msg);ret -1;goto out_dereg_recv;}}ret rdma_post_recv(id, NULL, recv_msg, 16, mr);if (ret) {perror(rdma_post_recv);goto out_dereg_send;}ret rdma_connect(id, NULL);if (ret) {perror(rdma_connect);goto out_dereg_send;}printf(client send: %s\n, (char *)send_msg);ret rdma_post_send(id, NULL, send_msg, 16, send_mr, send_flags);if (ret) {perror(rdma_post_send);goto out_disconnect;}while ((ret rdma_get_send_comp(id, wc)) 0);if (ret 0) {perror(rdma_get_send_comp);goto out_disconnect;}while ((ret rdma_get_recv_comp(id, wc)) 0);if (ret 0)perror(rdma_get_recv_comp);elseret 0;printf(client received: %s\n, (char *) recv_msg);out_disconnect:rdma_disconnect(id); out_dereg_send:if ((send_flags IBV_SEND_INLINE) 0)rdma_dereg_mr(send_mr); out_dereg_recv:rdma_dereg_mr(mr); out_destroy_ep:rdma_destroy_ep(id); out_free_addrinfo:rdma_freeaddrinfo(res); out:return ret; }int main(int argc, char **argv) {int ret;char *s hello world;// printf(client send: %s\n, s);memcpy(send_msg, s , strlen(s));printf(rdma_client: start\n);ret run();printf(rdma_client: end %d\n, ret);return ret; }server端代码 // server1.c /** Copyright (c) 2005-2009 Intel Corporation. All rights reserved.** This software is available to you under the OpenIB.org BSD license* below:** Redistribution and use in source and binary forms, with or* without modification, are permitted provided that the following* conditions are met:** - Redistributions of source code must retain the above* copyright notice, this list of conditions and the following* disclaimer.** - Redistributions in binary form must reproduce the above* copyright notice, this list of conditions and the following* disclaimer in the documentation and/or other materials* provided with the distribution.** THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE* SOFTWARE.*/#include stdio.h #include stdlib.h #include string.h #include errno.h #include getopt.h #include netdb.h #include rdma/rdma_cma.h #include rdma/rdma_verbs.hstatic const char *server 0.0.0.0; static const char *port 7471;static struct rdma_cm_id *listen_id, *id; static struct ibv_mr *mr, *send_mr; static int send_flags; static uint8_t send_msg[16]; static uint8_t recv_msg[16];static int run(void) {struct rdma_addrinfo hints, *res;struct ibv_qp_init_attr init_attr;struct ibv_qp_attr qp_attr;struct ibv_wc wc;int ret;memset(hints, 0, sizeof hints);hints.ai_flags RAI_PASSIVE;hints.ai_port_space RDMA_PS_TCP;ret rdma_getaddrinfo(server, port, hints, res);if (ret) {printf(rdma_getaddrinfo: %s\n, gai_strerror(ret));return ret;}memset(init_attr, 0, sizeof init_attr);init_attr.cap.max_send_wr init_attr.cap.max_recv_wr 1;init_attr.cap.max_send_sge init_attr.cap.max_recv_sge 1;init_attr.cap.max_inline_data 16;init_attr.sq_sig_all 1;ret rdma_create_ep(listen_id, res, NULL, init_attr);if (ret) {perror(rdma_create_ep);goto out_free_addrinfo;}ret rdma_listen(listen_id, 0);if (ret) {perror(rdma_listen);goto out_destroy_listen_ep;}ret rdma_get_request(listen_id, id);if (ret) {perror(rdma_get_request);goto out_destroy_listen_ep;}memset(qp_attr, 0, sizeof qp_attr);memset(init_attr, 0, sizeof init_attr);ret ibv_query_qp(id-qp, qp_attr, IBV_QP_CAP,init_attr);if (ret) {perror(ibv_query_qp);goto out_destroy_accept_ep;}if (init_attr.cap.max_inline_data 16)send_flags IBV_SEND_INLINE;elseprintf(rdma_server: device doesnt support IBV_SEND_INLINE, using sge sends\n);mr rdma_reg_msgs(id, recv_msg, 16);if (!mr) {ret -1;perror(rdma_reg_msgs for recv_msg);goto out_destroy_accept_ep;}if ((send_flags IBV_SEND_INLINE) 0) {send_mr rdma_reg_msgs(id, send_msg, 16);if (!send_mr) {ret -1;perror(rdma_reg_msgs for send_msg);goto out_dereg_recv;}}ret rdma_post_recv(id, NULL, recv_msg, 16, mr);if (ret) {perror(rdma_post_recv);goto out_dereg_send;}ret rdma_accept(id, NULL);if (ret) {perror(rdma_accept);goto out_dereg_send;}while ((ret rdma_get_recv_comp(id, wc)) 0);if (ret 0) {perror(rdma_get_recv_comp);goto out_disconnect;}printf(server received: %s\n , (char *)recv_msg);char *s ACK;memcpy(send_msg, s, strlen(s));printf(server send: %s\n, (char *)send_msg);ret rdma_post_send(id, NULL, send_msg, 16, send_mr, send_flags);if (ret) {perror(rdma_post_send);goto out_disconnect;}while ((ret rdma_get_send_comp(id, wc)) 0);if (ret 0)perror(rdma_get_send_comp);elseret 0;out_disconnect:rdma_disconnect(id); out_dereg_send:if ((send_flags IBV_SEND_INLINE) 0)rdma_dereg_mr(send_mr); out_dereg_recv:rdma_dereg_mr(mr); out_destroy_accept_ep:rdma_destroy_ep(id); out_destroy_listen_ep:rdma_destroy_ep(listen_id); out_free_addrinfo:rdma_freeaddrinfo(res);return ret; }int main(int argc, char **argv) {int ret;printf(rdma_server: start\n);ret run();printf(rdma_server: end %d\n, ret);return ret; }首先make编译完之后在server端执行 ./server1然后在客户端执行./client1 运行结果 可以看到 client向server发送了hello worldserver收到之后打印出来并回复给client端ACK消息client收到之后并打印。最后双方断开连接完成 version2-客户端发送一次服务端循环等待 client2的代码跟上面一样server2代码不一样。 server2的逻辑在run函数进来之后记录一个connect点当远程客户端发送完信息后释放连接的资源跳转到connect阶段准备让下一个client连接。 /** Copyright (c) 2005-2009 Intel Corporation. All rights reserved.** This software is available to you under the OpenIB.org BSD license* below:** Redistribution and use in source and binary forms, with or* without modification, are permitted provided that the following* conditions are met:** - Redistributions of source code must retain the above* copyright notice, this list of conditions and the following* disclaimer.** - Redistributions in binary form must reproduce the above* copyright notice, this list of conditions and the following* disclaimer in the documentation and/or other materials* provided with the distribution.** THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE* SOFTWARE.*/#include stdio.h #include stdlib.h #include string.h #include errno.h #include getopt.h #include netdb.h #include rdma/rdma_cma.h #include rdma/rdma_verbs.h#define N 100 #define MAX_CAP 32static const char *server 0.0.0.0; static const char *port 7471;static struct rdma_cm_id *listen_id, *id; static struct ibv_mr *mr, *send_mr; static int send_flags; static uint8_t send_msg[MAX_CAP]; static uint8_t recv_msg[MAX_CAP];static int run(void) {struct rdma_addrinfo hints, *res;struct ibv_qp_init_attr init_attr;struct ibv_qp_attr qp_attr;struct ibv_wc wc;int ret;while(1){memset(hints, 0, sizeof hints);hints.ai_flags RAI_PASSIVE;hints.ai_port_space RDMA_PS_TCP;ret rdma_getaddrinfo(server, port, hints, res);if (ret) {printf(rdma_getaddrinfo: %s\n, gai_strerror(ret));return ret;}memset(init_attr, 0, sizeof init_attr);init_attr.cap.max_send_wr init_attr.cap.max_recv_wr N;init_attr.cap.max_send_sge init_attr.cap.max_recv_sge 1;init_attr.cap.max_inline_data MAX_CAP;init_attr.sq_sig_all 1;ret rdma_create_ep(listen_id, res, NULL, init_attr);if (ret) {perror(rdma_create_ep);goto out_free_addrinfo;}ret rdma_listen(listen_id, 0);if (ret) {perror(rdma_listen);goto out_destroy_listen_ep;}ret rdma_get_request(listen_id, id);if (ret) {perror(rdma_get_request);goto out_destroy_listen_ep;}memset(qp_attr, 0, sizeof qp_attr);memset(init_attr, 0, sizeof init_attr);ret ibv_query_qp(id-qp, qp_attr, IBV_QP_CAP,init_attr);if (ret) {perror(ibv_query_qp);goto out_destroy_accept_ep;}if (init_attr.cap.max_inline_data MAX_CAP)send_flags IBV_SEND_INLINE;elseprintf(rdma_server: device doesnt support IBV_SEND_INLINE, using sge sends\n);mr rdma_reg_msgs(id, recv_msg, N);if (!mr) {ret -1;perror(rdma_reg_msgs for recv_msg);goto out_destroy_accept_ep;}if ((send_flags IBV_SEND_INLINE) 0) {send_mr rdma_reg_msgs(id, send_msg, MAX_CAP);if (!send_mr) {ret -1;perror(rdma_reg_msgs for send_msg);goto out_dereg_recv;}} ret rdma_accept(id, NULL);if (ret) {perror(rdma_accept);goto out_dereg_send;}memset(recv_msg, 0 , sizeof recv_msg);memset(send_msg, 0 , sizeof send_msg);ret rdma_post_recv(id, NULL, recv_msg, MAX_CAP, mr);if (ret) {perror(rdma_post_recv);goto out_dereg_send;}while ((ret rdma_get_recv_comp(id, wc)) 0);if (ret 0) {perror(rdma_get_recv_comp);goto out_disconnect;}printf(server received: %s\n, (char *)recv_msg);memcpy(send_msg, recv_msg, sizeof(recv_msg));ret rdma_post_send(id, NULL, send_msg, MAX_CAP, send_mr, send_flags);if (ret) {perror(rdma_post_send);goto out_disconnect;}while ((ret rdma_get_send_comp(id, wc)) 0); // 确认对方已经收到 对方会发送ackif (ret 0)perror(rdma_get_send_comp);elseret 0;rdma_disconnect(id);if ((send_flags IBV_SEND_INLINE) 0)rdma_dereg_mr(send_mr);rdma_dereg_mr(mr);rdma_destroy_ep(id);rdma_destroy_ep(listen_id);rdma_freeaddrinfo(res); }out_disconnect:rdma_disconnect(id); out_dereg_send:if ((send_flags IBV_SEND_INLINE) 0)rdma_dereg_mr(send_mr); out_dereg_recv:rdma_dereg_mr(mr); out_destroy_accept_ep:rdma_destroy_ep(id); out_destroy_listen_ep:rdma_destroy_ep(listen_id); out_free_addrinfo:rdma_freeaddrinfo(res); return ret; }int main(int argc, char **argv) {int ret;printf(rdma_server: start\n);ret run();printf(rdma_server: end %d\n, ret);return ret; }运行结果 可以看到客户端发送一次消息之后便结束了服务端却一直等待连接直到按下ctrlc。 version3-客户端循环发送服务端循环等待一次连接 和上述版本2不同的时候这里client和server只连接一次然后可以多次发送消息。直到client发送的消息为disconnect // client3.c /** Copyright (c) 2010 Intel Corporation. All rights reserved.** This software is available to you under the OpenIB.org BSD license* below:** Redistribution and use in source and binary forms, with or* without modification, are permitted provided that the following* conditions are met:** - Redistributions of source code must retain the above* copyright notice, this list of conditions and the following* disclaimer.** - Redistributions in binary form must reproduce the above* copyright notice, this list of conditions and the following* disclaimer in the documentation and/or other materials* provided with the distribution.** THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE* SOFTWARE.*/#include stdio.h #include stdlib.h #include string.h #include netdb.h #include errno.h #include getopt.h #include rdma/rdma_cma.h #include rdma/rdma_verbs.h#define N 100 #define MAX_CAP 32static const char *server 10.10.10.1; static const char *port 7471;static struct rdma_cm_id *id; static struct ibv_mr *mr, *send_mr; static int send_flags; static uint8_t send_msg[MAX_CAP]; static uint8_t recv_msg[MAX_CAP];static int run(void) {struct rdma_addrinfo hints, *res;struct ibv_qp_init_attr attr;struct ibv_wc wc;int ret;memset(hints, 0, sizeof hints);hints.ai_port_space RDMA_PS_TCP;ret rdma_getaddrinfo(server, port, hints, res);if (ret) {printf(rdma_getaddrinfo: %s\n, gai_strerror(ret));goto out;}memset(attr, 0, sizeof attr);attr.cap.max_send_wr attr.cap.max_recv_wr 5;attr.cap.max_send_sge attr.cap.max_recv_sge 1;attr.cap.max_inline_data MAX_CAP;attr.qp_context id;attr.sq_sig_all 1;ret rdma_create_ep(id, res, NULL, attr);// Check to see if we got inline data allowed or notif (attr.cap.max_inline_data MAX_CAP)send_flags IBV_SEND_INLINE;elseprintf(rdma_client: device doesnt support IBV_SEND_INLINE, using sge sends\n);if (ret) {perror(rdma_create_ep);goto out_free_addrinfo;}mr rdma_reg_msgs(id, recv_msg, MAX_CAP);if (!mr) {perror(rdma_reg_msgs for recv_msg);ret -1;goto out_destroy_ep;}if ((send_flags IBV_SEND_INLINE) 0) {send_mr rdma_reg_msgs(id, send_msg, MAX_CAP);if (!send_mr) {perror(rdma_reg_msgs for send_msg);ret -1;goto out_dereg_recv;}}// ret rdma_post_recv(id, NULL, recv_msg, 16, mr);// if (ret) {// perror(rdma_post_recv);// goto out_dereg_send;// }// printf(123\n);ret rdma_connect(id, NULL);if (ret) {perror(rdma_connect);goto out_dereg_send;}while(1){// sleep(5);memset(recv_msg, 0 , sizeof recv_msg);memset(send_msg, 0 , sizeof send_msg);printf(input send message: );scanf(%s, send_msg);getchar();ret rdma_post_recv(id, NULL, recv_msg, MAX_CAP, mr);if (ret) {perror(rdma_post_recv);goto out_dereg_send;}ret rdma_post_send(id, NULL, send_msg, MAX_CAP, send_mr, send_flags);if (ret) {perror(rdma_post_send);goto out_disconnect;}while ((ret rdma_get_send_comp(id, wc)) 0);if (ret 0) {perror(rdma_get_send_comp);goto out_disconnect;}while ((ret rdma_get_recv_comp(id, wc)) 0);if (ret 0)perror(rdma_get_recv_comp);elseret 0;if(strcmp((char*)send_msg,disconnect) 0){printf(disconnect\n);goto out_disconnect;}else{printf(%s\n, recv_msg);}}out_disconnect:rdma_disconnect(id); out_dereg_send:if ((send_flags IBV_SEND_INLINE) 0)rdma_dereg_mr(send_mr); out_dereg_recv:rdma_dereg_mr(mr); out_destroy_ep:rdma_destroy_ep(id); out_free_addrinfo:rdma_freeaddrinfo(res); out:return ret;}int main(int argc, char **argv) {int ret;//memcpy(send_msg, argv[1], 50);// while ((op getopt(argc, argv, s:p:)) ! -1) {// switch (op) {// case s:// server optarg;// break;// case p:// port optarg;// break;// default:// printf(usage: %s\n, argv[0]);// printf(\t[-s server_address]\n);// printf(\t[-p port_number]\n);// exit(1);// }// }printf(rdma_client: start\n);ret run();printf(rdma_client: end %d\n, ret);return ret; }// server3.c /** Copyright (c) 2005-2009 Intel Corporation. All rights reserved.** This software is available to you under the OpenIB.org BSD license* below:** Redistribution and use in source and binary forms, with or* without modification, are permitted provided that the following* conditions are met:** - Redistributions of source code must retain the above* copyright notice, this list of conditions and the following* disclaimer.** - Redistributions in binary form must reproduce the above* copyright notice, this list of conditions and the following* disclaimer in the documentation and/or other materials* provided with the distribution.** THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE* SOFTWARE.*/#include stdio.h #include stdlib.h #include string.h #include errno.h #include getopt.h #include netdb.h #include rdma/rdma_cma.h #include rdma/rdma_verbs.h#define N 100 #define MAX_CAP 32static const char *server 0.0.0.0; static const char *port 7471;static struct rdma_cm_id *listen_id, *id; static struct ibv_mr *mr, *send_mr; static int send_flags; static uint8_t send_msg[MAX_CAP]; static uint8_t recv_msg[MAX_CAP];static int run(void) {struct rdma_addrinfo hints, *res;struct ibv_qp_init_attr init_attr;struct ibv_qp_attr qp_attr;struct ibv_wc wc;int ret;connect:memset(hints, 0, sizeof hints);hints.ai_flags RAI_PASSIVE;hints.ai_port_space RDMA_PS_TCP;ret rdma_getaddrinfo(server, port, hints, res);if (ret) {printf(rdma_getaddrinfo: %s\n, gai_strerror(ret));return ret;}memset(init_attr, 0, sizeof init_attr);init_attr.cap.max_send_wr init_attr.cap.max_recv_wr N;init_attr.cap.max_send_sge init_attr.cap.max_recv_sge 1;init_attr.cap.max_inline_data MAX_CAP;init_attr.sq_sig_all 1;ret rdma_create_ep(listen_id, res, NULL, init_attr);if (ret) {perror(rdma_create_ep);goto out_free_addrinfo;}ret rdma_listen(listen_id, 0);if (ret) {perror(rdma_listen);goto out_destroy_listen_ep;}ret rdma_get_request(listen_id, id);if (ret) {perror(rdma_get_request);goto out_destroy_listen_ep;}memset(qp_attr, 0, sizeof qp_attr);memset(init_attr, 0, sizeof init_attr);ret ibv_query_qp(id-qp, qp_attr, IBV_QP_CAP,init_attr);if (ret) {perror(ibv_query_qp);goto out_destroy_accept_ep;}if (init_attr.cap.max_inline_data MAX_CAP)send_flags IBV_SEND_INLINE;elseprintf(rdma_server: device doesnt support IBV_SEND_INLINE, using sge sends\n);mr rdma_reg_msgs(id, recv_msg, N);if (!mr) {ret -1;perror(rdma_reg_msgs for recv_msg);goto out_destroy_accept_ep;}if ((send_flags IBV_SEND_INLINE) 0) {send_mr rdma_reg_msgs(id, send_msg, MAX_CAP);if (!send_mr) {ret -1;perror(rdma_reg_msgs for send_msg);goto out_dereg_recv;}} ret rdma_accept(id, NULL);if (ret) {perror(rdma_accept);goto out_dereg_send;}while (1) {memset(recv_msg, 0 , sizeof recv_msg);memset(send_msg, 0 , sizeof send_msg);ret rdma_post_recv(id, NULL, recv_msg, MAX_CAP, mr);if (ret) {perror(rdma_post_recv);goto out_dereg_send;}while ((ret rdma_get_recv_comp(id, wc)) 0);if (ret 0) {perror(rdma_get_recv_comp);goto out_disconnect;}char *s (char *)recv_msg;int total_length strlen(server get ) strlen(s); // 加1是为了存储字符串结束符\0char *recv_str (char *)malloc(total_length); // 分配足够的空间strcpy(recv_str, server get );strcat(recv_str, s);//printf(%s\n, recv_str);memcpy(send_msg, recv_str, strlen(recv_str));ret rdma_post_send(id, NULL, send_msg, MAX_CAP, send_mr, send_flags);if (ret) {perror(rdma_post_send);goto out_disconnect;}if(strcmp((char*)recv_msg,disconnect) 0){//printf(%s\n,recv_msg);printf(client disconnect\n);rdma_disconnect(id);if ((send_flags IBV_SEND_INLINE) 0)rdma_dereg_mr(send_mr);rdma_dereg_mr(mr);rdma_destroy_ep(id);rdma_destroy_ep(listen_id);rdma_freeaddrinfo(res); //goto out_disconnect;goto connect;}else{printf(%s\n, recv_msg);}// while ((ret rdma_get_send_comp(id, wc)) 0); // 确认对方已经收到 对方发送ack// printf(after send\n);// if (ret 0)// perror(rdma_get_send_comp);// else// ret 0;}out_disconnect:rdma_disconnect(id); out_dereg_send:if ((send_flags IBV_SEND_INLINE) 0)rdma_dereg_mr(send_mr); out_dereg_recv:rdma_dereg_mr(mr); out_destroy_accept_ep:rdma_destroy_ep(id); out_destroy_listen_ep:rdma_destroy_ep(listen_id); out_free_addrinfo:rdma_freeaddrinfo(res); return ret; }int main(int argc, char **argv) {int op, ret;while ((op getopt(argc, argv, s:p:)) ! -1) {switch (op) {case s:server optarg;break;case p:port optarg;break;default:printf(usage: %s\n, argv[0]);printf(\t[-s server_address]\n);printf(\t[-p port_number]\n);exit(1);}}printf(rdma_server: start\n);ret run();printf(rdma_server: end %d\n, ret);return ret; }运行结果 总结 本文实现了rdma中send-receive双边原语的三种需求版本从单次发送到两者都能多次发送。理解其中的代码逻辑想要发送消息之前对端得创建一个recv队列用来接收消息。发送完了有一个发送完成队列接收完了也有一个接收完成队列。最后双方断开连接需要一起断开不能某一方执行disconnect另一方不执行。本次实验有一个关键点 while ((ret rdma_get_send_comp(id, wc)) 0)这一行代码是等待发送成功发送成功之后对方会给一个隐式信息表示我已经收到。这里耗费得时间比较长一点在版本3中如果不注释掉在server端的receive队列还没有建立好这就导致client发送了消息server还没有收到双方就陷入了死循环中。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/88581.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

电子商务书店网站设计实验门户网站 jsp

1 现象 用上海代数律动公司的AlgoT1-3组合导航设备采集数据进行组合导航算法调试,AlgoT1-3机器输出的结果很好很平滑,AlgoT1-3是带GNSS/INS的组合导航设备,另外还有一款更贵一点的带视觉的组合导航AlgoT1,效果会更好一些&#xf…

交互式网站开发苏州建站公司速找苏州聚尚网络

安装android studio到最后一步的时候遇见了这个问题 。 android studio安装详见Android Studio 安装 经过查阅多篇博客 把他们的解决方案放在一起一顿操作猛如虎,然后就成了。。。 2篇原文链接我放在这里: Android Studio新建工程时SDK缺少extra-an…

网站购买流程中国设计之家

在Java中生成PDF文件的缩略图可以使用Apache PDFBox库。以下是一个简单的示例代码来实现这个功能: import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.rendering.PDFRenderer; import org.apache.pdfbox.tools.imageio.ImageIOUtil;import j…

产品做推广都有那些网站新注册公司怎么做网站

目录捏 前言一、异步编程二、回调函数三、回调地狱四、Promise1. Promise 简介2. Promise 语法3. Promise 链式 五、总结 前言 想要学习Promise,我们首先要了解异步编程、回调函数、回调地狱三方面知识: 一、异步编程 异步编程技术使你的程序可以在执行一…

网站运营商查询大型网站开发价格

***import: html文件中,通过script标签引入js文件。而vue中,通过import xxx from xxx路径的方式导入文件,不光可以导入js文件。 from前的:“xxx”指的是为导入的文件起一个名称,不是指导入的文件的名称&…

泊头市做网站价格跨境网站开发

高纯气体应用领域极宽,在半导体工业,高纯氮、氢、氩、氦可作为运载气和保护气;高纯气体可作为配制混合气的底气。随着LED和半导体的发展,对于其原物料生产的所需要的高纯气体,特别是7N级别的高纯氨气的需求不断增加,近…

图书馆网站建设需求方案网站建设学习网

文章目录 项目介绍主要功能截图:部分代码展示设计总结项目获取方式🍅 作者主页:超级无敌暴龙战士塔塔开 🍅 简介:Java领域优质创作者🏆、 简历模板、学习资料、面试题库【关注我,都给你】 🍅文末获取源码联系🍅 项目介绍 基于SSM的超市订单管理系统,java项目。 …

网站域名费用交给谁企业运营管理流程图

文章目录 1.存储基础1.1 基础知识1.1.1 存储基础1.1.2 存储使用 1.2 文件系统1.2.1 简介1.2.2 数据存储1.2.3 存储应用的基本方式1.2.4 文件存储 1.3 小结 1.存储基础 学习目标:这一节,我们从基础知识、文件系统、小节三个方面来学习。 1.1 基础知识 1.…

要点营销网站官方网站建设合作协议

目录 1、通义千问 (aliyun.com) 2、MIYAGPT (miyadns.com) 3、AIchatOS 4、 Safeline Waf CE (aitianhu1.top)

深圳最好的营销网站建设公司排名七牛云微信打开wordpress

欢迎来到《算法与数据结构》专栏!这个专栏将引领您进入计算机科学领域中最重要、最精彩的领域之一:算法与数据结构。不管您是一名初学者,还是已经拥有一定编程经验的开发者,都可以从这里找到有益的知识和实践。 在计算机科学的世…

freenom怎么做网站青岛注册公司代理

进制: 概念: 进制:指进位制,是人们规定的一种进位方式,表示某一位置的数看,运算时是逢*进一位。十进制是逢十进一,二进制是逢二进一。以此类推。学习的目的就是为了数据运算过程理解的更加深刻…

涞水网站建设深圳做企业网站多少钱

1、前期准备 部署好mysql数据库,创建好unicom数据库下载好bootstap的插件下载好jquery的插件下载好mysqlclient-1.4.6-cp36-cp36m-win_amd64.whl的安装包,根据python的版本下载 2、创建项目 在pycharm中创建项目 在pycharm的终端创建虚拟环境 py -m v…

中国机械工业建设集团有限公司网站南湖区建设街道办事处网站

导语 在互联网时代,获取用户的反馈和意见是非常重要的,它可以帮助我们了解用户的需求和喜好,提高我们的产品和服务质量。有时候,我们需要从地图上爬取用户对某些地点或商家的评价和评论,这样我们就可以分析用户对不同…

网站改版声明wordpress自主注册

人脸检测是一种计算机视觉技术,旨在识别图像或视频中的人脸。这项技术的基本内容包括使用特定的算法和模型来定位和识别人脸,通常涉及在图像中寻找面部特征,如眼睛、鼻子、嘴巴等,以便准确地确定人脸的位置和边界。人脸检测技术的…

淘宝放单网站怎么做网站单页模板怎么安装

图形和动画本地化是多媒体改编的一个关键方面,需要对技术技能和文化细微差别有深入的理解。当由母语人士和设计师进行时,这一过程达到了自动化系统通常无法复制的真实性和相关性水平。 本土专业人士对文化偏好、象征主义和视觉美学有着固有的理解&#…

北京哪有建网站公司或个人的自动网站建设系统cms

今日简单分享 empty 组件的源码实现,主要从以下三个方面: 1、empty 组件页面结构 2、empty 组件属性 3、empty 组件 slot 一、empty 组件页面结构 二、empty 组件属性 2.1 image 属性,图片地址,类型 string,无默认…

网站跟网页的区别是什么设计网站报价

在Java中,已检查异常(Checked Exceptions)和未检查异常(Unchecked Exceptions)是两种主要的异常类型。 已检查异常(Checked Exceptions):这种类型的异常在编译期就会被检查&#xf…

金融投资网站模板策划公司职位

CentOS 使用 Cronie 实现定时任务 文章目录 CentOS 使用 Cronie 实现定时任务一、简介二、基本使用1、常用命令2、使用示例第一步:创建脚本/home/create.sh第二步:添加定时任务第三步:重启 cronie 服务额外:查看 cronie 运行状态定…

巴中网站开发wechat网页版登陆

编程笔记 html5&css&js 005 小学数学四则运算练习 一、代码二、解释 这段代码定义了一个页面&#xff0c;用于小学数学四则运算的练习。这可能有点难&#xff0c;实际如果需要可以通过更改代码来达到要求。 一、代码 <!DOCTYPE html> <html lang"zh&quo…