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"
14 // Prevent the compiler from optimizing away the arguments so they appear
15 // nicely on the stack in crash dumps.
17 #pragma warning (disable: 4748)
18 #pragma optimize( "", off )
20 // Pass the important values as function arguments so that they are available
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
)
27 CHECK(false); // Crash.
31 #pragma optimize( "", on )
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
);