| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/winsock_util.h" | 5 #include "net/base/winsock_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // Prevent the compiler from optimizing away the arguments so they appear | 14 // Prevent the compiler from optimizing away the arguments so they appear |
| 15 // nicely on the stack in crash dumps. | 15 // nicely on the stack in crash dumps. |
| 16 #pragma warning(push) | 16 #pragma warning(push) |
| 17 #pragma warning (disable: 4748) | 17 #pragma warning(disable : 4748) |
| 18 #pragma optimize( "", off ) | 18 #pragma optimize("", off) |
| 19 | 19 |
| 20 // Pass the important values as function arguments so that they are available | 20 // Pass the important values as function arguments so that they are available |
| 21 // in crash dumps. | 21 // in crash dumps. |
| 22 void CheckEventWait(WSAEVENT hEvent, DWORD wait_rv, DWORD expected) { | 22 void CheckEventWait(WSAEVENT hEvent, DWORD wait_rv, DWORD expected) { |
| 23 if (wait_rv != expected) { | 23 if (wait_rv != expected) { |
| 24 DWORD err = ERROR_SUCCESS; | 24 DWORD err = ERROR_SUCCESS; |
| 25 if (wait_rv == WAIT_FAILED) | 25 if (wait_rv == WAIT_FAILED) |
| 26 err = GetLastError(); | 26 err = GetLastError(); |
| 27 CHECK(false); // Crash. | 27 CHECK(false); // Crash. |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 #pragma optimize( "", on ) | 31 #pragma optimize("", on) |
| 32 #pragma warning(pop) | 32 #pragma warning(pop) |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 void AssertEventNotSignaled(WSAEVENT hEvent) { | 36 void AssertEventNotSignaled(WSAEVENT hEvent) { |
| 37 DWORD wait_rv = WaitForSingleObject(hEvent, 0); | 37 DWORD wait_rv = WaitForSingleObject(hEvent, 0); |
| 38 CheckEventWait(hEvent, wait_rv, WAIT_TIMEOUT); | 38 CheckEventWait(hEvent, wait_rv, WAIT_TIMEOUT); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool ResetEventIfSignaled(WSAEVENT hEvent) { | 41 bool ResetEventIfSignaled(WSAEVENT hEvent) { |
| 42 // TODO(wtc): Remove the CHECKs after enough testing. | 42 // TODO(wtc): Remove the CHECKs after enough testing. |
| 43 DWORD wait_rv = WaitForSingleObject(hEvent, 0); | 43 DWORD wait_rv = WaitForSingleObject(hEvent, 0); |
| 44 if (wait_rv == WAIT_TIMEOUT) | 44 if (wait_rv == WAIT_TIMEOUT) |
| 45 return false; // The event object is not signaled. | 45 return false; // The event object is not signaled. |
| 46 CheckEventWait(hEvent, wait_rv, WAIT_OBJECT_0); | 46 CheckEventWait(hEvent, wait_rv, WAIT_OBJECT_0); |
| 47 BOOL ok = WSAResetEvent(hEvent); | 47 BOOL ok = WSAResetEvent(hEvent); |
| 48 CHECK(ok); | 48 CHECK(ok); |
| 49 return true; | 49 return true; |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace net | 52 } // namespace net |
| OLD | NEW |