[ovs-dev] [PATCH v2 1/7] util: Make WSAStartup available outside stream.c.
Gurucharan Shetty
shettyg at nicira.com
Fri Jun 13 14:40:00 UTC 2014
WSAStartup() needs to be called before using winsock2 related
functions. We need this for almost all the utilities. So call
it through OVS_CONSTRUCTOR.
Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
lib/stream.c | 29 -----------------------------
lib/util.c | 11 +++++++++++
2 files changed, 11 insertions(+), 29 deletions(-)
diff --git a/lib/stream.c b/lib/stream.c
index 55632fe..4e512da 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -75,27 +75,6 @@ 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)
@@ -234,10 +213,6 @@ 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) {
@@ -528,10 +503,6 @@ 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) {
diff --git a/lib/util.c b/lib/util.c
index 74dc889..830cf4f 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -32,6 +32,7 @@
#include "coverage.h"
#include "ovs-rcu.h"
#include "ovs-thread.h"
+#include "socket-util.h"
#include "vlog.h"
#ifdef HAVE_PTHREAD_SET_NAME_NP
#include <pthread_np.h>
@@ -1803,4 +1804,14 @@ ftruncate(int fd, off_t length)
}
return 0;
}
+
+OVS_CONSTRUCTOR(winsock_start) {
+ WSADATA wsaData;
+ int error;
+
+ error = WSAStartup(MAKEWORD(2, 2), &wsaData);
+ if (error != 0) {
+ VLOG_FATAL("WSAStartup failed: %s", sock_strerror(sock_errno()));
+ }
+}
#endif
--
1.7.9.5
More information about the dev
mailing list