The WSAStartup function initiates use of the Winsock DLL by a process.
The function should be called before any winsock related functions
are called.

Since, we use stream-fd-windows through pstream_open or stream_open
add the WSAStartup() call there.

The current version of the Windows Sockets specification is version 2.2

Signed-off-by: Gurucharan Shetty <gshe...@nicira.com>
---
 lib/stream.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/lib/stream.c b/lib/stream.c
index 1dfecf0..ea93d72 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -34,6 +34,7 @@
 #include "packets.h"
 #include "poll-loop.h"
 #include "random.h"
+#include "socket-util.h"
 #include "util.h"
 #include "vlog.h"
 
@@ -69,6 +70,26 @@ static const struct pstream_class *pstream_classes[] = {
 #endif
 };
 
+#ifdef _WIN32
+static int winsock_init;
+
+static void
+winsock_start()
+{
+    if (!winsock_init) {
+        WSADATA wsaData;
+        int error;
+
+        error = WSAStartup(MAKEWORD(2, 2), &wsaData);
+        if (error != 0) {
+            VLOG_FATAL("WSAStartup failed: %s", sock_strerror(sock_errno()));
+        }
+
+        winsock_init = 1;
+    }
+}
+#endif
+
 /* Check the validity of the stream class structures. */
 static void
 check_stream_classes(void)
@@ -207,6 +228,12 @@ stream_open(const char *name, struct stream **streamp, 
uint8_t dscp)
 
     COVERAGE_INC(stream_open);
 
+#ifdef _WIN32
+    if (!winsock_init) {
+        winsock_start();
+    }
+#endif
+
     /* Look up the class. */
     error = stream_lookup_class(name, &class);
     if (!class) {
@@ -497,6 +524,12 @@ pstream_open(const char *name, struct pstream **pstreamp, 
uint8_t dscp)
 
     COVERAGE_INC(pstream_open);
 
+#ifdef _WIN32
+    if (!winsock_init) {
+        winsock_start();
+    }
+#endif
+
     /* Look up the class. */
     error = pstream_lookup_class(name, &class);
     if (!class) {
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to