perftest: allow server to support both IPv6 and IPv4
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Fri, 6 Mar 2009 22:27:39 +0000 (22:27 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Fri, 6 Mar 2009 22:27:39 +0000 (22:27 +0000)
Changes based on Leonid's patch to add support for IPv6 and IPv4.  Allow the server to accept incoming connections from IPv6 and IPv4 clients.

Move connection handling code into common location to eliminate code duplication between perftest apps.

Signed-off-by: Leonid Keller <leonid@mellanox.co.il>
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2013 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

tests/perftest/perftest.c
tests/perftest/perftest.h
tests/perftest/rdma_bw/rdma_bw.c
tests/perftest/rdma_lat/rdma_lat.c
tests/perftest/read_bw/read_bw.c
tests/perftest/read_lat/read_lat.c
tests/perftest/send_bw/send_bw.c
tests/perftest/send_lat/send_lat.c
tests/perftest/write_bw/write_bw.c
tests/perftest/write_lat/write_lat.c

index 35b6327..1013663 100644 (file)
@@ -31,6 +31,8 @@
  */\r
 \r
 #include "perftest.h"\r
+#include <ws2tcpip.h>\r
+#include <stdio.h>\r
 \r
 UINT64 get_cycles()\r
 {\r
@@ -80,3 +82,93 @@ int __cdecl cycles_compare(const void * aptr, const void * bptr)
        return 0;\r
 \r
 }\r
+\r
+SOCKET pp_client_connect(const char *servername, int port)\r
+{\r
+       struct addrinfo *res, *t;\r
+       struct addrinfo hints;\r
+       char service[6];\r
+       int n;\r
+       SOCKET sockfd = INVALID_SOCKET;\r
+\r
+       memset(&hints, 0, sizeof hints);\r
+       hints.ai_family   = AF_UNSPEC;\r
+       hints.ai_socktype = SOCK_STREAM;\r
+       sprintf(service, "%d\0", port);\r
+\r
+       n = getaddrinfo(servername, service, &hints, &res);\r
+       if (n != 0) {\r
+               fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);\r
+               return INVALID_SOCKET;\r
+       }\r
+\r
+       for (t = res; t; t = t->ai_next) {\r
+               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
+               if (sockfd != INVALID_SOCKET) {\r
+                       if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
+                               break;\r
+                       closesocket(sockfd);\r
+                       sockfd = INVALID_SOCKET;\r
+               }\r
+       }\r
+\r
+       freeaddrinfo(res);\r
+\r
+       if (sockfd == INVALID_SOCKET) {\r
+               fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port);\r
+       }\r
+       return sockfd;\r
+}\r
+\r
+SOCKET pp_server_connect(int port)\r
+{\r
+       struct addrinfo *res, *t;\r
+       struct addrinfo hints;\r
+       char service[6];\r
+       SOCKET sockfd = INVALID_SOCKET, connfd;\r
+       int n;\r
+\r
+       memset(&hints, 0, sizeof hints);\r
+       hints.ai_flags    = AI_PASSIVE;\r
+       hints.ai_family   = AF_UNSPEC;\r
+       hints.ai_socktype = SOCK_STREAM;\r
+       sprintf(service, "%d\0", port);\r
+\r
+       n = getaddrinfo(NULL, service, &hints, &res);\r
+       if (n != 0) {\r
+               fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);\r
+               return INVALID_SOCKET;\r
+       }\r
+\r
+       for (t = res; t; t = t->ai_next) {\r
+               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
+               if (sockfd != INVALID_SOCKET) {\r
+                       n = 0;\r
+                       setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &n, sizeof n);\r
+                       n = 1;\r
+                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
+\r
+                       if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
+                               break;\r
+                       closesocket(sockfd);\r
+                       sockfd = INVALID_SOCKET;\r
+               }\r
+       }\r
+\r
+       freeaddrinfo(res);\r
+\r
+       if (sockfd == INVALID_SOCKET) {\r
+               fprintf(stderr, "Couldn't listen to port %d\n", port);\r
+               return INVALID_SOCKET;\r
+       }\r
+\r
+       listen(sockfd, 1);\r
+       connfd = accept(sockfd, NULL, 0);\r
+       if (connfd == INVALID_SOCKET) {\r
+               perror("server accept");\r
+               fprintf(stderr, "accept() failed\n");\r
+       }\r
+\r
+       closesocket(sockfd);\r
+       return connfd;\r
+}\r
index e0fd9c5..d06e42d 100644 (file)
  * SOFTWARE.\r
  */\r
 \r
+#ifndef _PERFTEST_H_\r
+#define _PERFTEST_H_\r
+\r
 #include <windows.h>\r
+#include <winsock2.h>\r
 \r
 typedef UINT64 cycles_t;\r
 \r
@@ -39,3 +43,8 @@ UINT64 get_freq();
 \r
 cycles_t get_median(int n, cycles_t delta[]);\r
 int __cdecl cycles_compare(const void * aptr, const void * bptr);\r
+\r
+SOCKET pp_client_connect(const char *servername, int port);\r
+SOCKET pp_server_connect(int port);\r
+\r
+#endif // _PERFTEST_H_
\ No newline at end of file
index 32afba5..c09f13d 100644 (file)
@@ -99,7 +99,7 @@ static uint16_t pp_get_local_lid(struct pingpong_context *ctx, int port)
        return attr.lid;\r
 }\r
 \r
-static struct pingpong_context *pp_client_connect(struct pp_data *data)\r
+static struct pingpong_context *pp_client_connect_cma(struct pp_data *data)\r
 {\r
        struct addrinfo *res, *t;\r
        struct addrinfo hints;\r
@@ -120,119 +120,108 @@ static struct pingpong_context *pp_client_connect(struct pp_data *data)
 \r
        if (n != 0) {\r
                fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), data->servername, data->port);\r
-               goto err4;\r
+               goto err1;\r
        }\r
 \r
-       if (data->use_cma) {\r
-               sin.sin_addr.s_addr = ((struct sockaddr_in*)res->ai_addr)->sin_addr.s_addr;\r
-               sin.sin_family = AF_INET;\r
-               sin.sin_port = htons((u_short) data->port);\r
-               if (rdma_resolve_addr(data->cm_id, NULL,\r
-                                        (struct sockaddr *)&sin, 2000)) {\r
-                       fprintf(stderr, "rdma_resolve_addr failed\n");\r
-                       goto err2;\r
-               }\r
-       \r
-               if (rdma_get_cm_event(data->cm_channel, &event)) \r
-                       goto err2;\r
+       sin.sin_addr.s_addr = ((struct sockaddr_in*)res->ai_addr)->sin_addr.s_addr;\r
+       sin.sin_family = AF_INET;\r
+       sin.sin_port = htons((u_short) data->port);\r
+       if (rdma_resolve_addr(data->cm_id, NULL,\r
+                                (struct sockaddr *)&sin, 2000)) {\r
+               fprintf(stderr, "rdma_resolve_addr failed\n");\r
+               goto err2;\r
+       }\r
 \r
-               if (event->event != RDMA_CM_EVENT_ADDR_RESOLVED) {\r
-                       fprintf(stderr, "unexpected CM event resolving addr %d\n", event->event);\r
-                       goto err1;\r
-               }\r
-               rdma_ack_cm_event(event);\r
-       \r
-               if (rdma_resolve_route(data->cm_id, 2000)) {\r
-                       fprintf(stderr, "rdma_resolve_route failed\n");\r
-                       goto err2;\r
-               }\r
-       \r
-               if (rdma_get_cm_event(data->cm_channel, &event))\r
-                       goto err2;\r
+       if (rdma_get_cm_event(data->cm_channel, &event)) \r
+               goto err2;\r
 \r
-               if (event->event != RDMA_CM_EVENT_ROUTE_RESOLVED) {\r
-                       fprintf(stderr, "unexpected CM event resolving route %d\n", event->event);\r
-                       rdma_ack_cm_event(event);\r
-                       goto err1;\r
-               }\r
-               rdma_ack_cm_event(event);\r
-               ctx = pp_init_ctx(data->cm_id, data);\r
-               if (!ctx) {\r
-                       fprintf(stderr, "pp_init_ctx failed\n");\r
-                       goto err2;\r
-               }\r
-               data->my_dest.psn = rand() & 0xffffff;\r
-               data->my_dest.qpn = 0;\r
-               data->my_dest.rkey = ctx->mr->rkey;\r
-               data->my_dest.vaddr = (uintptr_t)ctx->buf + ctx->size;\r
-       \r
-               memset(&conn_param, 0, sizeof conn_param);\r
-               conn_param.responder_resources = 1;\r
-               conn_param.initiator_depth = 1;\r
-               conn_param.retry_count = 5;\r
-               conn_param.private_data = &data->my_dest;\r
-               conn_param.private_data_len = sizeof(data->my_dest);\r
-\r
-               if (rdma_connect(data->cm_id, &conn_param)) {\r
-                       fprintf(stderr, "rdma_connect failure\n");\r
-                       goto err2;\r
-               }\r
-       \r
-               if (rdma_get_cm_event(data->cm_channel, &event))\r
-                       goto err2;\r
-       \r
-               if (event->event != RDMA_CM_EVENT_ESTABLISHED) {\r
-                       fprintf(stderr, "unexpected CM event connecting %d\n", event->event);\r
-                       goto err1;\r
-               }\r
-               if (!event->param.conn.private_data || \r
-                   (event->param.conn.private_data_len < sizeof(*data->rem_dest))) {\r
-                       fprintf(stderr, "bad private data ptr %p len %d\n",\r
-                               event->param.conn.private_data, \r
-                               event->param.conn.private_data_len);\r
-                       goto err1;\r
-               }\r
-               data->rem_dest = malloc(sizeof *data->rem_dest);\r
-               if (!data->rem_dest)\r
-                       goto err1;\r
-               \r
-               memcpy(data->rem_dest, event->param.conn.private_data, sizeof(*data->rem_dest));\r
-               rdma_ack_cm_event(event);\r
-       } else {\r
-               for (t = res; t; t = t->ai_next) {\r
-                       sockfd = socket(t->ai_family, t->ai_socktype,\r
-                                                t->ai_protocol);\r
-                       if (sockfd != INVALID_SOCKET) {\r
-                               if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
-                                       break;\r
-                               closesocket(sockfd);\r
-                               sockfd = INVALID_SOCKET;\r
-                       }\r
-               }\r
-               if (sockfd == INVALID_SOCKET) {\r
-                       fprintf(stderr, "Couldn't connect to %s:%d\n", data->servername, data->port);\r
-                       goto err3;\r
-               }\r
-               ctx = pp_init_ctx(data->ib_dev, data);\r
-               if (!ctx)\r
-                       goto err3;\r
-               data->sockfd = sockfd;\r
+       if (event->event != RDMA_CM_EVENT_ADDR_RESOLVED) {\r
+               fprintf(stderr, "unexpected CM event resolving addr %d\n", event->event);\r
+               goto err3;\r
+       }\r
+       rdma_ack_cm_event(event);\r
+\r
+       if (rdma_resolve_route(data->cm_id, 2000)) {\r
+               fprintf(stderr, "rdma_resolve_route failed\n");\r
+               goto err2;\r
        }\r
 \r
+       if (rdma_get_cm_event(data->cm_channel, &event))\r
+               goto err2;\r
+\r
+       if (event->event != RDMA_CM_EVENT_ROUTE_RESOLVED) {\r
+               fprintf(stderr, "unexpected CM event resolving route %d\n", event->event);\r
+               goto err3;\r
+       }\r
+       rdma_ack_cm_event(event);\r
+       ctx = pp_init_ctx(data->cm_id, data);\r
+       if (!ctx) {\r
+               fprintf(stderr, "pp_init_ctx failed\n");\r
+               goto err2;\r
+       }\r
+       data->my_dest.psn = rand() & 0xffffff;\r
+       data->my_dest.qpn = 0;\r
+       data->my_dest.rkey = ctx->mr->rkey;\r
+       data->my_dest.vaddr = (uintptr_t)ctx->buf + ctx->size;\r
+\r
+       memset(&conn_param, 0, sizeof conn_param);\r
+       conn_param.responder_resources = 1;\r
+       conn_param.initiator_depth = 1;\r
+       conn_param.retry_count = 5;\r
+       conn_param.private_data = &data->my_dest;\r
+       conn_param.private_data_len = sizeof(data->my_dest);\r
+\r
+       if (rdma_connect(data->cm_id, &conn_param)) {\r
+               fprintf(stderr, "rdma_connect failure\n");\r
+               goto err2;\r
+       }\r
+\r
+       if (rdma_get_cm_event(data->cm_channel, &event))\r
+               goto err2;\r
+\r
+       if (event->event != RDMA_CM_EVENT_ESTABLISHED) {\r
+               fprintf(stderr, "unexpected CM event connecting %d\n", event->event);\r
+               goto err3;\r
+       }\r
+       if (!event->param.conn.private_data || \r
+           (event->param.conn.private_data_len < sizeof(*data->rem_dest))) {\r
+               fprintf(stderr, "bad private data ptr %p len %d\n",\r
+                       event->param.conn.private_data, \r
+                       event->param.conn.private_data_len);\r
+               goto err3;\r
+       }\r
+       data->rem_dest = malloc(sizeof *data->rem_dest);\r
+       if (!data->rem_dest)\r
+               goto err3;\r
+       \r
+       memcpy(data->rem_dest, event->param.conn.private_data, sizeof(*data->rem_dest));\r
+       rdma_ack_cm_event(event);\r
        freeaddrinfo(res);\r
        return ctx;\r
 \r
-err1:\r
+err3:\r
        rdma_ack_cm_event(event);\r
 err2:\r
-       rdma_destroy_id(data->cm_id);\r
-       rdma_destroy_event_channel(data->cm_channel);\r
-err3: \r
        freeaddrinfo(res);\r
-err4\r
+err1\r
        return NULL;\r
 }\r
 \r
+static struct pingpong_context *pp_client_connect_socket(struct pp_data *data)\r
+{\r
+       data->sockfd = pp_client_connect(data->servername, data->port);\r
+       if (data->sockfd == INVALID_SOCKET) {\r
+               return NULL;\r
+       }\r
+\r
+       return pp_init_ctx(data->ib_dev, data);\r
+}\r
+\r
+static struct pingpong_context *pp_rdma_client_connect(struct pp_data *data)\r
+{\r
+       return data->use_cma ? pp_client_connect_cma(data) : pp_client_connect_socket(data);\r
+}\r
+\r
 static int pp_client_exch_dest(struct pp_data *data)\r
 {\r
        char msg[sizeof "0000:000000:000000:00000000:0000000000000000"];\r
@@ -276,14 +265,14 @@ err:
        return 1;\r
 }\r
 \r
-static struct pingpong_context *pp_server_connect(struct pp_data *data)\r
+static struct pingpong_context *pp_server_connect_cma(struct pp_data *data)\r
 {\r
        struct addrinfo *res, *t;\r
        struct addrinfo hints;\r
        char service[6];\r
        SOCKET sockfd = INVALID_SOCKET, connfd;\r
        int n;\r
-       struct rdma_cm_event *event;\r
+       struct rdma_cm_event *event, *accept_event;\r
        struct sockaddr_in sin;\r
        struct pingpong_context *ctx = NULL;\r
        struct rdma_cm_id *child_cm_id;\r
@@ -297,125 +286,101 @@ static struct pingpong_context *pp_server_connect(struct pp_data *data)
 \r
        if ( (n = getaddrinfo(NULL, service, &hints, &res)) != 0 ) {\r
                fprintf(stderr, "%s for port %d\n", gai_strerror(n), data->port);\r
-               goto err5;\r
+               goto err1;\r
        }\r
 \r
-       if (data->use_cma) {\r
-               sin.sin_addr.s_addr = 0;\r
-               sin.sin_family = AF_INET;\r
-               sin.sin_port = htons((u_short) data->port);\r
-               if (rdma_bind_addr(data->cm_id, (struct sockaddr *)&sin)) {\r
-                       fprintf(stderr, "rdma_bind_addr failed\n");\r
-                       goto err3;\r
-               }\r
-       \r
-               if (rdma_listen(data->cm_id, 0)) {\r
-                       fprintf(stderr, "rdma_listen failed\n");\r
-                       goto err3;\r
-               }\r
-       \r
-               if (rdma_get_cm_event(data->cm_channel, &event)) \r
-                       goto err3;\r
+       sin.sin_addr.s_addr = 0;\r
+       sin.sin_family = AF_INET;\r
+       sin.sin_port = htons((u_short) data->port);\r
+       if (rdma_bind_addr(data->cm_id, (struct sockaddr *)&sin)) {\r
+               fprintf(stderr, "rdma_bind_addr failed\n");\r
+               goto err2;\r
+       }\r
 \r
-               if (event->event != RDMA_CM_EVENT_CONNECT_REQUEST) {\r
-                       fprintf(stderr, "bad event waiting for connect request %d\n", event->event);\r
-                       goto err2;\r
-               }\r
-       \r
-               if (!event->param.conn.private_data ||\r
-                   (event->param.conn.private_data_len < sizeof(*data->rem_dest))) {\r
-                       fprintf(stderr, "bad private data len %d\n", event->param.conn.private_data_len);\r
-                       goto err2;\r
-               }\r
-               \r
-               data->rem_dest = malloc(sizeof *data->rem_dest);\r
-               if (!data->rem_dest)\r
-                       goto err2;\r
+       if (rdma_listen(data->cm_id, 0)) {\r
+               fprintf(stderr, "rdma_listen failed\n");\r
+               goto err2;\r
+       }\r
 \r
-               memcpy(data->rem_dest, event->param.conn.private_data, sizeof(*data->rem_dest));\r
+       if (rdma_get_cm_event(data->cm_channel, &event)) \r
+               goto err2;\r
 \r
-               child_cm_id = (struct rdma_cm_id *)event->id;\r
-               ctx = pp_init_ctx(child_cm_id, data);\r
-               if (!ctx) {\r
-                       free(data->rem_dest);\r
-                       goto err1;\r
-               }\r
-               data->my_dest.psn = rand() & 0xffffff;\r
-               data->my_dest.qpn = 0;\r
-               data->my_dest.rkey = ctx->mr->rkey;\r
-               data->my_dest.vaddr = (uintptr_t)ctx->buf + ctx->size;\r
-\r
-               memset(&conn_param, 0, sizeof conn_param);\r
-               conn_param.responder_resources = 1;\r
-               conn_param.initiator_depth = 1;\r
-               conn_param.private_data = &data->my_dest;\r
-               conn_param.private_data_len = sizeof(data->my_dest);\r
-               if (rdma_accept(child_cm_id, &conn_param)) {\r
-                       fprintf(stderr, "rdma_accept failed\n");\r
-                       goto err1;\r
-               }       \r
-               rdma_ack_cm_event(event);\r
-               if (rdma_get_cm_event(data->cm_channel, &event)) {\r
-                       fprintf(stderr, "rdma_get_cm_event error\n");\r
-                       rdma_destroy_id(child_cm_id);\r
-                       goto err3;\r
-               }\r
-               if (event->event != RDMA_CM_EVENT_ESTABLISHED) {\r
-                       fprintf(stderr, "bad event waiting for established %d\n", event->event);\r
-                       goto err1;\r
-               }\r
-               rdma_ack_cm_event(event);       \r
-       } else {\r
-               for (t = res; t; t = t->ai_next) {\r
-                       sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-                       if (sockfd != INVALID_SOCKET) {\r
-                               n = 1;\r
-       \r
-                               setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
-       \r
-                               if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
-                                       break;\r
-                               closesocket(sockfd);\r
-                               sockfd = INVALID_SOCKET;\r
-                       }\r
-               }\r
-       \r
-               if (sockfd == INVALID_SOCKET) {\r
-                       fprintf(stderr, "Couldn't listen to port %d\n", data->port);\r
-                       goto err4;\r
-               }\r
-       \r
-               listen(sockfd, 1);\r
-               connfd = accept(sockfd, NULL, 0);\r
-               if (connfd == INVALID_SOCKET) {\r
-                       perror("server accept");\r
-                       fprintf(stderr, "accept() failed\n");\r
-                       closesocket(sockfd);\r
-                       goto err4;\r
-               }\r
+       if (event->event != RDMA_CM_EVENT_CONNECT_REQUEST) {\r
+               fprintf(stderr, "bad event waiting for connect request %d\n", event->event);\r
+               goto err3;\r
+       }\r
+\r
+       if (!event->param.conn.private_data ||\r
+           (event->param.conn.private_data_len < sizeof(*data->rem_dest))) {\r
+               fprintf(stderr, "bad private data len %d\n", event->param.conn.private_data_len);\r
+               goto err3;\r
+       }\r
        \r
-               closesocket(sockfd);\r
+       child_cm_id = (struct rdma_cm_id *)event->id;\r
+       data->rem_dest = malloc(sizeof *data->rem_dest);\r
+       if (!data->rem_dest)\r
+               goto err4;\r
+\r
+       memcpy(data->rem_dest, event->param.conn.private_data, sizeof(*data->rem_dest));\r
 \r
-               ctx = pp_init_ctx(data->ib_dev, data);\r
-               if (!ctx)\r
-                       goto err4;\r
-               data->sockfd = connfd;\r
+       ctx = pp_init_ctx(child_cm_id, data);\r
+       if (!ctx) {\r
+               goto err5;\r
        }\r
+       data->my_dest.psn = rand() & 0xffffff;\r
+       data->my_dest.qpn = 0;\r
+       data->my_dest.rkey = ctx->mr->rkey;\r
+       data->my_dest.vaddr = (uintptr_t)ctx->buf + ctx->size;\r
+\r
+       memset(&conn_param, 0, sizeof conn_param);\r
+       conn_param.responder_resources = 1;\r
+       conn_param.initiator_depth = 1;\r
+       conn_param.private_data = &data->my_dest;\r
+       conn_param.private_data_len = sizeof(data->my_dest);\r
+       if (rdma_accept(child_cm_id, &conn_param)) {\r
+               fprintf(stderr, "rdma_accept failed\n");\r
+               goto err5;\r
+       }       \r
+       if (rdma_get_cm_event(data->cm_channel, &accept_event)) {\r
+               fprintf(stderr, "rdma_get_cm_event error\n");\r
+               goto err5;\r
+       }\r
+       if (accept_event->event != RDMA_CM_EVENT_ESTABLISHED) {\r
+               fprintf(stderr, "bad event waiting for established %d\n", event->event);\r
+               goto err6;\r
+       }\r
+       rdma_ack_cm_event(event);\r
+       rdma_ack_cm_event(accept_event);        \r
        freeaddrinfo(res);\r
        return ctx;\r
 \r
-err1:\r
+err6:\r
+       rdma_ack_cm_event(accept_event);\r
+err5:\r
+       free(data->rem_dest);\r
+err4:\r
        rdma_destroy_id(child_cm_id);\r
-err2:\r
-       rdma_ack_cm_event(event);\r
 err3:\r
-       rdma_destroy_id(data->cm_id);\r
-       rdma_destroy_event_channel(data->cm_channel);\r
-err4: \r
+       rdma_ack_cm_event(event);\r
+err2:\r
        freeaddrinfo(res);\r
-err5: \r
+err1:\r
        return NULL;\r
+}\r
 \r
+static struct pingpong_context *pp_server_connect_socket(struct pp_data *data)\r
+{\r
+       data->sockfd = pp_server_connect(data->port);\r
+       if (data->sockfd == INVALID_SOCKET) {\r
+               return NULL;\r
+       }\r
+\r
+       return pp_init_ctx(data->ib_dev, data);\r
+}\r
+\r
+static struct pingpong_context *pp_rdma_server_connect(struct pp_data *data)\r
+{\r
+       return data->use_cma ? pp_server_connect_cma(data) : pp_server_connect_socket(data);\r
 }\r
 \r
 static int pp_server_exch_dest(struct pp_data *data)\r
@@ -958,11 +923,11 @@ int __cdecl main(int argc, char *argv[])
                }\r
        \r
                if (data.servername) {\r
-                       ctx = pp_client_connect(&data);\r
+                       ctx = pp_rdma_client_connect(&data);\r
                        if (!ctx) \r
                                return 1;                       \r
                } else {\r
-                       ctx = pp_server_connect(&data);\r
+                       ctx = pp_rdma_server_connect(&data);\r
                        if (!ctx) \r
                                return 1;                       \r
                }\r
@@ -985,11 +950,11 @@ int __cdecl main(int argc, char *argv[])
                        }\r
                }\r
                if (data.servername) {\r
-                       ctx = pp_client_connect(&data);\r
+                       ctx = pp_rdma_client_connect(&data);\r
                        if (!ctx) \r
                                return 1;\r
                } else {\r
-                       ctx = pp_server_connect(&data);\r
+                       ctx = pp_rdma_server_connect(&data);\r
                        if (!ctx) \r
                                return 1;\r
                }\r
index 949ef0c..41be5a2 100644 (file)
@@ -177,7 +177,7 @@ static int pp_read_keys(SOCKET sockfd, const struct pingpong_dest *my_dest,
        return 0;\r
 }\r
 \r
-static struct pingpong_context *pp_client_connect(struct pp_data *data)\r
+static struct pingpong_context *pp_client_connect_cma(struct pp_data *data)\r
 {\r
        struct addrinfo *res, *t;\r
        struct addrinfo hints;\r
@@ -199,121 +199,108 @@ static struct pingpong_context *pp_client_connect(struct pp_data *data)
        if (n < 0) {\r
                fprintf(stderr, "%s for %s:%d\n",  gai_strerror(n),\r
                                data->servername, data->port);\r
-               goto err4;\r
+               goto err1;\r
        }\r
 \r
-       if (data->use_cma) {\r
-               sin.sin_addr.s_addr = ((struct sockaddr_in*)res->ai_addr)->sin_addr.s_addr;\r
-               sin.sin_family = AF_INET;\r
-               sin.sin_port = htons((u_short) data->port);\r
-               if (rdma_resolve_addr(data->cm_id, NULL,\r
-                                        (struct sockaddr *)&sin, 2000)) {\r
-                       fprintf(stderr, "rdma_resolve_addr failed\n");\r
-                       goto err2;\r
-               }\r
-       \r
-               if (rdma_get_cm_event(data->cm_channel, &event)) \r
-                       goto err2;\r
+       sin.sin_addr.s_addr = ((struct sockaddr_in*)res->ai_addr)->sin_addr.s_addr;\r
+       sin.sin_family = AF_INET;\r
+       sin.sin_port = htons((u_short) data->port);\r
+       if (rdma_resolve_addr(data->cm_id, NULL,\r
+                                (struct sockaddr *)&sin, 2000)) {\r
+               fprintf(stderr, "rdma_resolve_addr failed\n");\r
+               goto err2;\r
+       }\r
 \r
-               if (event->event != RDMA_CM_EVENT_ADDR_RESOLVED) {\r
-                       fprintf(stderr, "unexpected CM event resolving addr %d\n", event->event);\r
-                       goto err1;\r
-               }\r
-               rdma_ack_cm_event(event);\r
-       \r
-               if (rdma_resolve_route(data->cm_id, 2000)) {\r
-                       fprintf(stderr, "rdma_resolve_route failed\n");\r
-                       goto err2;\r
-               }\r
-       \r
-               if (rdma_get_cm_event(data->cm_channel, &event))\r
-                       goto err2;\r
+       if (rdma_get_cm_event(data->cm_channel, &event)) \r
+               goto err2;\r
 \r
-               if (event->event != RDMA_CM_EVENT_ROUTE_RESOLVED) {\r
-                       fprintf(stderr, "unexpected CM event resolving route %d\n", event->event);\r
-                       rdma_ack_cm_event(event);\r
-                       goto err1;\r
-               }\r
-               rdma_ack_cm_event(event);\r
-               ctx = pp_init_ctx(data->cm_id, data);\r
-               if (!ctx) {\r
-                       fprintf(stderr, "pp_init_ctx failed\n");\r
-                       goto err2;\r
-               }\r
-               data->my_dest.psn = rand() & 0xffffff;\r
-               data->my_dest.qpn = 0;\r
-               data->my_dest.rkey = ctx->mr->rkey;\r
-               data->my_dest.vaddr = (uintptr_t)ctx->buf + ctx->size;\r
-       \r
-               memset(&conn_param, 0, sizeof conn_param);\r
-               conn_param.responder_resources = 1;\r
-               conn_param.initiator_depth = 1;\r
-               conn_param.retry_count = 5;\r
-               conn_param.private_data = &data->my_dest;\r
-               conn_param.private_data_len = sizeof(data->my_dest);\r
-\r
-               if (rdma_connect(data->cm_id, &conn_param)) {\r
-                       fprintf(stderr, "rdma_connect failure\n");\r
-                       goto err2;\r
-               }\r
-       \r
-               if (rdma_get_cm_event(data->cm_channel, &event))\r
-                       goto err2;\r
-       \r
-               if (event->event != RDMA_CM_EVENT_ESTABLISHED) {\r
-                       fprintf(stderr, "unexpected CM event connecting %d\n", event->event);\r
-                       goto err1;\r
-               }\r
-               if (!event->param.conn.private_data || \r
-                   (event->param.conn.private_data_len < sizeof(*data->rem_dest))) {\r
-                       fprintf(stderr, "bad private data ptr %p len %d\n", \r
-                               event->param.conn.private_data, \r
-                               event->param.conn.private_data_len);\r
-                       goto err1;\r
-               }\r
-               data->rem_dest = malloc(sizeof *data->rem_dest);\r
-               if (!data->rem_dest)\r
-                       goto err1;\r
-               \r
-               memcpy(data->rem_dest, event->param.conn.private_data, sizeof(*data->rem_dest));\r
-               rdma_ack_cm_event(event);\r
-       } else {\r
-               for (t = res; t; t = t->ai_next) {\r
-                       sockfd = socket(t->ai_family, t->ai_socktype,\r
-                                                t->ai_protocol);\r
-                       if (sockfd != INVALID_SOCKET) {\r
-                               if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
-                                       break;\r
-                               closesocket(sockfd);\r
-                               sockfd = INVALID_SOCKET;\r
-                       }\r
-               }\r
-               if (sockfd == INVALID_SOCKET) {\r
-                       fprintf(stderr, "Couldn't connect to %s:%d\n",\r
-                               data->servername, data->port);\r
-                       goto err3;\r
-               }\r
-               ctx = pp_init_ctx(data->ib_dev, data);\r
-               if (!ctx)\r
-                       goto err3;\r
-               data->sockfd = sockfd;\r
+       if (event->event != RDMA_CM_EVENT_ADDR_RESOLVED) {\r
+               fprintf(stderr, "unexpected CM event resolving addr %d\n", event->event);\r
+               goto err3;\r
+       }\r
+       rdma_ack_cm_event(event);\r
+\r
+       if (rdma_resolve_route(data->cm_id, 2000)) {\r
+               fprintf(stderr, "rdma_resolve_route failed\n");\r
+               goto err2;\r
+       }\r
+\r
+       if (rdma_get_cm_event(data->cm_channel, &event))\r
+               goto err2;\r
+\r
+       if (event->event != RDMA_CM_EVENT_ROUTE_RESOLVED) {\r
+               fprintf(stderr, "unexpected CM event resolving route %d\n", event->event);\r
+               goto err3;\r
+       }\r
+       rdma_ack_cm_event(event);\r
+       ctx = pp_init_ctx(data->cm_id, data);\r
+       if (!ctx) {\r
+               fprintf(stderr, "pp_init_ctx failed\n");\r
+               goto err2;\r
+       }\r
+       data->my_dest.psn = rand() & 0xffffff;\r
+       data->my_dest.qpn = 0;\r
+       data->my_dest.rkey = ctx->mr->rkey;\r
+       data->my_dest.vaddr = (uintptr_t)ctx->buf + ctx->size;\r
+\r
+       memset(&conn_param, 0, sizeof conn_param);\r
+       conn_param.responder_resources = 1;\r
+       conn_param.initiator_depth = 1;\r
+       conn_param.retry_count = 5;\r
+       conn_param.private_data = &data->my_dest;\r
+       conn_param.private_data_len = sizeof(data->my_dest);\r
+\r
+       if (rdma_connect(data->cm_id, &conn_param)) {\r
+               fprintf(stderr, "rdma_connect failure\n");\r
+               goto err2;\r
        }\r
 \r
+       if (rdma_get_cm_event(data->cm_channel, &event))\r
+               goto err2;\r
+\r
+       if (event->event != RDMA_CM_EVENT_ESTABLISHED) {\r
+               fprintf(stderr, "unexpected CM event connecting %d\n", event->event);\r
+               goto err3;\r
+       }\r
+       if (!event->param.conn.private_data || \r
+           (event->param.conn.private_data_len < sizeof(*data->rem_dest))) {\r
+               fprintf(stderr, "bad private data ptr %p len %d\n", \r
+                       event->param.conn.private_data, \r
+                       event->param.conn.private_data_len);\r
+               goto err3;\r
+       }\r
+       data->rem_dest = malloc(sizeof *data->rem_dest);\r
+       if (!data->rem_dest)\r
+               goto err3;\r
+       \r
+       memcpy(data->rem_dest, event->param.conn.private_data, sizeof(*data->rem_dest));\r
+       rdma_ack_cm_event(event);\r
        freeaddrinfo(res);\r
        return ctx;\r
 \r
-err1:\r
+err3:\r
        rdma_ack_cm_event(event);\r
-err2:\r
-       rdma_destroy_id(data->cm_id);\r
-       rdma_destroy_event_channel(data->cm_channel);\r
-err3: \r
+err2: \r
        freeaddrinfo(res);\r
-err4\r
+err1\r
        return NULL;\r
 \r
 }\r
 \r
+static struct pingpong_context *pp_client_connect_socket(struct pp_data *data)\r
+{\r
+       data->sockfd = pp_client_connect(data->servername, data->port);\r
+       if (data->sockfd == INVALID_SOCKET) {\r
+               return NULL;\r
+       }\r
+\r
+       return pp_init_ctx(data->ib_dev, data);\r
+}\r
+\r
+static struct pingpong_context *pp_rdma_client_connect(struct pp_data *data)\r
+{\r
+       return data->use_cma ? pp_client_connect_cma(data) : pp_client_connect_socket(data);\r
+}\r
 \r
 static int pp_client_exch_dest(struct pp_data *data)\r
 {\r
@@ -330,14 +317,14 @@ static int pp_client_exch_dest(struct pp_data *data)
        return pp_read_keys(data->sockfd, &data->my_dest, data->rem_dest);\r
 }\r
 \r
-static struct pingpong_context *pp_server_connect(struct pp_data *data)\r
+static struct pingpong_context *pp_server_connect_cma(struct pp_data *data)\r
 {\r
        struct addrinfo *res, *t;\r
        struct addrinfo hints;\r
        char service[6];\r
        SOCKET sockfd = INVALID_SOCKET, connfd;\r
        int n;\r
-       struct rdma_cm_event *event;\r
+       struct rdma_cm_event *event, *accept_event;\r
        struct sockaddr_in sin;\r
        struct pingpong_context *ctx = NULL;\r
        struct rdma_cm_id *child_cm_id;\r
@@ -349,126 +336,103 @@ static struct pingpong_context *pp_server_connect(struct pp_data *data)
        hints.ai_socktype = SOCK_STREAM;\r
        sprintf(service, "%d", data->port);\r
 \r
-       if ( (n = getaddrinfo(NULL, service, &hints, &res)) < 0 ) {\r
+       if ( (n = getaddrinfo(NULL, service, &hints, &res)) != 0 ) {\r
                fprintf(stderr, "%s for port %d\n", gai_strerror(n), data->port);\r
-               goto err5;\r
+               goto err1;\r
        }\r
 \r
-       if (data->use_cma) {\r
-               sin.sin_addr.s_addr = 0;\r
-               sin.sin_family = AF_INET;\r
-               sin.sin_port = htons((u_short) data->port);\r
-               if (rdma_bind_addr(data->cm_id, (struct sockaddr *)&sin)) {\r
-                       fprintf(stderr, "rdma_bind_addr failed\n");\r
-                       goto err3;\r
-               }\r
-       \r
-               if (rdma_listen(data->cm_id, 0)) {\r
-                       fprintf(stderr, "rdma_listen failed\n");\r
-                       goto err3;\r
-               }\r
-       \r
-               if (rdma_get_cm_event(data->cm_channel, &event)) \r
-                       goto err3;\r
+       sin.sin_addr.s_addr = 0;\r
+       sin.sin_family = AF_INET;\r
+       sin.sin_port = htons((u_short) data->port);\r
+       if (rdma_bind_addr(data->cm_id, (struct sockaddr *)&sin)) {\r
+               fprintf(stderr, "rdma_bind_addr failed\n");\r
+               goto err2;\r
+       }\r
 \r
-               if (event->event != RDMA_CM_EVENT_CONNECT_REQUEST) {\r
-                       fprintf(stderr, "bad event waiting for connect request %d\n", event->event);\r
-                       goto err2;\r
-               }\r
-       \r
-               if (!event->param.conn.private_data ||\r
-                   (event->param.conn.private_data_len < sizeof(*data->rem_dest))) {\r
-                       fprintf(stderr, "bad private data len %d\n",\r
-                                       event->param.conn.private_data_len);\r
-                       goto err2;\r
-               }\r
-               \r
-               data->rem_dest = malloc(sizeof *data->rem_dest);\r
-               if (!data->rem_dest)\r
-                       goto err2;\r
+       if (rdma_listen(data->cm_id, 0)) {\r
+               fprintf(stderr, "rdma_listen failed\n");\r
+               goto err2;\r
+       }\r
 \r
-               memcpy(data->rem_dest, event->param.conn.private_data, sizeof(*data->rem_dest));\r
+       if (rdma_get_cm_event(data->cm_channel, &event)) \r
+               goto err2;\r
 \r
-               child_cm_id = (struct rdma_cm_id *)event->id;\r
-               ctx = pp_init_ctx(child_cm_id, data);\r
-               if (!ctx) {\r
-                       free(data->rem_dest);\r
-                       goto err1;\r
-               }\r
-               data->my_dest.psn = rand() & 0xffffff;\r
-               data->my_dest.qpn = 0;\r
-               data->my_dest.rkey = ctx->mr->rkey;\r
-               data->my_dest.vaddr = (uintptr_t)ctx->buf + ctx->size;\r
-\r
-               memset(&conn_param, 0, sizeof conn_param);\r
-               conn_param.responder_resources = 1;\r
-               conn_param.initiator_depth = 1;\r
-               conn_param.private_data = &data->my_dest;\r
-               conn_param.private_data_len = sizeof(data->my_dest);\r
-               if (rdma_accept(child_cm_id, &conn_param)) {\r
-                       fprintf(stderr, "rdma_accept failed\n");\r
-                       goto err1;\r
-               }       \r
-               rdma_ack_cm_event(event);\r
-               if (rdma_get_cm_event(data->cm_channel, &event)) {\r
-                       fprintf(stderr, "rdma_get_cm_event error\n");\r
-                       rdma_destroy_id(child_cm_id);\r
-                       goto err3;\r
-               }\r
-               if (event->event != RDMA_CM_EVENT_ESTABLISHED) {\r
-                       fprintf(stderr, "bad event waiting for established %d\n", event->event);\r
-                       goto err1;\r
-               }\r
-               rdma_ack_cm_event(event);       \r
-       } else {\r
-               for (t = res; t; t = t->ai_next) {\r
-                       sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-                       if (sockfd != INVALID_SOCKET) {\r
-                               n = 1;\r
-       \r
-                               if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
-                                       break;\r
-                               closesocket(sockfd);\r
-                               sockfd = INVALID_SOCKET;\r
-                       }\r
-               }\r
-       \r
-               if (sockfd == INVALID_SOCKET) {\r
-                       fprintf(stderr, "Couldn't listen to port %d\n", data->port);\r
-                       goto err4;\r
-               }\r
-       \r
-               listen(sockfd, 1);\r
-               connfd = accept(sockfd, NULL, 0);\r
-               if (connfd == INVALID_SOCKET) {\r
-                       perror("server accept");\r
-                       fprintf(stderr, "accept() failed\n");\r
-                       closesocket(sockfd);\r
-                       goto err4;\r
-               }\r
+       if (event->event != RDMA_CM_EVENT_CONNECT_REQUEST) {\r
+               fprintf(stderr, "bad event waiting for connect request %d\n", event->event);\r
+               goto err3;\r
+       }\r
+\r
+       if (!event->param.conn.private_data ||\r
+           (event->param.conn.private_data_len < sizeof(*data->rem_dest))) {\r
+               fprintf(stderr, "bad private data len %d\n", event->param.conn.private_data_len);\r
+               goto err3;\r
+       }\r
        \r
-               closesocket(sockfd);\r
+       child_cm_id = (struct rdma_cm_id *)event->id;\r
+       data->rem_dest = malloc(sizeof *data->rem_dest);\r
+       if (!data->rem_dest)\r
+               goto err4;\r
+\r
+       memcpy(data->rem_dest, event->param.conn.private_data, sizeof(*data->rem_dest));\r
+\r
+       ctx = pp_init_ctx(child_cm_id, data);\r
+       if (!ctx) {\r
+               goto err5;\r
+       }\r
+       data->my_dest.psn = rand() & 0xffffff;\r
+       data->my_dest.qpn = 0;\r
+       data->my_dest.rkey = ctx->mr->rkey;\r
+       data->my_dest.vaddr = (uintptr_t)ctx->buf + ctx->size;\r
 \r
-               ctx = pp_init_ctx(data->ib_dev, data);\r
-               if (!ctx)\r
-                       goto err4;\r
-               data->sockfd = connfd;\r
+       memset(&conn_param, 0, sizeof conn_param);\r
+       conn_param.responder_resources = 1;\r
+       conn_param.initiator_depth = 1;\r
+       conn_param.private_data = &data->my_dest;\r
+       conn_param.private_data_len = sizeof(data->my_dest);\r
+       if (rdma_accept(child_cm_id, &conn_param)) {\r
+               fprintf(stderr, "rdma_accept failed\n");\r
+               goto err5;\r
+       }       \r
+       if (rdma_get_cm_event(data->cm_channel, &accept_event)) {\r
+               fprintf(stderr, "rdma_get_cm_event error\n");\r
+               goto err5;\r
+       }\r
+       if (accept_event->event != RDMA_CM_EVENT_ESTABLISHED) {\r
+               fprintf(stderr, "bad event waiting for established %d\n", event->event);\r
+               goto err6;\r
        }\r
+       rdma_ack_cm_event(event);\r
+       rdma_ack_cm_event(accept_event);\r
        freeaddrinfo(res);\r
        return ctx;\r
 \r
-err1:\r
+err6:\r
+       rdma_ack_cm_event(accept_event);\r
+err5:\r
+       free(data->rem_dest);\r
+err4:\r
        rdma_destroy_id(child_cm_id);\r
-err2:\r
-       rdma_ack_cm_event(event);\r
 err3:\r
-       rdma_destroy_id(data->cm_id);\r
-       rdma_destroy_event_channel(data->cm_channel);\r
-err4: \r
+       rdma_ack_cm_event(event);\r
+err2:\r
        freeaddrinfo(res);\r
-err5: \r
+err1:\r
        return NULL;\r
+}\r
 \r
+static struct pingpong_context *pp_server_connect_socket(struct pp_data *data)\r
+{\r
+       data->sockfd = pp_server_connect(data->port);\r
+       if (data->sockfd == INVALID_SOCKET) {\r
+               return NULL;\r
+       }\r
+\r
+       return pp_init_ctx(data->ib_dev, data);\r
+}\r
+\r
+static struct pingpong_context *pp_rdma_server_connect(struct pp_data *data)\r
+{\r
+       return data->use_cma ? pp_server_connect_cma(data) : pp_server_connect_socket(data);\r
 }\r
 \r
 static int pp_server_exch_dest(struct pp_data *data)\r
@@ -1049,11 +1013,11 @@ int __cdecl main(int argc, char *argv[])
                }\r
        \r
                if (data.servername) {\r
-                       ctx = pp_client_connect(&data);\r
+                       ctx = pp_rdma_client_connect(&data);\r
                        if (!ctx) \r
                                return 1;                       \r
                } else {\r
-                       ctx = pp_server_connect(&data);\r
+                       ctx = pp_rdma_server_connect(&data);\r
                        if (!ctx) \r
                                return 1;                       \r
                }\r
@@ -1080,11 +1044,11 @@ int __cdecl main(int argc, char *argv[])
                        return 7;\r
        \r
                if (data.servername) {\r
-                       ctx = pp_client_connect(&data);\r
+                       ctx = pp_rdma_client_connect(&data);\r
                        if (!ctx) \r
                                return 8;\r
                } else {\r
-                       ctx = pp_server_connect(&data);\r
+                       ctx = pp_rdma_server_connect(&data);\r
                        if (!ctx) \r
                                return 8;\r
                }\r
index d3013ab..6213717 100644 (file)
@@ -92,45 +92,6 @@ static uint16_t pp_get_local_lid(struct pingpong_context *ctx, int port)
        return attr.lid;\r
 }\r
 \r
-static SOCKET pp_client_connect(const char *servername, int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       int n;\r
-       SOCKET sockfd = INVALID_SOCKET;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(servername, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port);\r
-               return sockfd;\r
-       }\r
-       return sockfd;\r
-}\r
-\r
 static struct pingpong_dest * pp_client_exch_dest(SOCKET sockfd,\r
                                           const struct pingpong_dest *my_dest)\r
 {\r
@@ -171,61 +132,6 @@ out:
        return rem_dest;\r
 }\r
 \r
-static SOCKET pp_server_connect(int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       SOCKET sockfd = INVALID_SOCKET, connfd;\r
-       int n;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_flags    = AI_PASSIVE;\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(NULL, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       n = 1;\r
-\r
-                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
-\r
-                       if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't listen to port %d\n", port);\r
-               return sockfd;\r
-       }\r
-\r
-       listen(sockfd, 1);\r
-       connfd = accept(sockfd, NULL, 0);\r
-       if (connfd == INVALID_SOCKET) {\r
-               perror("server accept");\r
-               fprintf(stderr, "accept() failed\n");\r
-               closesocket(sockfd);\r
-               return connfd;\r
-       }\r
-\r
-       closesocket(sockfd);\r
-       return connfd;\r
-}\r
-\r
 static struct pingpong_dest *pp_server_exch_dest(SOCKET connfd, const struct pingpong_dest *my_dest)\r
 {\r
        char msg[sizeof "0000:000000:000000:00000000:0000000000000000"];\r
index e5062a4..0d33407 100644 (file)
@@ -167,45 +167,6 @@ static int pp_read_keys(SOCKET sockfd, const struct pingpong_dest *my_dest,
        return 0;\r
 }\r
 \r
-static SOCKET pp_client_connect(const char *servername, int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       int n;\r
-       SOCKET sockfd = INVALID_SOCKET;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(servername, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port);\r
-               return sockfd;\r
-       }\r
-       return sockfd;\r
-}\r
-\r
 static int pp_client_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_dest,\r
                               struct pingpong_dest *rem_dest)\r
 {\r
@@ -215,61 +176,6 @@ static int pp_client_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_des
        return pp_read_keys(sockfd, my_dest, rem_dest);\r
 }\r
 \r
-static SOCKET pp_server_connect(int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       SOCKET sockfd = INVALID_SOCKET, connfd;\r
-       int n;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_flags    = AI_PASSIVE;\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(NULL, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       n = 1;\r
-\r
-                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
-\r
-                       if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't listen to port %d\n", port);\r
-               return sockfd;\r
-       }\r
-\r
-       listen(sockfd, 1);\r
-       connfd = accept(sockfd, NULL, 0);\r
-       if (connfd == INVALID_SOCKET) {\r
-               perror("server accept");\r
-               fprintf(stderr, "accept() failed\n");\r
-               closesocket(sockfd);\r
-               return connfd;\r
-       }\r
-\r
-       closesocket(sockfd);\r
-       return connfd;\r
-}\r
-\r
 static int pp_server_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_dest,\r
                               struct pingpong_dest* rem_dest)\r
 {\r
index d3fa8b5..3a736d8 100644 (file)
@@ -107,45 +107,6 @@ static uint16_t pp_get_local_lid(struct pingpong_context *ctx, int port)
        return attr.lid;\r
 }\r
 \r
-static SOCKET pp_client_connect(const char *servername, int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       int n;\r
-       SOCKET sockfd = INVALID_SOCKET;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(servername, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port);\r
-               return sockfd;\r
-       }\r
-       return sockfd;\r
-}\r
-\r
 static struct pingpong_dest * pp_client_exch_dest(SOCKET sockfd,\r
                                           const struct pingpong_dest *my_dest)\r
 {\r
@@ -186,61 +147,6 @@ out:
        return rem_dest;\r
 }\r
 \r
-static SOCKET pp_server_connect(int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       SOCKET sockfd = INVALID_SOCKET, connfd;\r
-       int n;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_flags    = AI_PASSIVE;\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(NULL, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       n = 1;\r
-\r
-                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
-\r
-                       if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't listen to port %d\n", port);\r
-               return sockfd;\r
-       }\r
-\r
-       listen(sockfd, 1);\r
-       connfd = accept(sockfd, NULL, 0);\r
-       if (connfd == INVALID_SOCKET) {\r
-               perror("server accept");\r
-               fprintf(stderr, "accept() failed\n");\r
-               closesocket(sockfd);\r
-               return connfd;\r
-       }\r
-\r
-       closesocket(sockfd);\r
-       return connfd;\r
-}\r
-\r
 static struct pingpong_dest *pp_server_exch_dest(SOCKET connfd, const struct pingpong_dest *my_dest)\r
 {\r
        char msg[sizeof "0000:000000:000000:00000000:0000000000000000"];\r
index 05bd130..5795803 100644 (file)
@@ -178,45 +178,6 @@ static int pp_read_keys(SOCKET sockfd, const struct pingpong_dest *my_dest,
        return 0;\r
 }\r
 \r
-static SOCKET pp_client_connect(const char *servername, int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       int n;\r
-       SOCKET sockfd = INVALID_SOCKET;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(servername, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port);\r
-               return sockfd;\r
-       }\r
-       return sockfd;\r
-}\r
-\r
 static int pp_client_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_dest,\r
                               struct pingpong_dest *rem_dest)\r
 {\r
@@ -226,61 +187,6 @@ static int pp_client_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_des
        return pp_read_keys(sockfd, my_dest, rem_dest);\r
 }\r
 \r
-static SOCKET pp_server_connect(int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       SOCKET sockfd = INVALID_SOCKET, connfd;\r
-       int n;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_flags    = AI_PASSIVE;\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(NULL, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       n = 1;\r
-\r
-                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
-\r
-                       if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't listen to port %d\n", port);\r
-               return sockfd;\r
-       }\r
-\r
-       listen(sockfd, 1);\r
-       connfd = accept(sockfd, NULL, 0);\r
-       if (connfd == INVALID_SOCKET) {\r
-               perror("server accept");\r
-               fprintf(stderr, "accept() failed\n");\r
-               closesocket(sockfd);\r
-               return connfd;\r
-       }\r
-\r
-       closesocket(sockfd);\r
-       return connfd;\r
-}\r
-\r
 static int pp_server_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_dest,\r
                               struct pingpong_dest* rem_dest)\r
 {\r
index 15fd27b..194899f 100644 (file)
@@ -101,45 +101,6 @@ static uint16_t pp_get_local_lid(struct pingpong_context *ctx, int port)
        return attr.lid;\r
 }\r
 \r
-static SOCKET pp_client_connect(const char *servername, int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       int n;\r
-       SOCKET sockfd = INVALID_SOCKET;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(servername, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port);\r
-               return sockfd;\r
-       }\r
-       return sockfd;\r
-}\r
-\r
 static struct pingpong_dest * pp_client_exch_dest(SOCKET sockfd,\r
                                           const struct pingpong_dest *my_dest)\r
 {\r
@@ -180,61 +141,6 @@ out:
        return rem_dest;\r
 }\r
 \r
-static SOCKET pp_server_connect(int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       SOCKET sockfd = INVALID_SOCKET, connfd;\r
-       int n;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_flags    = AI_PASSIVE;\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(NULL, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       n = 1;\r
-\r
-                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
-\r
-                       if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't listen to port %d\n", port);\r
-               return sockfd;\r
-       }\r
-\r
-       listen(sockfd, 1);\r
-       connfd = accept(sockfd, NULL, 0);\r
-       if (connfd == INVALID_SOCKET) {\r
-               perror("server accept");\r
-               fprintf(stderr, "accept() failed\n");\r
-               closesocket(sockfd);\r
-               return connfd;\r
-       }\r
-\r
-       closesocket(sockfd);\r
-       return connfd;\r
-}\r
-\r
 static struct pingpong_dest *pp_server_exch_dest(SOCKET connfd, const struct pingpong_dest *my_dest)\r
 {\r
        char msg[sizeof "0000:000000:000000:00000000:0000000000000000"];\r
index 81f5cfc..af7d782 100644 (file)
@@ -164,45 +164,6 @@ static int pp_read_keys(SOCKET sockfd, const struct pingpong_dest *my_dest,
        return 0;\r
 }\r
 \r
-static SOCKET pp_client_connect(const char *servername, int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       int n;\r
-       SOCKET sockfd = INVALID_SOCKET;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(servername, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for %s:%d\n", gai_strerror(n), servername, port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       if (!connect(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't connect to %s:%d\n", servername, port);\r
-               return sockfd;\r
-       }\r
-       return sockfd;\r
-}\r
-\r
 static int pp_client_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_dest,\r
                               struct pingpong_dest *rem_dest)\r
 {\r
@@ -212,61 +173,6 @@ static int pp_client_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_des
        return pp_read_keys(sockfd, my_dest, rem_dest);\r
 }\r
 \r
-static SOCKET pp_server_connect(int port)\r
-{\r
-       struct addrinfo *res, *t;\r
-       struct addrinfo hints;\r
-       char service[6];\r
-       SOCKET sockfd = INVALID_SOCKET, connfd;\r
-       int n;\r
-\r
-       memset(&hints, 0, sizeof hints);\r
-       hints.ai_flags    = AI_PASSIVE;\r
-       hints.ai_family   = AF_UNSPEC;\r
-       hints.ai_socktype = SOCK_STREAM;\r
-       sprintf(service, "%d\0", port);\r
-\r
-       n = getaddrinfo(NULL, service, &hints, &res);\r
-\r
-       if (n != 0) {\r
-               fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);\r
-               return n;\r
-       }\r
-\r
-       for (t = res; t; t = t->ai_next) {\r
-               sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);\r
-               if (sockfd != INVALID_SOCKET) {\r
-                       n = 1;\r
-\r
-                       setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof n);\r
-\r
-                       if (!bind(sockfd, t->ai_addr, t->ai_addrlen))\r
-                               break;\r
-                       closesocket(sockfd);\r
-                       sockfd = INVALID_SOCKET;\r
-               }\r
-       }\r
-\r
-       freeaddrinfo(res);\r
-\r
-       if (sockfd == INVALID_SOCKET) {\r
-               fprintf(stderr, "Couldn't listen to port %d\n", port);\r
-               return sockfd;\r
-       }\r
-\r
-       listen(sockfd, 1);\r
-       connfd = accept(sockfd, NULL, 0);\r
-       if (connfd == INVALID_SOCKET) {\r
-               perror("server accept");\r
-               fprintf(stderr, "accept() failed\n");\r
-               closesocket(sockfd);\r
-               return connfd;\r
-       }\r
-\r
-       closesocket(sockfd);\r
-       return connfd;\r
-}\r
-\r
 static int pp_server_exch_dest(SOCKET sockfd, const struct pingpong_dest *my_dest,\r
                               struct pingpong_dest* rem_dest)\r
 {\r