Imported Upstream version 1.41.0
[platform/upstream/grpc.git] / src / core / lib / iomgr / resolve_address.h
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #ifndef GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
20 #define GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include <stddef.h>
25
26 #include "src/core/lib/iomgr/port.h"
27
28 #ifdef GRPC_WINSOCK_SOCKET
29 #include <ws2tcpip.h>
30 #endif
31
32 #if defined(GRPC_POSIX_SOCKET) || defined(GRPC_CFSTREAM)
33 #include <sys/socket.h>
34 #endif
35
36 #include "src/core/lib/iomgr/pollset_set.h"
37
38 #define GRPC_MAX_SOCKADDR_SIZE 128
39
40 struct grpc_resolved_address {
41   char addr[GRPC_MAX_SOCKADDR_SIZE];
42   socklen_t len;
43 };
44 struct grpc_resolved_addresses {
45   size_t naddrs;
46   grpc_resolved_address* addrs;
47 };
48
49 namespace grpc_core {
50 extern const char* kDefaultSecurePort;
51 constexpr int kDefaultSecurePortInt = 443;
52 }  // namespace grpc_core
53
54 typedef struct grpc_address_resolver_vtable {
55   void (*resolve_address)(const char* addr, const char* default_port,
56                           grpc_pollset_set* interested_parties,
57                           grpc_closure* on_done,
58                           grpc_resolved_addresses** addresses);
59   grpc_error_handle (*blocking_resolve_address)(
60       const char* name, const char* default_port,
61       grpc_resolved_addresses** addresses);
62 } grpc_address_resolver_vtable;
63
64 void grpc_set_resolver_impl(grpc_address_resolver_vtable* vtable);
65
66 /* Asynchronously resolve addr. Use default_port if a port isn't designated
67    in addr, otherwise use the port in addr. */
68 /* TODO(apolcyn): add a timeout here */
69 void grpc_resolve_address(const char* addr, const char* default_port,
70                           grpc_pollset_set* interested_parties,
71                           grpc_closure* on_done,
72                           grpc_resolved_addresses** addresses);
73
74 /* Destroy resolved addresses */
75 void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addresses);
76
77 /* Resolve addr in a blocking fashion. On success,
78    result must be freed with grpc_resolved_addresses_destroy. */
79 grpc_error_handle grpc_blocking_resolve_address(
80     const char* name, const char* default_port,
81     grpc_resolved_addresses** addresses);
82
83 #endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */