Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2015 gRPC authors. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Craig Tiller | 9a4dddd | 2016-03-25 17:08:13 -0700 | [diff] [blame] | 19 | #ifndef GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H |
| 20 | #define GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 21 | |
Yash Tibrewal | 68dbea2 | 2018-03-08 18:23:18 -0800 | [diff] [blame] | 22 | #include <grpc/support/port_platform.h> |
Yash Tibrewal | 5f3b474 | 2018-03-09 14:59:07 -0800 | [diff] [blame] | 23 | |
Craig Tiller | dfff1b8 | 2015-09-21 14:39:57 -0700 | [diff] [blame] | 24 | #include <stddef.h> |
Yash Tibrewal | 68dbea2 | 2018-03-08 18:23:18 -0800 | [diff] [blame] | 25 | |
Yash Tibrewal | ea37b0c | 2018-03-09 14:33:11 -0800 | [diff] [blame] | 26 | #include "src/core/lib/iomgr/port.h" |
| 27 | |
| 28 | #ifdef GRPC_UV |
| 29 | #include <uv.h> |
| 30 | #endif |
| 31 | |
Yash Tibrewal | 44a1588 | 2018-03-14 18:41:33 -0700 | [diff] [blame] | 32 | #ifdef GRPC_WINSOCK_SOCKET |
Yash Tibrewal | 4d46260 | 2018-03-09 18:32:18 -0800 | [diff] [blame] | 33 | #include <ws2tcpip.h> |
Yash Tibrewal | ea37b0c | 2018-03-09 14:33:11 -0800 | [diff] [blame] | 34 | #endif |
| 35 | |
Muxi Yan | d810bdc | 2018-05-31 16:32:48 -0700 | [diff] [blame] | 36 | #if defined(GRPC_POSIX_SOCKET) || defined(GRPC_CFSTREAM) |
Muxi Yan | 67ff405 | 2018-05-15 12:36:10 -0700 | [diff] [blame] | 37 | #include <sys/socket.h> |
| 38 | #endif |
| 39 | |
Yuchen Zeng | 15521de | 2016-11-17 20:39:27 -0800 | [diff] [blame] | 40 | #include "src/core/lib/iomgr/pollset_set.h" |
Craig Tiller | 0c0b60c | 2015-01-21 15:49:28 -0800 | [diff] [blame] | 41 | |
| 42 | #define GRPC_MAX_SOCKADDR_SIZE 128 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 43 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 44 | typedef struct { |
Craig Tiller | 0c0b60c | 2015-01-21 15:49:28 -0800 | [diff] [blame] | 45 | char addr[GRPC_MAX_SOCKADDR_SIZE]; |
Yash Tibrewal | 268936a | 2018-02-20 10:42:40 -0800 | [diff] [blame] | 46 | socklen_t len; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 47 | } grpc_resolved_address; |
| 48 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 49 | typedef struct { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 50 | size_t naddrs; |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 51 | grpc_resolved_address* addrs; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 52 | } grpc_resolved_addresses; |
| 53 | |
kpayson64 | 539f506 | 2018-03-12 19:16:30 -0700 | [diff] [blame] | 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* (*blocking_resolve_address)(const char* name, |
| 60 | 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 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 66 | /* Asynchronously resolve addr. Use default_port if a port isn't designated |
| 67 | in addr, otherwise use the port in addr. */ |
| 68 | /* TODO(ctiller): add a timeout here */ |
kpayson64 | 539f506 | 2018-03-12 19:16:30 -0700 | [diff] [blame] | 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 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 74 | /* Destroy resolved addresses */ |
Craig Tiller | baa14a9 | 2017-11-03 09:09:36 -0700 | [diff] [blame] | 75 | void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addresses); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 76 | |
kpayson64 | 539f506 | 2018-03-12 19:16:30 -0700 | [diff] [blame] | 77 | /* Resolve addr in a blocking fashion. On success, |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 78 | result must be freed with grpc_resolved_addresses_destroy. */ |
kpayson64 | 539f506 | 2018-03-12 19:16:30 -0700 | [diff] [blame] | 79 | grpc_error* grpc_blocking_resolve_address(const char* name, |
| 80 | const char* default_port, |
| 81 | grpc_resolved_addresses** addresses); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 82 | |
Yash Tibrewal | 12fc6d4 | 2017-10-09 16:43:34 -0700 | [diff] [blame] | 83 | #endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */ |