diff options
Diffstat (limited to 'src/core/iomgr')
-rw-r--r-- | src/core/iomgr/endpoint.c | 4 | ||||
-rw-r--r-- | src/core/iomgr/endpoint.h | 6 | ||||
-rw-r--r-- | src/core/iomgr/pollset.c | 37 | ||||
-rw-r--r-- | src/core/iomgr/pollset.h | 51 | ||||
-rw-r--r-- | src/core/iomgr/tcp_posix.c | 11 |
5 files changed, 106 insertions, 3 deletions
diff --git a/src/core/iomgr/endpoint.c b/src/core/iomgr/endpoint.c index 259c948720..f1944bf672 100644 --- a/src/core/iomgr/endpoint.c +++ b/src/core/iomgr/endpoint.c @@ -44,6 +44,10 @@ grpc_endpoint_write_status grpc_endpoint_write( return ep->vtable->write(ep, slices, nslices, cb, user_data, deadline); } +void grpc_endpoint_add_to_pollset(grpc_endpoint *ep, grpc_pollset *pollset) { + ep->vtable->add_to_pollset(ep, pollset); +} + void grpc_endpoint_shutdown(grpc_endpoint *ep) { ep->vtable->shutdown(ep); } void grpc_endpoint_destroy(grpc_endpoint *ep) { ep->vtable->destroy(ep); } diff --git a/src/core/iomgr/endpoint.h b/src/core/iomgr/endpoint.h index 88949fb03f..bbd800bea8 100644 --- a/src/core/iomgr/endpoint.h +++ b/src/core/iomgr/endpoint.h @@ -34,6 +34,7 @@ #ifndef __GRPC_INTERNAL_IOMGR_ENDPOINT_H__ #define __GRPC_INTERNAL_IOMGR_ENDPOINT_H__ +#include "src/core/iomgr/pollset.h" #include <grpc/support/slice.h> #include <grpc/support/time.h> @@ -69,6 +70,7 @@ struct grpc_endpoint_vtable { grpc_endpoint_write_status (*write)(grpc_endpoint *ep, gpr_slice *slices, size_t nslices, grpc_endpoint_write_cb cb, void *user_data, gpr_timespec deadline); + void (*add_to_pollset)(grpc_endpoint *ep, grpc_pollset *pollset); void (*shutdown)(grpc_endpoint *ep); void (*destroy)(grpc_endpoint *ep); }; @@ -92,6 +94,10 @@ grpc_endpoint_write_status grpc_endpoint_write( void grpc_endpoint_shutdown(grpc_endpoint *ep); void grpc_endpoint_destroy(grpc_endpoint *ep); +/* Add an endpoint to a pollset, so that when the pollset is polled, events from + this endpoint are considered */ +void grpc_endpoint_add_to_pollset(grpc_endpoint *ep, grpc_pollset *pollset); + struct grpc_endpoint { const grpc_endpoint_vtable *vtable; }; diff --git a/src/core/iomgr/pollset.c b/src/core/iomgr/pollset.c new file mode 100644 index 0000000000..62a0019eb3 --- /dev/null +++ b/src/core/iomgr/pollset.c @@ -0,0 +1,37 @@ +/* + * + * Copyright 2014, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "src/core/iomgr/pollset.h" + +void grpc_pollset_init(grpc_pollset *pollset) { pollset->unused = 0; } +void grpc_pollset_destroy(grpc_pollset *pollset) {} diff --git a/src/core/iomgr/pollset.h b/src/core/iomgr/pollset.h new file mode 100644 index 0000000000..ba1a9d5429 --- /dev/null +++ b/src/core/iomgr/pollset.h @@ -0,0 +1,51 @@ +/* + * + * Copyright 2014, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __GRPC_INTERNAL_IOMGR_POLLSET_H_ +#define __GRPC_INTERNAL_IOMGR_POLLSET_H_ + +/* A grpc_pollset is a set of file descriptors that a higher level item is + interested in. For example: + - a server will typically keep a pollset containing all connected channels, + so that it can find new calls to service + - a completion queue might keep a pollset with an entry for each transport + that is servicing a call that it's tracking */ +/* Eventually different implementations of iomgr will provide their own + grpc_pollset structs. As this is just a dummy wrapper to get the API in, + we just define a simple type here. */ +typedef struct { char unused; } grpc_pollset; + +void grpc_pollset_init(grpc_pollset *pollset); +void grpc_pollset_destroy(grpc_pollset *pollset); + +#endif /* __GRPC_INTERNAL_IOMGR_POLLSET_H_ */ diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c index b59e916e13..bc3ce69e47 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -538,9 +538,14 @@ static grpc_endpoint_write_status grpc_tcp_write( return status; } -static const grpc_endpoint_vtable vtable = {grpc_tcp_notify_on_read, - grpc_tcp_write, grpc_tcp_shutdown, - grpc_tcp_destroy}; +static void grpc_tcp_add_to_pollset(grpc_endpoint *ep, grpc_pollset *pollset) { + /* tickle the pollset so we crash if things aren't wired correctly */ + pollset->unused++; +} + +static const grpc_endpoint_vtable vtable = { + grpc_tcp_notify_on_read, grpc_tcp_write, grpc_tcp_add_to_pollset, + grpc_tcp_shutdown, grpc_tcp_destroy}; grpc_endpoint *grpc_tcp_create(grpc_fd *em_fd, size_t slice_size) { grpc_tcp *tcp = (grpc_tcp *)gpr_malloc(sizeof(grpc_tcp)); |