blob: 6afe94a7a923e4deab4dea179d403beffe1c2220 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2015 gRPC authors.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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 Nobleb7ebd3b2014-11-26 16:33:03 -08008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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 Nobleb7ebd3b2014-11-26 16:33:03 -080016 *
17 */
18
Craig Tiller9a4dddd2016-03-25 17:08:13 -070019#ifndef GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
20#define GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080021
Yash Tibrewal68dbea22018-03-08 18:23:18 -080022#include <grpc/support/port_platform.h>
Yash Tibrewal5f3b4742018-03-09 14:59:07 -080023
Craig Tillerdfff1b82015-09-21 14:39:57 -070024#include <stddef.h>
Yash Tibrewal68dbea22018-03-08 18:23:18 -080025
Yash Tibrewalea37b0c2018-03-09 14:33:11 -080026#include "src/core/lib/iomgr/port.h"
27
28#ifdef GRPC_UV
29#include <uv.h>
30#endif
31
Yash Tibrewal44a15882018-03-14 18:41:33 -070032#ifdef GRPC_WINSOCK_SOCKET
Yash Tibrewal4d462602018-03-09 18:32:18 -080033#include <ws2tcpip.h>
Yash Tibrewalea37b0c2018-03-09 14:33:11 -080034#endif
35
Muxi Yand810bdc2018-05-31 16:32:48 -070036#if defined(GRPC_POSIX_SOCKET) || defined(GRPC_CFSTREAM)
Muxi Yan67ff4052018-05-15 12:36:10 -070037#include <sys/socket.h>
38#endif
39
Yuchen Zeng15521de2016-11-17 20:39:27 -080040#include "src/core/lib/iomgr/pollset_set.h"
Craig Tiller0c0b60c2015-01-21 15:49:28 -080041
42#define GRPC_MAX_SOCKADDR_SIZE 128
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080043
Craig Tillera82950e2015-09-22 12:33:20 -070044typedef struct {
Craig Tiller0c0b60c2015-01-21 15:49:28 -080045 char addr[GRPC_MAX_SOCKADDR_SIZE];
Yash Tibrewal268936a2018-02-20 10:42:40 -080046 socklen_t len;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080047} grpc_resolved_address;
48
Craig Tillera82950e2015-09-22 12:33:20 -070049typedef struct {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080050 size_t naddrs;
Craig Tillerbaa14a92017-11-03 09:09:36 -070051 grpc_resolved_address* addrs;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080052} grpc_resolved_addresses;
53
kpayson64539f5062018-03-12 19:16:30 -070054typedef 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
64void grpc_set_resolver_impl(grpc_address_resolver_vtable* vtable);
65
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080066/* 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 */
kpayson64539f5062018-03-12 19:16:30 -070069void 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 Nobleb7ebd3b2014-11-26 16:33:03 -080074/* Destroy resolved addresses */
Craig Tillerbaa14a92017-11-03 09:09:36 -070075void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addresses);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080076
kpayson64539f5062018-03-12 19:16:30 -070077/* Resolve addr in a blocking fashion. On success,
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080078 result must be freed with grpc_resolved_addresses_destroy. */
kpayson64539f5062018-03-12 19:16:30 -070079grpc_error* grpc_blocking_resolve_address(const char* name,
80 const char* default_port,
81 grpc_resolved_addresses** addresses);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080082
Yash Tibrewal12fc6d42017-10-09 16:43:34 -070083#endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */