From: Gurucharan Shetty Date: Mon, 17 Mar 2014 16:28:07 +0000 (-0700) Subject: stream: Call WSAStartup() before calling any winsock functions. X-Git-Tag: sliver-openvswitch-2.2.90-1~6^2~85 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=26e1fdc46c820354fe1345cb0c56b6fb77b04492;p=sliver-openvswitch.git stream: Call WSAStartup() before calling any winsock functions. 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 Acked-by: Ben Pfaff --- diff --git a/lib/stream.c b/lib/stream.c index 1dfecf060..fa5b6d604 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -31,9 +31,11 @@ #include "ofpbuf.h" #include "openflow/nicira-ext.h" #include "openflow/openflow.h" +#include "ovs-thread.h" #include "packets.h" #include "poll-loop.h" #include "random.h" +#include "socket-util.h" #include "util.h" #include "vlog.h" @@ -69,6 +71,27 @@ static const struct pstream_class *pstream_classes[] = { #endif }; +#ifdef _WIN32 +static void +do_winsock_start(void) +{ + WSADATA wsaData; + int error; + + error = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (error != 0) { + VLOG_FATAL("WSAStartup failed: %s", sock_strerror(sock_errno())); + } +} + +static void +winsock_start(void) +{ + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, do_winsock_start); +} +#endif + /* Check the validity of the stream class structures. */ static void check_stream_classes(void) @@ -207,6 +230,10 @@ stream_open(const char *name, struct stream **streamp, uint8_t dscp) COVERAGE_INC(stream_open); +#ifdef _WIN32 + winsock_start(); +#endif + /* Look up the class. */ error = stream_lookup_class(name, &class); if (!class) { @@ -497,6 +524,10 @@ pstream_open(const char *name, struct pstream **pstreamp, uint8_t dscp) COVERAGE_INC(pstream_open); +#ifdef _WIN32 + winsock_start(); +#endif + /* Look up the class. */ error = pstream_lookup_class(name, &class); if (!class) {