Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / base / winsock_util.cc
blob5522e2719a549e9d0fdc6d557df63f3d715d5964
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 } // namespace
36 void AssertEventNotSignaled(WSAEVENT hEvent) {
37 DWORD wait_rv = WaitForSingleObject(hEvent, 0);
38 CheckEventWait(hEvent, wait_rv, WAIT_TIMEOUT);
41 bool ResetEventIfSignaled(WSAEVENT hEvent) {
42 // TODO(wtc): Remove the CHECKs after enough testing.
43 DWORD wait_rv = WaitForSingleObject(hEvent, 0);
44 if (wait_rv == WAIT_TIMEOUT)
45 return false; // The event object is not signaled.
46 CheckEventWait(hEvent, wait_rv, WAIT_OBJECT_0);
47 BOOL ok = WSAResetEvent(hEvent);
48 CHECK(ok);
49 return true;
52 } // namespace net