[ovs-dev] [PATCH 02/16] socket-util-windows: Make WSAStartup available outside stream.c.
Gurucharan Shetty
shettyg at nicira.com
Fri May 30 19:06:10 UTC 2014
There are a couple of upcoming users.
Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
lib/automake.mk | 1 +
lib/socket-util-windows.c | 41 +++++++++++++++++++++++++++++++++++++++++
lib/socket-util.h | 2 ++
lib/stream.c | 21 ---------------------
4 files changed, 44 insertions(+), 21 deletions(-)
create mode 100644 lib/socket-util-windows.c
diff --git a/lib/automake.mk b/lib/automake.mk
index dc2ca0e..70436cf 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -251,6 +251,7 @@ lib_libopenvswitch_la_SOURCES += \
lib/getrusage-windows.c \
lib/latch-windows.c \
lib/route-table-stub.c \
+ lib/socket-util-windows.c \
lib/strsep.c \
lib/stream-fd-windows.c
else
diff --git a/lib/socket-util-windows.c b/lib/socket-util-windows.c
new file mode 100644
index 0000000..1cd8aa6
--- /dev/null
+++ b/lib/socket-util-windows.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2014 Nicira, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <config.h>
+#include "ovs-thread.h"
+#include "socket-util.h"
+#include "vlog.h"
+
+VLOG_DEFINE_THIS_MODULE(socket_util_windows);
+
+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()));
+ }
+}
+
+void
+winsock_start(void)
+{
+ static pthread_once_t once = PTHREAD_ONCE_INIT;
+ pthread_once(&once, do_winsock_start);
+}
diff --git a/lib/socket-util.h b/lib/socket-util.h
index 3db9a89..a058ff3 100644
--- a/lib/socket-util.h
+++ b/lib/socket-util.h
@@ -110,6 +110,8 @@ static inline int rpl_getsockopt(int sock, int level, int optname,
{
return (getsockopt)(sock, level, optname, optval, optlen);
}
+
+void winsock_start(void);
#endif
/* In Windows platform, errno is not set for socket calls.
diff --git a/lib/stream.c b/lib/stream.c
index 55632fe..c24bfe4 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)
--
1.7.9.5
More information about the dev
mailing list