15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_BASE_WINSOCK_UTIL_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_BASE_WINSOCK_UTIL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <winsock2.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "net/base/net_export.h"
11eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Assert that the (manual-reset) event object is not signaled.
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void AssertEventNotSignaled(WSAEVENT hEvent);
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If the (manual-reset) event object is signaled, resets it and returns true.
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Otherwise, does nothing and returns false.  Called after a Winsock function
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// succeeds synchronously
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Our testing shows that except in rare cases (when running inside QEMU),
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the event object is already signaled at this point, so we call this method
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to avoid a context switch in common cases.  This is just a performance
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// optimization.  The code still works if this function simply returns false.
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool ResetEventIfSignaled(WSAEVENT hEvent);
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_BASE_WINSOCK_UTIL_H_
30