This source file includes following definitions.
- CheckEventWait
- AssertEventNotSignaled
- ResetEventIfSignaled
#include "net/base/winsock_util.h"
#include "base/logging.h"
#include "net/base/net_errors.h"
namespace net {
namespace {
#pragma warning(push)
#pragma warning (disable: 4748)
#pragma optimize( "", off )
void CheckEventWait(WSAEVENT hEvent, DWORD wait_rv, DWORD expected) {
if (wait_rv != expected) {
DWORD err = ERROR_SUCCESS;
if (wait_rv == WAIT_FAILED)
err = GetLastError();
CHECK(false);
}
}
#pragma optimize( "", on )
#pragma warning(pop)
}
void AssertEventNotSignaled(WSAEVENT hEvent) {
DWORD wait_rv = WaitForSingleObject(hEvent, 0);
CheckEventWait(hEvent, wait_rv, WAIT_TIMEOUT);
}
bool ResetEventIfSignaled(WSAEVENT hEvent) {
DWORD wait_rv = WaitForSingleObject(hEvent, 0);
if (wait_rv == WAIT_TIMEOUT)
return false;
CheckEventWait(hEvent, wait_rv, WAIT_OBJECT_0);
BOOL ok = WSAResetEvent(hEvent);
CHECK(ok);
return true;
}
}