\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
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
\r
free(rai);\r
}\r
+ ucma_shutdown();\r
}\r