Windows should animate when they are about to get docked at screen edges.
[chromium-blink-merge.git] / net / base / winsock_util.cc
blob5e5c312d385ce2705453f93a248eb85545655574
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/base/winsock_util.h"
7 #include "base/logging.h"
8 #include "net/base/net_errors.h"
10 namespace net {
12 namespace {
14 // Prevent the compiler from optimizing away the arguments so they appear
15 // nicely on the stack in crash dumps.
16 #pragma warning(push)
17 #pragma warning (disable: 4748)
18 #pragma optimize( "", off )
20 // Pass the important values as function arguments so that they are available
21 // in crash dumps.
22 void CheckEventWait(WSAEVENT hEvent, DWORD wait_rv, DWORD expected) {
23 if (wait_rv != expected) {
24 DWORD err = ERROR_SUCCESS;
25 if (wait_rv == WAIT_FAILED)
26 err = GetLastError();
27 CHECK(false); // Crash.
31 #pragma optimize( "", on )
32 #pragma warning(pop)
34 net::PlatformSocketFactory* g_socket_factory = NULL;
36 } // namespace
38 void AssertEventNotSignaled(WSAEVENT hEvent) {
39 DWORD wait_rv = WaitForSingleObject(hEvent, 0);
40 CheckEventWait(hEvent, wait_rv, WAIT_TIMEOUT);
43 bool ResetEventIfSignaled(WSAEVENT hEvent) {
44 // TODO(wtc): Remove the CHECKs after enough testing.
45 DWORD wait_rv = WaitForSingleObject(hEvent, 0);
46 if (wait_rv == WAIT_TIMEOUT)
47 return false; // The event object is not signaled.
48 CheckEventWait(hEvent, wait_rv, WAIT_OBJECT_0);
49 BOOL ok = WSAResetEvent(hEvent);
50 CHECK(ok);
51 return true;
54 void PlatformSocketFactory::SetInstance(PlatformSocketFactory* factory) {
55 g_socket_factory = factory;
58 SOCKET CreatePlatformSocket(int family, int type, int protocol) {
59 if (g_socket_factory)
60 return g_socket_factory->CreateSocket(family, type, protocol);
61 else
62 return ::WSASocket(family, type, protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
65 } // namespace net