OLD | NEW |
(Empty) | |
| 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_IOMGR_ENDPOINT_H |
| 35 #define GRPC_INTERNAL_CORE_IOMGR_ENDPOINT_H |
| 36 |
| 37 #include "src/core/iomgr/pollset.h" |
| 38 #include "src/core/iomgr/pollset_set.h" |
| 39 #include <grpc/support/slice.h> |
| 40 #include <grpc/support/slice_buffer.h> |
| 41 #include <grpc/support/time.h> |
| 42 |
| 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 |
| 46 typedef struct grpc_endpoint grpc_endpoint; |
| 47 typedef struct grpc_endpoint_vtable grpc_endpoint_vtable; |
| 48 |
| 49 struct 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); |
| 61 }; |
| 62 |
| 63 /* 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. */ |
| 67 void grpc_endpoint_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, |
| 68 gpr_slice_buffer *slices, grpc_closure *cb); |
| 69 |
| 70 char *grpc_endpoint_get_peer(grpc_endpoint *ep); |
| 71 |
| 72 /* Write slices out to the socket. |
| 73 |
| 74 If the connection is ready for more data after the end of the call, it |
| 75 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 */ |
| 82 void grpc_endpoint_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, |
| 83 gpr_slice_buffer *slices, grpc_closure *cb); |
| 84 |
| 85 /* Causes any pending read/write callbacks to run immediately with |
| 86 success==0 */ |
| 87 void grpc_endpoint_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep); |
| 88 void grpc_endpoint_destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep); |
| 89 |
| 90 /* Add an endpoint to a pollset, so that when the pollset is polled, events from |
| 91 this endpoint are considered */ |
| 92 void grpc_endpoint_add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, |
| 93 grpc_pollset *pollset); |
| 94 void grpc_endpoint_add_to_pollset_set(grpc_exec_ctx *exec_ctx, |
| 95 grpc_endpoint *ep, |
| 96 grpc_pollset_set *pollset_set); |
| 97 |
| 98 struct grpc_endpoint { |
| 99 const grpc_endpoint_vtable *vtable; |
| 100 }; |
| 101 |
| 102 #endif /* GRPC_INTERNAL_CORE_IOMGR_ENDPOINT_H */ |
OLD | NEW |