Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, 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 | |
| 34 | #ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_CONNECTOR_H |
| 35 | #define GRPC_INTERNAL_CORE_CLIENT_CONFIG_CONNECTOR_H |
| 36 | |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 37 | #include "src/core/channel/channel_stack.h" |
Craig Tiller | 5f84c84 | 2015-06-26 16:08:21 -0700 | [diff] [blame] | 38 | #include "src/core/iomgr/sockaddr.h" |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 39 | #include "src/core/transport/transport.h" |
| 40 | |
| 41 | typedef struct grpc_connector grpc_connector; |
| 42 | typedef struct grpc_connector_vtable grpc_connector_vtable; |
| 43 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 44 | struct grpc_connector { |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 45 | const grpc_connector_vtable *vtable; |
| 46 | }; |
| 47 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 48 | typedef struct { |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 49 | /** set of pollsets interested in this connection */ |
| 50 | grpc_pollset_set *interested_parties; |
| 51 | /** address to connect to */ |
| 52 | const struct sockaddr *addr; |
Craig Tiller | 3121fd4 | 2015-09-10 09:56:20 -0700 | [diff] [blame] | 53 | size_t addr_len; |
yang-g | a612412 | 2015-11-05 22:36:20 -0800 | [diff] [blame] | 54 | /** initial connect string to send */ |
| 55 | gpr_slice initial_connect_string; |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 56 | /** deadline for connection */ |
| 57 | gpr_timespec deadline; |
| 58 | /** channel arguments (to be passed to transport) */ |
| 59 | const grpc_channel_args *channel_args; |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 60 | } grpc_connect_in_args; |
| 61 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 62 | typedef struct { |
Craig Tiller | 04c5d4b | 2015-06-26 17:21:41 -0700 | [diff] [blame] | 63 | /** the connected transport */ |
| 64 | grpc_transport *transport; |
| 65 | /** any additional filters (owned by the caller of connect) */ |
| 66 | const grpc_channel_filter **filters; |
| 67 | size_t num_filters; |
| 68 | } grpc_connect_out_args; |
| 69 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 70 | struct grpc_connector_vtable { |
| 71 | void (*ref)(grpc_connector *connector); |
| 72 | void (*unref)(grpc_exec_ctx *exec_ctx, grpc_connector *connector); |
Craig Tiller | 131f6ed | 2015-09-15 08:20:20 -0700 | [diff] [blame] | 73 | /** Implementation of grpc_connector_shutdown */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 74 | void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_connector *connector); |
Craig Tiller | 131f6ed | 2015-09-15 08:20:20 -0700 | [diff] [blame] | 75 | /** Implementation of grpc_connector_connect */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 76 | void (*connect)(grpc_exec_ctx *exec_ctx, grpc_connector *connector, |
| 77 | const grpc_connect_in_args *in_args, |
| 78 | grpc_connect_out_args *out_args, grpc_closure *notify); |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 81 | void grpc_connector_ref(grpc_connector *connector); |
| 82 | void grpc_connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *connector); |
Craig Tiller | 131f6ed | 2015-09-15 08:20:20 -0700 | [diff] [blame] | 83 | /** Connect using the connector: max one outstanding call at a time */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 84 | void grpc_connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *connector, |
| 85 | const grpc_connect_in_args *in_args, |
| 86 | grpc_connect_out_args *out_args, |
| 87 | grpc_closure *notify); |
Craig Tiller | 131f6ed | 2015-09-15 08:20:20 -0700 | [diff] [blame] | 88 | /** Cancel any pending connection */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 89 | void grpc_connector_shutdown(grpc_exec_ctx *exec_ctx, |
| 90 | grpc_connector *connector); |
Craig Tiller | 9162466 | 2015-06-25 16:31:02 -0700 | [diff] [blame] | 91 | |
| 92 | #endif |