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