• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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 #include "src/core/lib/event_engine/utils.h"
15 
16 #include <grpc/event_engine/event_engine.h>
17 #include <grpc/support/port_platform.h>
18 #include <stdint.h>
19 
20 #include <algorithm>
21 
22 #include "absl/strings/str_cat.h"
23 #include "src/core/util/notification.h"
24 #include "src/core/util/time.h"
25 
26 namespace grpc_event_engine {
27 namespace experimental {
28 
HandleToStringInternal(uintptr_t a,uintptr_t b)29 std::string HandleToStringInternal(uintptr_t a, uintptr_t b) {
30   return absl::StrCat("{", absl::Hex(a, absl::kZeroPad16), ",",
31                       absl::Hex(b, absl::kZeroPad16), "}");
32 }
33 
ToTimestamp(grpc_core::Timestamp now,EventEngine::Duration delta)34 grpc_core::Timestamp ToTimestamp(grpc_core::Timestamp now,
35                                  EventEngine::Duration delta) {
36   return now +
37          std::max(grpc_core::Duration::Milliseconds(1),
38                   grpc_core::Duration::NanosecondsRoundUp(delta.count())) +
39          grpc_core::Duration::Milliseconds(1);
40 }
41 
42 absl::StatusOr<std::vector<EventEngine::ResolvedAddress>>
LookupHostnameBlocking(EventEngine::DNSResolver * dns_resolver,absl::string_view name,absl::string_view default_port)43 LookupHostnameBlocking(EventEngine::DNSResolver* dns_resolver,
44                        absl::string_view name, absl::string_view default_port) {
45   absl::StatusOr<std::vector<EventEngine::ResolvedAddress>> results;
46   grpc_core::Notification done;
47   dns_resolver->LookupHostname(
48       [&](absl::StatusOr<std::vector<EventEngine::ResolvedAddress>> addresses) {
49         results = std::move(addresses);
50         done.Notify();
51       },
52       name, default_port);
53   done.WaitForNotification();
54   return results;
55 }
56 
57 }  // namespace experimental
58 }  // namespace grpc_event_engine
59