xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/io/quic_default_event_loop.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2022 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "quiche/quic/core/io/quic_default_event_loop.h"
6 
7 #include <algorithm>
8 #include <memory>
9 #include <vector>
10 
11 #include "absl/algorithm/container.h"
12 #include "quiche/quic/core/io/quic_poll_event_loop.h"
13 #include "quiche/common/platform/api/quiche_event_loop.h"
14 
15 #ifdef QUICHE_ENABLE_LIBEVENT
16 #include "quiche/quic/bindings/quic_libevent.h"
17 #endif
18 
19 namespace quic {
20 
GetDefaultEventLoop()21 QuicEventLoopFactory* GetDefaultEventLoop() {
22   if (QuicEventLoopFactory* factory =
23           quiche::GetOverrideForDefaultEventLoop()) {
24     return factory;
25   }
26 #ifdef QUICHE_ENABLE_LIBEVENT
27   return QuicLibeventEventLoopFactory::Get();
28 #else
29   return QuicPollEventLoopFactory::Get();
30 #endif
31 }
32 
GetAllSupportedEventLoops()33 std::vector<QuicEventLoopFactory*> GetAllSupportedEventLoops() {
34   std::vector<QuicEventLoopFactory*> loops = {QuicPollEventLoopFactory::Get()};
35 #ifdef QUICHE_ENABLE_LIBEVENT
36   loops.push_back(QuicLibeventEventLoopFactory::Get());
37   if (QuicLibeventEventLoopFactory::Get()->GetName() !=
38       QuicLibeventEventLoopFactory::GetLevelTriggeredBackendForTests()
39           ->GetName()) {
40     loops.push_back(
41         QuicLibeventEventLoopFactory::GetLevelTriggeredBackendForTests());
42   }
43 #endif
44   std::vector<QuicEventLoopFactory*> extra =
45       quiche::GetExtraEventLoopImplementations();
46   loops.insert(loops.end(), extra.begin(), extra.end());
47   return loops;
48 }
49 
50 }  // namespace quic
51