[openib-general] [PATCH 2/2] librdmacm: update test programs to use event channels
Sean Hefty
sean.hefty at intel.com
Fri May 5 14:14:06 PDT 2006
Update test programs to use the event channel interfaces.
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
Index: examples/rping.c
===================================================================
--- examples/rping.c (revision 5693)
+++ examples/rping.c (working copy)
@@ -141,6 +141,7 @@ struct rping_cb {
/* CM stuff */
pthread_t cmthread;
+ struct rdma_event_channel *cm_channel;
struct rdma_cm_id *cm_id; /* connection on client side,*/
/* listener on service side. */
struct rdma_cm_id *child_cm_id; /* connection on server side */
@@ -532,11 +533,12 @@ err1:
static void *cm_thread(void *arg)
{
+ struct rping_cb *cb = arg;
struct rdma_cm_event *event;
int ret;
while (1) {
- ret = rdma_get_cm_event(&event);
+ ret = rdma_get_cm_event(cb->cm_channel, &event);
if (ret) {
fprintf(stderr, "rdma_get_cm_event err %d\n", ret);
exit(ret);
@@ -1017,11 +1019,18 @@ int main(int argc, char *argv[])
goto out;
}
- ret = rdma_create_id(&cb->cm_id, cb);
+ cb->cm_channel = rdma_create_event_channel();
+ if (!cb->cm_channel) {
+ ret = errno;
+ fprintf(stderr, "rdma_create_event_channel error %d\n", ret);
+ goto out;
+ }
+
+ ret = rdma_create_id(cb->cm_channel, &cb->cm_id, cb);
if (ret) {
ret = errno;
fprintf(stderr, "rdma_create_id error %d\n", ret);
- goto out;
+ goto out2;
}
DEBUG_LOG("created cm_id %p\n", cb->cm_id);
@@ -1034,6 +1043,8 @@ int main(int argc, char *argv[])
DEBUG_LOG("destroy cm_id %p\n", cb->cm_id);
rdma_destroy_id(cb->cm_id);
+out2:
+ rdma_destroy_event_channel(cb->cm_channel);
out:
free(cb);
return ret;
Index: examples/cmatose.c
===================================================================
--- examples/cmatose.c (revision 6183)
+++ examples/cmatose.c (working copy)
@@ -69,6 +69,7 @@ struct cmatest_node {
};
struct cmatest {
+ struct rdma_event_channel *channel;
struct cmatest_node *nodes;
int conn_index;
int connects_left;
@@ -375,7 +376,8 @@ static int alloc_nodes(void)
for (i = 0; i < connections; i++) {
test.nodes[i].id = i;
if (!is_server) {
- ret = rdma_create_id(&test.nodes[i].cma_id,
+ ret = rdma_create_id(test.channel,
+ &test.nodes[i].cma_id,
&test.nodes[i]);
if (ret)
goto err;
@@ -424,7 +426,7 @@ static void connect_events(void)
int err = 0;
while (test.connects_left && !err) {
- err = rdma_get_cm_event(&event);
+ err = rdma_get_cm_event(test.channel, &event);
if (!err) {
cma_handler(event->id, event);
rdma_ack_cm_event(event);
@@ -438,7 +440,7 @@ static void disconnect_events(void)
int err = 0;
while (test.disconnects_left && !err) {
- err = rdma_get_cm_event(&event);
+ err = rdma_get_cm_event(test.channel, &event);
if (!err) {
cma_handler(event->id, event);
rdma_ack_cm_event(event);
@@ -452,7 +454,7 @@ static void run_server(void)
int i, ret;
printf("cmatose: starting server\n");
- ret = rdma_create_id(&listen_id, &test);
+ ret = rdma_create_id(test.channel, &listen_id, &test);
if (ret) {
printf("cmatose: listen request failed\n");
return;
@@ -582,6 +584,13 @@ int main(int argc, char **argv)
test.src_addr = (struct sockaddr *) &test.src_in;
test.connects_left = connections;
test.disconnects_left = connections;
+
+ test.channel = rdma_create_event_channel();
+ if (!test.channel) {
+ printf("failed to create event channel\n");
+ exit(1);
+ }
+
if (alloc_nodes())
exit(1);
@@ -592,5 +601,6 @@ int main(int argc, char **argv)
printf("test complete\n");
destroy_nodes();
+ rdma_destroy_event_channel(test.channel);
return 0;
}
More information about the general
mailing list