blob: a649f143aef01a52d23453474840da7f93d53367 [file] [log] [blame]
Craig Tiller91624662015-06-25 16:31:02 -07001/*
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 Tiller04c5d4b2015-06-26 17:21:41 -070037#include "src/core/channel/channel_stack.h"
Craig Tiller5f84c842015-06-26 16:08:21 -070038#include "src/core/iomgr/sockaddr.h"
Craig Tiller91624662015-06-25 16:31:02 -070039#include "src/core/transport/transport.h"
40
41typedef struct grpc_connector grpc_connector;
42typedef struct grpc_connector_vtable grpc_connector_vtable;
43
Craig Tillera82950e2015-09-22 12:33:20 -070044struct grpc_connector {
Craig Tiller91624662015-06-25 16:31:02 -070045 const grpc_connector_vtable *vtable;
46};
47
Craig Tillera82950e2015-09-22 12:33:20 -070048typedef struct {
Craig Tiller04c5d4b2015-06-26 17:21:41 -070049 /** set of pollsets interested in this connection */
50 grpc_pollset_set *interested_parties;
51 /** address to connect to */
52 const struct sockaddr *addr;
Craig Tiller3121fd42015-09-10 09:56:20 -070053 size_t addr_len;
yang-ga6124122015-11-05 22:36:20 -080054 /** initial connect string to send */
55 gpr_slice initial_connect_string;
Craig Tiller04c5d4b2015-06-26 17:21:41 -070056 /** deadline for connection */
57 gpr_timespec deadline;
58 /** channel arguments (to be passed to transport) */
59 const grpc_channel_args *channel_args;
Craig Tiller04c5d4b2015-06-26 17:21:41 -070060} grpc_connect_in_args;
61
Craig Tillera82950e2015-09-22 12:33:20 -070062typedef struct {
Craig Tiller04c5d4b2015-06-26 17:21:41 -070063 /** 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 Tillera82950e2015-09-22 12:33:20 -070070struct grpc_connector_vtable {
71 void (*ref)(grpc_connector *connector);
72 void (*unref)(grpc_exec_ctx *exec_ctx, grpc_connector *connector);
Craig Tiller131f6ed2015-09-15 08:20:20 -070073 /** Implementation of grpc_connector_shutdown */
Craig Tillera82950e2015-09-22 12:33:20 -070074 void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_connector *connector);
Craig Tiller131f6ed2015-09-15 08:20:20 -070075 /** Implementation of grpc_connector_connect */
Craig Tillera82950e2015-09-22 12:33:20 -070076 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 Tiller91624662015-06-25 16:31:02 -070079};
80
Craig Tillera82950e2015-09-22 12:33:20 -070081void grpc_connector_ref(grpc_connector *connector);
82void grpc_connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *connector);
Craig Tiller131f6ed2015-09-15 08:20:20 -070083/** Connect using the connector: max one outstanding call at a time */
Craig Tillera82950e2015-09-22 12:33:20 -070084void 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 Tiller131f6ed2015-09-15 08:20:20 -070088/** Cancel any pending connection */
Craig Tillera82950e2015-09-22 12:33:20 -070089void grpc_connector_shutdown(grpc_exec_ctx *exec_ctx,
90 grpc_connector *connector);
Craig Tiller91624662015-06-25 16:31:02 -070091
92#endif