GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

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