gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
endpoint.h
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 <grpc/support/slice.h>
39 #include <grpc/support/time.h>
40 
41 /* An endpoint caps a streaming channel between two communicating processes.
42  Examples may be: a tcp socket, <stdin+stdout>, or some shared memory. */
43 
44 typedef struct grpc_endpoint grpc_endpoint;
46 
47 typedef enum grpc_endpoint_cb_status {
48  GRPC_ENDPOINT_CB_OK = 0, /* Call completed successfully */
49  GRPC_ENDPOINT_CB_EOF, /* Call completed successfully, end of file reached */
50  GRPC_ENDPOINT_CB_SHUTDOWN, /* Call interrupted by shutdown */
51  GRPC_ENDPOINT_CB_ERROR /* Call interrupted by socket error */
52 } grpc_endpoint_cb_status;
53 
54 typedef enum grpc_endpoint_write_status {
55  GRPC_ENDPOINT_WRITE_DONE, /* completed immediately, cb won't be called */
56  GRPC_ENDPOINT_WRITE_PENDING, /* cb will be called when completed */
57  GRPC_ENDPOINT_WRITE_ERROR /* write errored out, cb won't be called */
58 } grpc_endpoint_write_status;
59 
60 typedef void (*grpc_endpoint_read_cb)(void *user_data, gpr_slice *slices,
61  size_t nslices,
62  grpc_endpoint_cb_status error);
63 typedef void (*grpc_endpoint_write_cb)(void *user_data,
64  grpc_endpoint_cb_status error);
65 
67  void (*notify_on_read)(grpc_endpoint *ep, grpc_endpoint_read_cb cb,
68  void *user_data);
69  grpc_endpoint_write_status (*write)(grpc_endpoint *ep, gpr_slice *slices,
70  size_t nslices, grpc_endpoint_write_cb cb,
71  void *user_data);
72  void (*add_to_pollset)(grpc_endpoint *ep, grpc_pollset *pollset);
73  void (*shutdown)(grpc_endpoint *ep);
74  void (*destroy)(grpc_endpoint *ep);
75 };
76 
77 /* When data is available on the connection, calls the callback with slices. */
78 void grpc_endpoint_notify_on_read(grpc_endpoint *ep, grpc_endpoint_read_cb cb,
79  void *user_data);
80 
81 /* Write slices out to the socket.
82 
83  If the connection is ready for more data after the end of the call, it
84  returns GRPC_ENDPOINT_WRITE_DONE.
85  Otherwise it returns GRPC_ENDPOINT_WRITE_PENDING and calls cb when the
86  connection is ready for more data. */
87 grpc_endpoint_write_status grpc_endpoint_write(grpc_endpoint *ep,
88  gpr_slice *slices,
89  size_t nslices,
90  grpc_endpoint_write_cb cb,
91  void *user_data);
92 
93 /* Causes any pending read/write callbacks to run immediately with
94  GRPC_ENDPOINT_CB_SHUTDOWN status */
95 void grpc_endpoint_shutdown(grpc_endpoint *ep);
96 void grpc_endpoint_destroy(grpc_endpoint *ep);
97 
98 /* Add an endpoint to a pollset, so that when the pollset is polled, events from
99  this endpoint are considered */
100 void grpc_endpoint_add_to_pollset(grpc_endpoint *ep, grpc_pollset *pollset);
101 
103  const grpc_endpoint_vtable *vtable;
104 };
105 
106 #endif /* GRPC_INTERNAL_CORE_IOMGR_ENDPOINT_H */
Definition: pollset_posix.h:48
Definition: endpoint.h:66
Definition: endpoint.h:102
Definition: slice.h:79