blob: ecc06340a350c853b82c7b4da475d5fa0877309a [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Craig Tiller9a4dddd2016-03-25 17:08:13 -070034#ifndef GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
35#define GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
Craig Tillerdfff1b82015-09-21 14:39:57 -070037#include <stddef.h>
Craig Tiller9533d042016-03-25 17:11:06 -070038#include "src/core/lib/iomgr/exec_ctx.h"
39#include "src/core/lib/iomgr/iomgr.h"
Craig Tiller0c0b60c2015-01-21 15:49:28 -080040
41#define GRPC_MAX_SOCKADDR_SIZE 128
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080042
Craig Tillera82950e2015-09-22 12:33:20 -070043typedef struct {
Craig Tiller0c0b60c2015-01-21 15:49:28 -080044 char addr[GRPC_MAX_SOCKADDR_SIZE];
Craig Tiller3121fd42015-09-10 09:56:20 -070045 size_t len;
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080046} grpc_resolved_address;
47
Craig Tillera82950e2015-09-22 12:33:20 -070048typedef struct {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080049 size_t naddrs;
50 grpc_resolved_address *addrs;
51} grpc_resolved_addresses;
52
53/* Async result callback:
54 On success: addresses is the result, and the callee must call
55 grpc_resolved_addresses_destroy when it's done with them
56 On failure: addresses is NULL */
Craig Tillera82950e2015-09-22 12:33:20 -070057typedef void (*grpc_resolve_cb)(grpc_exec_ctx *exec_ctx, void *arg,
58 grpc_resolved_addresses *addresses);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080059/* Asynchronously resolve addr. Use default_port if a port isn't designated
60 in addr, otherwise use the port in addr. */
61/* TODO(ctiller): add a timeout here */
Craig Tillera82950e2015-09-22 12:33:20 -070062void grpc_resolve_address(const char *addr, const char *default_port,
63 grpc_resolve_cb cb, void *arg);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080064/* Destroy resolved addresses */
Craig Tillera82950e2015-09-22 12:33:20 -070065void grpc_resolved_addresses_destroy(grpc_resolved_addresses *addresses);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080066
67/* Resolve addr in a blocking fashion. Returns NULL on failure. On success,
68 result must be freed with grpc_resolved_addresses_destroy. */
Craig Tillere1e45592016-03-11 08:01:58 -080069extern grpc_resolved_addresses *(*grpc_blocking_resolve_address)(
70 const char *name, const char *default_port);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080071
Craig Tiller9a4dddd2016-03-25 17:08:13 -070072#endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */