• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The gRPC Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #ifndef GRPC_SRC_CORE_LIB_EVENT_ENGINE_WINDOWS_IOCP_H
15 #define GRPC_SRC_CORE_LIB_EVENT_ENGINE_WINDOWS_IOCP_H
16 
17 #include <grpc/support/port_platform.h>
18 
19 #ifdef GPR_WINDOWS
20 
21 #include <grpc/event_engine/event_engine.h>
22 
23 #include "absl/status/status.h"
24 #include "src/core/lib/event_engine/poller.h"
25 #include "src/core/lib/event_engine/thread_pool/thread_pool.h"
26 #include "src/core/lib/event_engine/windows/win_socket.h"
27 
28 namespace grpc_event_engine {
29 namespace experimental {
30 
31 class IOCP final : public Poller {
32  public:
33   explicit IOCP(ThreadPool* thread_pool) noexcept;
34   ~IOCP() override;
35   // Not copyable
36   IOCP(const IOCP&) = delete;
37   IOCP& operator=(const IOCP&) = delete;
38   // Not moveable
39   IOCP(IOCP&& other) = delete;
40   IOCP& operator=(IOCP&& other) = delete;
41 
42   // interface methods
43   void Shutdown();
44   WorkResult Work(EventEngine::Duration timeout,
45                   absl::FunctionRef<void()> schedule_poll_again) override;
46   void Kick() override;
47 
48   std::unique_ptr<WinSocket> Watch(SOCKET socket);
49   // Return the set of default flags
50   static DWORD GetDefaultSocketFlags();
51 
52  private:
53   // Initialize default flags via checking platform support
54   static DWORD WSASocketFlagsInit();
55 
56   ThreadPool* thread_pool_;
57   HANDLE iocp_handle_;
58   OVERLAPPED kick_overlap_;
59   ULONG kick_token_;
60   std::atomic<int> outstanding_kicks_{0};
61 };
62 
63 }  // namespace experimental
64 }  // namespace grpc_event_engine
65 
66 #endif
67 
68 #endif  // GRPC_SRC_CORE_LIB_EVENT_ENGINE_WINDOWS_IOCP_H
69