blob: 740ec50c6a03fc4a99dced91e749268638e47ea4 [file] [log] [blame]
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -08001/*
2 *
David Garcia Quintas3598d442016-03-15 14:53:05 -07003 * Copyright 2015-2016, 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_ENDPOINT_H
35#define GRPC_CORE_LIB_IOMGR_ENDPOINT_H
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080036
37#include <grpc/support/slice.h>
Craig Tillerb0298592015-08-27 07:38:01 -070038#include <grpc/support/slice_buffer.h>
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080039#include <grpc/support/time.h>
Craig Tillerf40df232016-03-25 13:38:14 -070040#include "src/core/iomgr/pollset.h"
41#include "src/core/iomgr/pollset_set.h"
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080042
43/* An endpoint caps a streaming channel between two communicating processes.
44 Examples may be: a tcp socket, <stdin+stdout>, or some shared memory. */
45
46typedef struct grpc_endpoint grpc_endpoint;
47typedef struct grpc_endpoint_vtable grpc_endpoint_vtable;
48
Craig Tillera82950e2015-09-22 12:33:20 -070049struct grpc_endpoint_vtable {
50 void (*read)(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
51 gpr_slice_buffer *slices, grpc_closure *cb);
52 void (*write)(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
53 gpr_slice_buffer *slices, grpc_closure *cb);
54 void (*add_to_pollset)(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
55 grpc_pollset *pollset);
56 void (*add_to_pollset_set)(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
57 grpc_pollset_set *pollset);
58 void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep);
59 void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep);
60 char *(*get_peer)(grpc_endpoint *ep);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080061};
62
Craig Tillerb0298592015-08-27 07:38:01 -070063/* When data is available on the connection, calls the callback with slices.
64 Callback success indicates that the endpoint can accept more reads, failure
65 indicates the endpoint is closed.
66 Valid slices may be placed into \a slices even on callback success == 0. */
Craig Tillera82950e2015-09-22 12:33:20 -070067void grpc_endpoint_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
68 gpr_slice_buffer *slices, grpc_closure *cb);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080069
Craig Tillera82950e2015-09-22 12:33:20 -070070char *grpc_endpoint_get_peer(grpc_endpoint *ep);
Craig Tiller1b22b9d2015-07-20 13:42:22 -070071
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080072/* Write slices out to the socket.
73
74 If the connection is ready for more data after the end of the call, it
Craig Tillerb0298592015-08-27 07:38:01 -070075 returns GRPC_ENDPOINT_DONE.
76 Otherwise it returns GRPC_ENDPOINT_PENDING and calls cb when the
77 connection is ready for more data.
78 \a slices may be mutated at will by the endpoint until cb is called.
79 No guarantee is made to the content of slices after a write EXCEPT that
80 it is a valid slice buffer.
81 */
Craig Tillera82950e2015-09-22 12:33:20 -070082void grpc_endpoint_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
83 gpr_slice_buffer *slices, grpc_closure *cb);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080084
85/* Causes any pending read/write callbacks to run immediately with
Craig Tillerb0298592015-08-27 07:38:01 -070086 success==0 */
Craig Tillera82950e2015-09-22 12:33:20 -070087void grpc_endpoint_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep);
88void grpc_endpoint_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep);
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080089
ctillerd79b4862014-12-17 16:36:59 -080090/* Add an endpoint to a pollset, so that when the pollset is polled, events from
91 this endpoint are considered */
Craig Tillera82950e2015-09-22 12:33:20 -070092void grpc_endpoint_add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
93 grpc_pollset *pollset);
94void grpc_endpoint_add_to_pollset_set(grpc_exec_ctx *exec_ctx,
95 grpc_endpoint *ep,
96 grpc_pollset_set *pollset_set);
ctillerd79b4862014-12-17 16:36:59 -080097
Craig Tillera82950e2015-09-22 12:33:20 -070098struct grpc_endpoint {
Nicolas Nobleb7ebd3b2014-11-26 16:33:03 -080099 const grpc_endpoint_vtable *vtable;
100};
101
Craig Tiller9a4dddd2016-03-25 17:08:13 -0700102#endif /* GRPC_CORE_LIB_IOMGR_ENDPOINT_H */