summaryrefslogtreecommitdiffstats
path: root/chromium/net/base/winsock_util.h
diff options
context:
space:
mode:
authorZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
committerZeno Albisser <zeno.albisser@digia.com>2013-08-15 21:46:11 +0200
commit679147eead574d186ebf3069647b4c23e8ccace6 (patch)
treefc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/net/base/winsock_util.h
Initial import.
Diffstat (limited to 'chromium/net/base/winsock_util.h')
-rw-r--r--chromium/net/base/winsock_util.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/chromium/net/base/winsock_util.h b/chromium/net/base/winsock_util.h
new file mode 100644
index 00000000000..06ac448a817
--- /dev/null
+++ b/chromium/net/base/winsock_util.h
@@ -0,0 +1,49 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_WINSOCK_UTIL_H_
+#define NET_BASE_WINSOCK_UTIL_H_
+
+#include <winsock2.h>
+
+#include "net/base/net_export.h"
+
+namespace net {
+
+// Assert that the (manual-reset) event object is not signaled.
+void AssertEventNotSignaled(WSAEVENT hEvent);
+
+// If the (manual-reset) event object is signaled, resets it and returns true.
+// Otherwise, does nothing and returns false. Called after a Winsock function
+// succeeds synchronously
+//
+// Our testing shows that except in rare cases (when running inside QEMU),
+// the event object is already signaled at this point, so we call this method
+// to avoid a context switch in common cases. This is just a performance
+// optimization. The code still works if this function simply returns false.
+bool ResetEventIfSignaled(WSAEVENT hEvent);
+
+// Interface to create Windows Socket.
+// Usually such factories are used for testing purposes, which is not true in
+// this case. This interface is used to substitute WSASocket to make possible
+// execution of some network code in sandbox.
+class NET_EXPORT PlatformSocketFactory {
+ public:
+ PlatformSocketFactory() {}
+ virtual ~PlatformSocketFactory() {}
+
+ // Creates Windows socket. See WSASocket documentation of parameters.
+ virtual SOCKET CreateSocket(int family, int type, int protocol) = 0;
+
+ // Replace WSASocket with given factory. The factory will be used by
+ // CreatePlatformSocket.
+ static void SetInstance(PlatformSocketFactory* factory);
+};
+
+// Creates Windows Socket. See WSASocket documentation of parameters.
+SOCKET CreatePlatformSocket(int family, int type, int protocol);
+
+} // namespace net
+
+#endif // NET_BASE_WINSOCK_UTIL_H_