• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 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 
15 #ifndef GRPC_SRC_CORE_LIB_EVENT_ENGINE_WINDOWS_GRPC_POLLED_FD_WINDOWS_H
16 #define GRPC_SRC_CORE_LIB_EVENT_ENGINE_WINDOWS_GRPC_POLLED_FD_WINDOWS_H
17 
18 #include <grpc/support/port_platform.h>
19 
20 #include "src/core/lib/iomgr/port.h"  // IWYU pragma: keep
21 
22 #if GRPC_ARES == 1 && defined(GRPC_WINDOWS_SOCKET_ARES_EV_DRIVER)
23 
24 #include <ares.h>
25 #include <grpc/event_engine/event_engine.h>
26 
27 #include <memory>
28 
29 #include "absl/functional/any_invocable.h"
30 #include "absl/status/status.h"
31 #include "src/core/lib/event_engine/common_closures.h"
32 #include "src/core/lib/event_engine/grpc_polled_fd.h"
33 #include "src/core/lib/event_engine/windows/iocp.h"
34 #include "src/core/lib/event_engine/windows/win_socket.h"
35 #include "src/core/util/sync.h"
36 
37 struct iovec;
38 
39 namespace grpc_event_engine {
40 namespace experimental {
41 
42 class GrpcPolledFdWindows;
43 
44 class GrpcPolledFdFactoryWindows : public GrpcPolledFdFactory {
45  public:
46   explicit GrpcPolledFdFactoryWindows(IOCP* iocp);
47   ~GrpcPolledFdFactoryWindows() override;
48 
49   void Initialize(grpc_core::Mutex* mutex, EventEngine* event_engine) override;
50   std::unique_ptr<GrpcPolledFd> NewGrpcPolledFdLocked(
51       ares_socket_t as) override;
52   void ConfigureAresChannelLocked(ares_channel channel) override;
53 
54  private:
55   friend class CustomSockFuncs;
56 
57   // The mutex is owned by the AresResolver which owns this object.
58   grpc_core::Mutex* mu_;
59   // The IOCP object is owned by the WindowsEngine whose ownership is shared by
60   // the AresResolver.
61   IOCP* iocp_;
62   // This pointer is initialized from the stored pointer inside the shared
63   // pointer owned by the AresResolver which owns this object.
64   EventEngine* event_engine_;
65   std::map<SOCKET, std::unique_ptr<GrpcPolledFdWindows>> sockets_;
66 };
67 
68 }  // namespace experimental
69 }  // namespace grpc_event_engine
70 
71 #endif  // GRPC_ARES == 1 && defined(GRPC_WINDOWS_SOCKET_ARES_EV_DRIVER)
72 
73 #endif  // GRPC_SRC_CORE_LIB_EVENT_ENGINE_WINDOWS_GRPC_POLLED_FD_WINDOWS_H
74