move socket_init to qemu-sockets.c

Signed-off-by: Paolo Bonzini <[email protected]>
Signed-off-by: Aurelien Jarno <[email protected]>
diff --git a/qemu-sockets.c b/qemu-sockets.c
index 23c3def..a7399aa 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -648,3 +648,27 @@
 }
 
 #endif
+
+#ifdef _WIN32
+static void socket_cleanup(void)
+{
+    WSACleanup();
+}
+#endif
+
+int socket_init(void)
+{
+#ifdef _WIN32
+    WSADATA Data;
+    int ret, err;
+
+    ret = WSAStartup(MAKEWORD(2,2), &Data);
+    if (ret != 0) {
+        err = WSAGetLastError();
+        fprintf(stderr, "WSAStartup: %d\n", err);
+        return -1;
+    }
+    atexit(socket_cleanup);
+#endif
+    return 0;
+}