]> git.openfabrics.org - ~shefty/rdma-win.git/commitdiff
librdmacm: initialize wsa
authorSean Hefty <sean.hefty@intel.com>
Mon, 16 Aug 2010 22:03:51 +0000 (15:03 -0700)
committerSean Hefty <sean.hefty@intel.com>
Mon, 16 Aug 2010 22:03:51 +0000 (15:03 -0700)
trunk/ulp/librdmacm/src/addrinfo.cpp

index b9642fe623bbbc95a98d7f75803ef0c8cc8ec726..cc848c2abf40818358ea6e9f1f358a68d769c307 100644 (file)
 \r
 #include <windows.h>\r
 #include <winsock2.h>\r
+#include <stdio.h>\r
 \r
 #include "cma.h"\r
 #include <rdma/rdma_cma.h>\r
 #include <rdma/rdma_verbs.h>\r
 \r
+static DWORD addr_ref;\r
+\r
+static void ucma_startup(void)\r
+{\r
+       WSADATA wsadata;\r
+\r
+       EnterCriticalSection(&lock);\r
+       if (addr_ref++) {\r
+               goto out;\r
+       }\r
+\r
+       if (WSAStartup(MAKEWORD(2, 2), &wsadata)) {\r
+               addr_ref--;\r
+       }\r
+\r
+out:\r
+       LeaveCriticalSection(&lock);\r
+}\r
+\r
+static void ucma_shutdown(void)\r
+{\r
+       EnterCriticalSection(&lock);\r
+       if (--addr_ref == 0) {\r
+               WSACleanup();\r
+       }\r
+       LeaveCriticalSection(&lock);\r
+}\r
+\r
 static void ucma_convert_to_ai(struct addrinfo *ai, struct rdma_addrinfo *rai)\r
 {\r
        memset(ai, 0, sizeof *ai);\r
@@ -136,12 +165,13 @@ int rdma_getaddrinfo(char *node, char *service,
        struct addrinfo *ai;\r
        int ret;\r
 \r
+       ucma_startup();\r
        if (hints)\r
                ucma_convert_to_ai(&ai_hints, hints);\r
 \r
        ret = getaddrinfo(node, service, &ai_hints, &ai);\r
        if (ret)\r
-               return ret;\r
+               return rdmaw_wsa_errno(ret);\r
 \r
        rai = (struct rdma_addrinfo *) malloc(sizeof(*rai));\r
        if (!rai) {\r
@@ -208,4 +238,5 @@ void rdma_freeaddrinfo(struct rdma_addrinfo *res)
 \r
                free(rai);\r
        }\r
+       ucma_shutdown();\r
 }\r