]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
rdma_client: use perror, unwind allocs on failure
authorDoug Ledford <dledford@redhat.com>
Wed, 18 Jun 2014 17:44:13 +0000 (10:44 -0700)
committerSean Hefty <sean.hefty@intel.com>
Wed, 18 Jun 2014 17:44:13 +0000 (10:44 -0700)
Our main test function prints out errno directly, which is hard to read
as it's not decoded at all.  Instead, use perror() to make failures more
readable.  Also redo the failure flow so that we can do a simple unwind
at the end of the function and just jump to the right unwind spot on
error.

Signed-off-by: Doug Ledford <dledford@redhat.com>
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
examples/rdma_client.c

index 7a59d976ce82e7104e6ca71f1ce5789cab04862d..e0e176b4bdee3527caf30ee9e843ce842681ba95 100644 (file)
@@ -54,8 +54,8 @@ static int run(void)
        hints.ai_port_space = RDMA_PS_TCP;
        ret = rdma_getaddrinfo(server, port, &hints, &res);
        if (ret) {
-               printf("rdma_getaddrinfo %d\n", errno);
-               return ret;
+               perror("rdma_getaddrinfo");
+               goto out;
        }
 
        memset(&attr, 0, sizeof attr);
@@ -65,46 +65,58 @@ static int run(void)
        attr.qp_context = id;
        attr.sq_sig_all = 1;
        ret = rdma_create_ep(&id, res, NULL, &attr);
-       rdma_freeaddrinfo(res);
        if (ret) {
-               printf("rdma_create_ep %d\n", errno);
-               return ret;
+               perror("rdma_create_ep");
+               goto out_free_addrinfo;
        }
 
        mr = rdma_reg_msgs(id, recv_msg, 16);
        if (!mr) {
-               printf("rdma_reg_msgs %d\n", errno);
-               return ret;
+               perror("rdma_reg_msgs for recv_msg");
+               ret = -1;
+               goto out_destroy_ep;
        }
 
        ret = rdma_post_recv(id, NULL, recv_msg, 16, mr);
        if (ret) {
-               printf("rdma_post_recv %d\n", errno);
-               return ret;
+               perror("rdma_post_recv");
+               goto out_dereg;
        }
 
        ret = rdma_connect(id, NULL);
        if (ret) {
-               printf("rdma_connect %d\n", errno);
-               return ret;
+               perror("rdma_connect");
+               goto out_dereg;
        }
 
        ret = rdma_post_send(id, NULL, send_msg, 16, NULL, IBV_SEND_INLINE);
        if (ret) {
-               printf("rdma_post_send %d\n", errno);
-               return ret;
+               perror("rdma_post_send");
+               goto out_disconnect;
        }
 
-       ret = rdma_get_recv_comp(id, &wc);
-       if (ret <= 0) {
-               printf("rdma_get_recv_comp %d\n", ret);
-               return ret;
+       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");
+       else
+               ret = 0;
+
+out_disconnect:
        rdma_disconnect(id);
+out_dereg:
        rdma_dereg_mr(mr);
+out_destroy_ep:
        rdma_destroy_ep(id);
-       return 0;
+out_free_addrinfo:
+       rdma_freeaddrinfo(res);
+out:
+       return ret;
 }
 
 int main(int argc, char **argv)