Yuchen Zeng | 9b5aa63 | 2016-07-26 19:09:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2016, Google Inc. |
| 4 | * 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 Tiller | d608cd6 | 2017-04-02 16:23:17 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H |
| 35 | #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H |
Yuchen Zeng | b48000c | 2016-08-09 22:44:23 -0700 | [diff] [blame] | 36 | |
Yuchen Zeng | 9e4c8eb | 2016-11-18 01:06:57 -0800 | [diff] [blame] | 37 | #include <ares.h> |
| 38 | |
Yuchen Zeng | 85750b0 | 2016-08-08 14:16:34 -0700 | [diff] [blame] | 39 | #include "src/core/lib/iomgr/exec_ctx.h" |
| 40 | #include "src/core/lib/iomgr/pollset_set.h" |
Yuchen Zeng | 9b5aa63 | 2016-07-26 19:09:56 -0700 | [diff] [blame] | 41 | |
Yuchen Zeng | 85750b0 | 2016-08-08 14:16:34 -0700 | [diff] [blame] | 42 | typedef struct grpc_ares_ev_driver grpc_ares_ev_driver; |
| 43 | |
Yuchen Zeng | 38f34fb | 2016-10-11 15:56:33 -0700 | [diff] [blame] | 44 | /* Start \a ev_driver. It will keep working until all IO on its ares_channel is |
Yuchen Zeng | c1893dc | 2016-09-30 18:49:41 -0700 | [diff] [blame] | 45 | done, or grpc_ares_ev_driver_destroy() is called. It may notify the callbacks |
| 46 | bound to its ares_channel when necessary. */ |
| 47 | void grpc_ares_ev_driver_start(grpc_exec_ctx *exec_ctx, |
Yuchen Zeng | a418ed2 | 2016-08-08 17:24:33 -0700 | [diff] [blame] | 48 | grpc_ares_ev_driver *ev_driver); |
Yuchen Zeng | 0056531 | 2016-08-24 16:41:12 -0700 | [diff] [blame] | 49 | |
Yuchen Zeng | 3ae2663 | 2016-11-09 15:53:50 -0800 | [diff] [blame] | 50 | /* Returns the ares_channel owned by \a ev_driver. To bind a c-ares query to |
| 51 | \a ev_driver, use the ares_channel owned by \a ev_driver as the arg of the |
| 52 | query. */ |
Yuchen Zeng | 9e4c8eb | 2016-11-18 01:06:57 -0800 | [diff] [blame] | 53 | ares_channel *grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver *ev_driver); |
Yuchen Zeng | 85750b0 | 2016-08-08 14:16:34 -0700 | [diff] [blame] | 54 | |
Yuchen Zeng | c1893dc | 2016-09-30 18:49:41 -0700 | [diff] [blame] | 55 | /* Creates a new grpc_ares_ev_driver. Returns GRPC_ERROR_NONE if \a ev_driver is |
| 56 | created successfully. */ |
Yuchen Zeng | 8917aec | 2016-08-09 18:41:31 -0700 | [diff] [blame] | 57 | grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver, |
| 58 | grpc_pollset_set *pollset_set); |
Yuchen Zeng | c1893dc | 2016-09-30 18:49:41 -0700 | [diff] [blame] | 59 | |
Yuchen Zeng | 3ae2663 | 2016-11-09 15:53:50 -0800 | [diff] [blame] | 60 | /* Destroys \a ev_driver asynchronously. Pending lookups made on \a ev_driver |
| 61 | will be cancelled and their on_done callbacks will be invoked with a status |
| 62 | of ARES_ECANCELLED. */ |
Yuchen Zeng | 117a300 | 2016-11-17 19:43:36 -0800 | [diff] [blame] | 63 | void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver *ev_driver); |
Yuchen Zeng | b48000c | 2016-08-09 22:44:23 -0700 | [diff] [blame] | 64 | |
Yuchen Zeng | 3b4bed2 | 2017-06-04 01:41:15 -0700 | [diff] [blame^] | 65 | /* Shutdown all the grpc_fds used by \a ev_driver */ |
| 66 | void grpc_ares_ev_driver_shutdown(grpc_exec_ctx *exec_ctx, |
| 67 | grpc_ares_ev_driver *ev_driver); |
| 68 | |
Craig Tiller | 90d1015 | 2017-04-03 07:15:28 -0700 | [diff] [blame] | 69 | #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H \ |
| 70 | */ |