/* Server run loop till shutdown */ void rdb_r_s_server_run(struct server_data *server_data) { int i; /* default xio supplied main loop */ if (xio_context_run_loop(server_data->ctx, XIO_INFINITE) != 0) { for (i = 0; i < server_data->nworkers; i++) { xio_context_stop_loop(server_data->wdata[i].ctx); } fprintf(stderr, "failed to run event loop for server listner. reason %d - (%s)\n", xio_errno(), xio_strerror(xio_errno())); } /* join the worker threads */ for (i = 0; i < server_data->nworkers; i++) { pthread_join(server_data->wdata[i].thread_id, NULL); } /* free the server */ if (server_data->server) xio_unbind(server_data->server); /* free the context */ if (server_data->ctx) xio_context_destroy(server_data->ctx); xio_shutdown(); if (server_data) free(server_data); }
/*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { struct xio_server *server; /* server portal */ struct server_data *server_data; char url[256]; int i; uint16_t port = atoi(argv[2]); server_data = calloc(1, sizeof(*server_data)); if (!server_data) return -1; xio_init(); /* create thread context for the client */ server_data->ctx = xio_context_create(NULL, 0); /* create url to connect to */ sprintf(url, "rdma://%s:%d", argv[1], port); /* bind a listener server to a portal/url */ server = xio_bind(server_data->ctx, &server_ops, url, NULL, 0, server_data); if (server == NULL) goto cleanup; /* spawn portals */ for (i = 0; i < MAX_THREADS; i++) { server_data->tdata[i].affinity = i+1; port += 1; sprintf(server_data->tdata[i].portal, "rdma://%s:%d", argv[1], port); pthread_create(&server_data->tdata[i].thread_id, NULL, portal_server_cb, &server_data->tdata[i]); } xio_context_run_loop(server_data->ctx, XIO_INFINITE); /* normal exit phase */ fprintf(stdout, "exit signaled\n"); /* join the threads */ for (i = 0; i < MAX_THREADS; i++) pthread_join(server_data->tdata[i].thread_id, NULL); /* free the server */ xio_unbind(server); cleanup: /* free the context */ xio_context_destroy(server_data->ctx); xio_shutdown(); free(server_data); return 0; }
/*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { struct xio_session *session; char url[256]; struct session_data session_data; int i = 0; struct xio_session_params params; if (argc < 3) { printf("Usage: %s <host> <port> <transport:optional>\n", argv[0]); exit(1); } memset(&session_data, 0, sizeof(session_data)); memset(¶ms, 0, sizeof(params)); /* initialize library */ xio_init(); /* create thread context for the client */ session_data.ctx = xio_context_create(NULL, 0, -1); /* create url to connect to */ if (argc > 3) sprintf(url, "%s://%s:%s", argv[3], argv[1], argv[2]); else sprintf(url, "rdma://%s:%s", argv[1], argv[2]); params.type = XIO_SESSION_CLIENT; params.ses_ops = &ses_ops; params.user_context = &session_data; params.uri = url; session = xio_session_create(¶ms); /* connect the session */ session_data.conn = xio_connect(session, session_data.ctx, 0, NULL, &session_data); /* create "hello world" message */ for (i = 0; i < QUEUE_DEPTH; i++) { memset(&session_data.req[i], 0, sizeof(session_data.req[i])); /* header */ session_data.req[i].out.header.iov_base = strdup("hello world header request"); session_data.req[i].out.header.iov_len = strlen(session_data.req[i].out.header.iov_base) + 1; /* iovec[0]*/ session_data.req[i].in.sgl_type = XIO_SGL_TYPE_IOV; session_data.req[i].in.data_iov.max_nents = XIO_IOVLEN; session_data.req[i].out.sgl_type = XIO_SGL_TYPE_IOV; session_data.req[i].out.data_iov.max_nents = XIO_IOVLEN; session_data.req[i].out.data_iov.sglist[0].iov_base = strdup("hello world data request"); session_data.req[i].out.data_iov.sglist[0].iov_len = strlen(session_data.req[i].out.data_iov.sglist[0].iov_base) + 1; session_data.req[i].out.data_iov.nents = 1; } /* send first message */ for (i = 0; i < QUEUE_DEPTH; i++) { xio_send_request(session_data.conn, &session_data.req[i]); session_data.nsent++; } /* event dispatcher is now running */ xio_context_run_loop(session_data.ctx, XIO_INFINITE); /* normal exit phase */ fprintf(stdout, "exit signaled\n"); /* free the message */ for (i = 0; i < QUEUE_DEPTH; i++) { free(session_data.req[i].out.header.iov_base); free(session_data.req[i].out.data_iov.sglist[0].iov_base); } /* free the context */ xio_context_destroy(session_data.ctx); xio_shutdown(); printf("good bye\n"); return 0; }
/*---------------------------------------------------------------------------*/ int main(int argc, char *const argv[]) { struct xio_session *session; char url[256]; int i; struct sigaction sa; int c; char *addr = NULL; char *port = NULL; char *trans = NULL; struct xio_session_params params; struct xio_connection_params cparams; while (1) { c = getopt_long(argc, argv, "a:p:r:hdnV", longopts, NULL); if (c == -1) break; switch (c) { case 'a': addr = optarg; break; case 'p': port = optarg; break; case 'r': trans = optarg; break; case 'h': usage(argv[0], 0); case 'd': debug_flag++; nofork_flag++; break; case 'n': nofork_flag++; break; case 'V': printf("%s\n", PACKAGE_STRING); exit(0); break; default: usage(argv[0], 1); break; } } memset(&sa, 0, sizeof(sa)); sa.sa_handler = signal_handler; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sa.sa_handler = SIG_IGN; sa.sa_flags = SA_RESTART; sigaction(SIGPIPE, &sa, NULL); if (!nofork_flag && daemon(0, 0)) { logerr("daemon() failed"); exit(1); } if (!debug_flag) { openlog("xioclntd", LOG_PID, LOG_DAEMON); use_syslog = 1; } /* Create the process PID file */ if (create_pidfile(pid_file) != 0) exit(EXIT_FAILURE); memset(&session_data, 0, sizeof(session_data)); memset(¶ms, 0, sizeof(params)); memset(&cparams, 0, sizeof(cparams)); /* initialize library */ xio_init(); /* create "hello world" message */ for (i = 0; i < QUEUE_DEPTH; i++) { memset(&session_data.req[i], 0, sizeof(session_data.req[i])); /* header */ session_data.req[i].out.header.iov_base = strdup("hello world header request"); session_data.req[i].out.header.iov_len = strlen((const char *) session_data.req[i].out.header.iov_base) + 1; /* iovec[0]*/ session_data.req[i].out.sgl_type = XIO_SGL_TYPE_IOV; session_data.req[i].out.data_iov.max_nents = XIO_IOVLEN; session_data.req[i].out.data_iov.sglist[0].iov_base = strdup("hello world iovec request"); session_data.req[i].out.data_iov.sglist[0].iov_len = strlen((const char *) session_data.req[i].out.data_iov.sglist[0].iov_base) + 1; session_data.req[i].out.data_iov.nents = 1; } /* create thread context for the client */ session_data.ctx = xio_context_create(NULL, 0, -1); /* create url to connect to */ if (trans) sprintf(url, "%s://%s:%s", trans, addr, port); else sprintf(url, "rdma://%s:%s", addr, port); params.type = XIO_SESSION_CLIENT; params.ses_ops = &ses_ops; params.user_context = &session_data; params.uri = url; reconnect: session = xio_session_create(¶ms); cparams.session = session; cparams.ctx = session_data.ctx; cparams.conn_user_context = &session_data; /* connect the session */ session_data.conn = xio_connect(&cparams); /* event dispatcher is now running */ xio_context_run_loop(session_data.ctx, XIO_INFINITE); if (reconnect_flag || reload_flag) { session_data.cnt = 0; if (reconnect_flag) sleep(1); reload_flag = 0; reconnect_flag = 0; goto reconnect; } /* normal exit phase */ logit(LOG_INFO, "exit signaled\n"); /* free the message */ for (i = 0; i < QUEUE_DEPTH; i++) { free(session_data.req[i].out.header.iov_base); free(session_data.req[i].out.data_iov.sglist[0].iov_base); } /* free the context */ xio_context_destroy(session_data.ctx); xio_shutdown(); remove_pidfile(); if (use_syslog) closelog(); return 0; }
/*---------------------------------------------------------------------------*/ int run_client_test(struct perf_parameters *user_param) { struct session_data sess_data; struct perf_comm *comm; struct thread_data *tdata; char url[256]; int i = 0; int max_cpus; pthread_t statistics_thread_id; struct perf_command command; int size_log2; int max_size_log2 = 24; /* client session attributes */ struct xio_session_attr attr = { &ses_ops, NULL, 0 }; xio_init(); g_mhz = get_cpu_mhz(0); max_cpus = sysconf(_SC_NPROCESSORS_ONLN); threads_iter = 1; size_log2 = 0; tdata = calloc(user_param->threads_num, sizeof(*tdata)); if (tdata == NULL) { fprintf(fd, "malloc failed\n"); return -1; } comm = create_comm_struct(user_param); if (establish_connection(comm)) { fprintf(stderr, "failed to establish connection\n"); free(tdata); destroy_comm_struct(comm); return -1; } if (user_param->output_file) { fd = fopen(user_param->output_file, "w"); if (fd == NULL) { fprintf(fd, "file open failed. %s\n", user_param->output_file); free(sess_data.tdata); destroy_comm_struct(comm); return -1; } fprintf(fd, "size, threads, tps, bw[Mbps], lat[usec]\n"); fflush(fd); } printf("%s", RESULT_FMT); printf("%s", RESULT_LINE); while (threads_iter <= user_param->threads_num) { data_len = (uint64_t)1 << size_log2; memset(&sess_data, 0, sizeof(sess_data)); memset(tdata, 0, user_param->threads_num*sizeof(*tdata)); sess_data.tdata = tdata; command.test_param.machine_type = user_param->machine_type; command.test_param.test_type = user_param->test_type; command.test_param.verb = user_param->verb; command.test_param.data_len = data_len; command.command = GetTestParams; ctx_write_data(comm, &command, sizeof(command)); sprintf(url, "rdma://%s:%d", user_param->server_addr, user_param->server_port); sess_data.session = xio_session_create(XIO_SESSION_CLIENT, &attr, url, 0, 0, &sess_data); if (sess_data.session == NULL) { int error = xio_errno(); fprintf(stderr, "session creation failed. reason %d - (%s)\n", error, xio_strerror(error)); goto cleanup; } pthread_create(&statistics_thread_id, NULL, statistics_thread_cb, &sess_data); /* spawn threads to handle connection */ for (i = 0; i < threads_iter; i++) { sess_data.tdata[i].affinity = ((user_param->cpu + i) % max_cpus); sess_data.tdata[i].cid = i; sess_data.tdata[i].sdata = &sess_data; sess_data.tdata[i].user_param = user_param; sess_data.tdata[i].data_len = data_len; /* all threads are working on the same session */ sess_data.tdata[i].session = sess_data.session; pthread_create(&sess_data.tdata[i].thread_id, NULL, worker_thread, &sess_data.tdata[i]); } pthread_join(statistics_thread_id, NULL); /* join the threads */ for (i = 0; i < threads_iter; i++) pthread_join(sess_data.tdata[i].thread_id, NULL); /* close the session */ xio_session_destroy(sess_data.session); if (sess_data.abort) { fprintf(stderr, "program aborted\n"); goto cleanup; } /* send result to server */ command.results.bytes = data_len; command.results.threads = threads_iter; command.results.tps = sess_data.tps; command.results.avg_bw = sess_data.avg_bw; command.results.avg_lat = sess_data.avg_lat_us; command.results.min_lat = sess_data.min_lat_us; command.results.max_lat = sess_data.max_lat_us; command.command = GetTestResults; /* sync point */ ctx_write_data(comm, &command, sizeof(command)); printf(REPORT_FMT, data_len, threads_iter, sess_data.tps, sess_data.avg_bw, sess_data.avg_lat_us, sess_data.min_lat_us, sess_data.max_lat_us); if (fd) fprintf(fd, "%lu, %d, %lu, %.2lf, %.2lf\n", data_len, threads_iter, sess_data.tps, sess_data.avg_bw, sess_data.avg_lat_us); fflush(fd); /* sync point */ ctx_read_data(comm, NULL, 0, NULL); if (++size_log2 < max_size_log2) continue; threads_iter++; size_log2 = 0; } printf("%s", RESULT_LINE); cleanup: if (fd) fclose(fd); ctx_hand_shake(comm); ctx_close_connection(comm); destroy_comm_struct(comm); free(tdata); xio_shutdown(); return 0; }
/*---------------------------------------------------------------------------*/ int run_server_test(struct perf_parameters *user_param) { struct server_data server_data; struct perf_command command; int i, len, retval; int max_cpus; uint64_t cpusmask; int cpusnr; int cpu; xio_init(); max_cpus = sysconf(_SC_NPROCESSORS_ONLN); i = intf_name_best_cpus(user_param->intf_name, &cpusmask, &cpusnr); if (i == 0) { printf("best cpus [%d] %s\n", cpusnr, intf_cpusmask_str(cpusmask, cpusnr, user_param->intf_name)); } server_data.my_test_param.machine_type = user_param->machine_type; server_data.my_test_param.test_type = user_param->test_type; server_data.my_test_param.verb = user_param->verb; server_data.my_test_param.data_len = 0; server_data.tdata = calloc(user_param->threads_num, sizeof(*server_data.tdata)); /* spawn portals */ for (i = 0, cpu = 0; i < user_param->threads_num; i++, cpu++) { while (1) { if (cpusmask_test_bit(cpu, &cpusmask)) break; if (++cpu == max_cpus) cpu = 0; } server_data.tdata[i].affinity = cpu; server_data.tdata[i].portal_index = (i % user_param->portals_arr_len); server_data.tdata[i].user_param = user_param; pthread_create(&server_data.tdata[i].thread_id, NULL, portal_server_cb, &server_data.tdata[i]); } server_data.user_param = user_param; pthread_create(&server_data.thread_id, NULL, balancer_server_cb, &server_data); server_data.comm = create_comm_struct(user_param); if (establish_connection(server_data.comm)) { fprintf(stderr, "failed to establish connection\n"); goto cleanup; } printf("%s", RESULT_FMT); printf("%s", RESULT_LINE); while (1) { /* sync test parameters */ retval = ctx_read_data(server_data.comm, &command, sizeof(command), &len); if (retval) { /* disconnection */ fprintf(stderr, "program aborted\n"); break; } if (len == 0) { /* handshake */ ctx_write_data(server_data.comm, NULL, 0); break; } switch (command.command) { case GetTestResults: on_test_results(&command.results); ctx_write_data(server_data.comm, NULL, 0); break; case GetTestParams: break; default: fprintf(stderr, "unknown command %d\n", len); exit(0); break; }; } if (retval == 0) printf("%s", RESULT_LINE); /* normal exit phase */ ctx_close_connection(server_data.comm); cleanup: for (i = 0; i < user_param->threads_num; i++) xio_context_stop_loop(server_data.tdata[i].ctx, 0); destroy_comm_struct(server_data.comm); /* join the threads */ for (i = 0; i < user_param->threads_num; i++) pthread_join(server_data.tdata[i].thread_id, NULL); if (server_data.running) xio_context_stop_loop(server_data.ctx, 0); pthread_join(server_data.thread_id, NULL); free(server_data.tdata); xio_shutdown(); return 0; }
/*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { struct xio_session *session; char url[256]; struct session_data session_data; int i = 0; /* client session attributes */ struct xio_session_attr attr = { &ses_ops, /* callbacks structure */ NULL, /* no need to pass the server private data */ 0 }; memset(&session_data, 0, sizeof(session_data)); /* initialize library */ xio_init(); /* create thread context for the client */ session_data.ctx = xio_context_create(NULL, 0); /* create url to connect to */ sprintf(url, "rdma://%s:%s", argv[1], argv[2]); session = xio_session_create(XIO_SESSION_CLIENT, &attr, url, 0, 0, &session_data); /* connect the session */ session_data.conn = xio_connect(session, session_data.ctx, 0, NULL, &session_data); /* create "hello world" message */ for (i = 0; i < QUEUE_DEPTH; i++) { memset(&session_data.req[i], 0, sizeof(session_data.req[i])); session_data.req[i].out.header.iov_base = strdup("hello world header request"); session_data.req[i].out.header.iov_len = strlen(session_data.req[i].out.header.iov_base) + 1; } /* send first message */ for (i = 0; i < QUEUE_DEPTH; i++) { xio_send_request(session_data.conn, &session_data.req[i]); session_data.nsent++; } /* event dispatcher is now running */ xio_context_run_loop(session_data.ctx, XIO_INFINITE); /* normal exit phase */ fprintf(stdout, "exit signaled\n"); /* free the message */ for (i = 0; i < QUEUE_DEPTH; i++) free(session_data.req[i].out.header.iov_base); /* free the context */ xio_context_destroy(session_data.ctx); xio_shutdown(); printf("good bye\n"); return 0; }
/*---------------------------------------------------------------------------*/ int main(int argc, char *const argv[]) { struct xio_server *server; /* server portal */ char url[256]; int i; struct sigaction sa; int c; char *addr = NULL; char *port = NULL; char *trans = NULL; while (1) { c = getopt_long(argc, argv, "a:p:r:hdnV", longopts, NULL); if (c == -1) break; switch (c) { case 'a': addr = optarg; break; case 'p': port = optarg; break; case 'r': trans = optarg; break; case 'h': usage(argv[0], 0); case 'd': debug_flag++; nofork_flag++; break; case 'n': nofork_flag++; break; case 'V': printf("%s\n", PACKAGE_STRING); exit(0); break; default: usage(argv[0], 1); break; } } memset(&sa, 0, sizeof(sa)); sa.sa_handler = signal_handler; sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGQUIT, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sa.sa_handler = SIG_IGN; sa.sa_flags = SA_RESTART; sigaction(SIGPIPE, &sa, NULL); if (!nofork_flag && daemon(0, 0)) { logerr("daemon() failed"); exit(1); } if (!debug_flag) { openlog("xiosrvd", LOG_PID, LOG_DAEMON); use_syslog = 1; } /* Create the process PID file */ if (create_pidfile(pid_file) != 0) exit(EXIT_FAILURE); /* initialize library */ xio_init(); /* create "hello world" message */ memset(&server_data, 0, sizeof(server_data)); for (i = 0; i < QUEUE_DEPTH; i++) { server_data.rsp[i].out.header.iov_base = strdup("hello world header response"); server_data.rsp[i].out.header.iov_len = strlen((const char *) server_data.rsp[i].out.header.iov_base) + 1; } /* create thread context for the client */ server_data.ctx = xio_context_create(NULL, 0, -1); /* create url to connect to */ if (trans) sprintf(url, "%s://%s:%s", trans, addr, port); else sprintf(url, "rdma://%s:%s", addr, port); reload: /* bind a listener server to a portal/url */ server = xio_bind(server_data.ctx, &server_ops, url, NULL, 0, &server_data); if (server) { logit(LOG_INFO, "listen to %s", url); xio_context_run_loop(server_data.ctx, XIO_INFINITE); /* free the server */ xio_unbind(server); if (reload_flag) { reload_flag = 0; goto reload; } /* normal exit phase */ logit(LOG_INFO, "exit signaled"); } /* free the message */ for (i = 0; i < QUEUE_DEPTH; i++) free(server_data.rsp[i].out.header.iov_base); /* free the context */ xio_context_destroy(server_data.ctx); xio_shutdown(); remove_pidfile(); if (use_syslog) closelog(); return 0; }
/*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { struct xio_session *session; char url[256]; struct session_data session_data; int i = 0; struct event timeout; struct event xio_event; struct timeval tv; struct xio_poll_params poll_params; struct xio_session_params params; if (argc < 3) { printf("Usage: %s <host> <port> <transport:optional>\n", argv[0]); exit(1); } memset(&session_data, 0, sizeof(session_data)); memset(¶ms, 0, sizeof(params)); /* initialize library */ xio_init(); /* create thread context for the client */ session_data.ctx = xio_context_create(NULL, 0, -1); /* get poll parameters for libevent */ xio_context_get_poll_params(session_data.ctx, &poll_params); /* create url to connect to */ if (argc > 3) sprintf(url, "%s://%s:%s", argv[3], argv[1], argv[2]); else sprintf(url, "rdma://%s:%s", argv[1], argv[2]); params.type = XIO_SESSION_CLIENT; params.ses_ops = &ses_ops; params.user_context = &session_data; params.uri = url; session = xio_session_create(¶ms); /* connect the session */ session_data.conn = xio_connect(session, session_data.ctx, 0, NULL, &session_data); /* create "hello world" message */ for (i = 0; i < QUEUE_DEPTH; i++) { memset(&session_data.req[i], 0, sizeof(session_data.req[i])); /* header */ session_data.req[i].out.header.iov_base = strdup("hello world header request"); session_data.req[i].out.header.iov_len = strlen(session_data.req[i].out.header.iov_base) + 1; /* iovec[0]*/ session_data.req[i].out.sgl_type = XIO_SGL_TYPE_IOV; session_data.req[i].out.data_iov.max_nents = XIO_IOVLEN; session_data.req[i].out.data_iov.sglist[0].iov_base = strdup("hello world iovec request"); session_data.req[i].out.data_iov.sglist[0].iov_len = strlen(session_data.req[i].out.data_iov.sglist[0].iov_base) + 1; session_data.req[i].out.data_iov.nents = 1; } /* send first message */ for (i = 0; i < QUEUE_DEPTH; i++) { xio_send_request(session_data.conn, &session_data.req[i]); session_data.nsent++; } /* Initialize the event library */ session_data.evbase = event_base_new(); /* Initialize one timer event */ event_assign(&timeout, session_data.evbase, -1, EV_PERSIST, timeout_cb, (void *)&timeout); evutil_timerclear(&tv); tv.tv_sec = 2; event_add(&timeout, &tv); event_assign(&xio_event, session_data.evbase, poll_params.fd, EV_READ|EV_PERSIST, xio_event_handler, (void *)&poll_params); /* Add it to the active events, without a timeout */ event_add(&xio_event, NULL); event_base_dispatch(session_data.evbase); fprintf(stdout, "exit signaled\n"); event_base_free(session_data.evbase); /* free the message */ for (i = 0; i < QUEUE_DEPTH; i++) { free(session_data.req[i].out.header.iov_base); free(session_data.req[i].out.data_iov.sglist[0].iov_base); } /* free the context */ xio_context_destroy(session_data.ctx); xio_shutdown(); printf("good bye\n"); return 0; }
/*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { struct xio_server *server; /* server portal */ struct server_data server_data; char url[256]; struct xio_msg *rsp; int i, opt, optlen; struct xio_reg_mem xbuf; int msg_size = 0; int max_msg_size = 0; uint8_t *data = NULL; xbuf.addr = NULL; xbuf.mr = NULL; if (argc < 3) { printf("Usage: %s <host> <port> <transport:optional>"\ "<finite run:optional> <msg size:optional>\n", argv[0]); exit(1); } if (argc > 4) test_disconnect = atoi(argv[4]); else test_disconnect = 0; if (argc > 5) msg_size = atoi(argv[5]); /* initialize library */ xio_init(); /* get max msg size */ /* this size distinguishes between big and small msgs, where for small msgs rdma_post_send/rdma_post_recv are called as opposed to to big msgs where rdma_write/rdma_read are called */ xio_get_opt(NULL, XIO_OPTLEVEL_ACCELIO, XIO_OPTNAME_MAX_INLINE_XIO_DATA, &opt, &optlen); max_msg_size = opt; /* create "hello world" message */ memset(&server_data, 0, sizeof(server_data)); rsp = server_data.rsp_ring; for (i = 0; i < QUEUE_DEPTH; i++) { /* header */ rsp->out.header.iov_base = strdup("hello world header response"); rsp->out.header.iov_len = strlen((const char *) rsp->out.header.iov_base) + 1; rsp->out.sgl_type = XIO_SGL_TYPE_IOV; rsp->out.data_iov.max_nents = XIO_IOVLEN; /* data */ if (msg_size < max_msg_size) { /* small msgs */ rsp->out.data_iov.sglist[0].iov_base = strdup("hello world data response"); } else { /* big msgs */ if (data == NULL) { printf("allocating xio memory...\n"); xio_mem_alloc(msg_size, &xbuf); if (xbuf.addr != NULL){ data = (uint8_t *)xbuf.addr; memset(data, 0, msg_size); sprintf((char *)data, "hello world data response"); } else { printf("ERROR - xio_mem_alloc failed.\n"); exit(1); } } rsp->out.data_iov.sglist[0].mr = xbuf.mr; rsp->out.data_iov.sglist[0].iov_base = data; } rsp->out.data_iov.sglist[0].iov_len = strlen((const char *) rsp->out.data_iov.sglist[0].iov_base) + 1; rsp->out.data_iov.nents = 1; rsp++; } /* create thread context for the client */ server_data.ctx = xio_context_create(NULL, 0, -1); /* create url to connect to */ if (argc > 3) sprintf(url, "%s://%s:%s", argv[3], argv[1], argv[2]); else sprintf(url, "rdma://%s:%s", argv[1], argv[2]); /* bind a listener server to a portal/url */ server = xio_bind(server_data.ctx, &server_ops, url, NULL, 0, &server_data); if (server) { printf("listen to %s\n", url); xio_context_run_loop(server_data.ctx, XIO_INFINITE); /* normal exit phase */ fprintf(stdout, "exit signaled\n"); /* free the server */ xio_unbind(server); } /* free the message */ rsp = server_data.rsp_ring; for (i = 0; i < QUEUE_DEPTH; i++) { free(rsp->out.header.iov_base); if (msg_size < max_msg_size) free(rsp->out.data_iov.sglist[0].iov_base); rsp++; } if (data) { printf("freeing xio memory...\n"); xio_mem_free(&xbuf); xbuf.addr = NULL; } /* free the context */ xio_context_destroy(server_data.ctx); xio_shutdown(); return 0; }
void sd_xio_shutdown(void) { xio_shutdown(); }