mirror of https://github.com/grpc/grpc.git
Conflicts: Makefile build.json vsprojects/vs2013/grpc.vcxproj vsprojects/vs2013/grpc.vcxproj.filters vsprojects/vs2013/grpc_unsecure.vcxproj vsprojects/vs2013/grpc_unsecure.vcxproj.filterspull/168/head
commit
9574132019
158 changed files with 2056 additions and 957 deletions
@ -0,0 +1,67 @@ |
||||
/*
|
||||
* |
||||
* 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_GRPC_HTTP_H__ |
||||
#define __GRPC_GRPC_HTTP_H__ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* HTTP GET support.
|
||||
|
||||
HTTP2 servers can publish statically generated text content served |
||||
via HTTP2 GET queries by publishing one or more grpc_http_server_page |
||||
elements via repeated GRPC_ARG_SERVE_OVER_HTTP elements in the servers |
||||
channel_args. |
||||
|
||||
This is not: |
||||
- a general purpose web server |
||||
- particularly fast |
||||
|
||||
It's useful for being able to serve up some static content (maybe some |
||||
javascript to be able to interact with your GRPC server?) */ |
||||
|
||||
typedef struct { |
||||
const char *path; |
||||
const char *content_type; |
||||
const char *content; |
||||
} grpc_http_server_page; |
||||
|
||||
#define GRPC_ARG_SERVE_OVER_HTTP "grpc.serve_over_http" |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __GRPC_GRPC_HTTP_H__ */ |
@ -0,0 +1,82 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, 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 <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_LINUX_EVENTFD |
||||
|
||||
#include <errno.h> |
||||
#include <sys/eventfd.h> |
||||
#include <unistd.h> |
||||
|
||||
#include "src/core/iomgr/wakeup_fd_posix.h" |
||||
#include <grpc/support/log.h> |
||||
|
||||
static void eventfd_create(grpc_wakeup_fd_info *fd_info) { |
||||
int efd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); |
||||
/* TODO(klempner): Handle failure more gracefully */ |
||||
GPR_ASSERT(efd >= 0); |
||||
fd_info->read_fd = efd; |
||||
fd_info->write_fd = -1; |
||||
} |
||||
|
||||
static void eventfd_consume(grpc_wakeup_fd_info *fd_info) { |
||||
eventfd_t value; |
||||
int err; |
||||
do { |
||||
err = eventfd_read(fd_info->read_fd, &value); |
||||
} while (err < 0 && errno == EINTR); |
||||
} |
||||
|
||||
static void eventfd_wakeup(grpc_wakeup_fd_info *fd_info) { |
||||
int err; |
||||
do { |
||||
err = eventfd_write(fd_info->read_fd, 1); |
||||
} while (err < 0 && errno == EINTR); |
||||
} |
||||
|
||||
static void eventfd_destroy(grpc_wakeup_fd_info *fd_info) { |
||||
close(fd_info->read_fd); |
||||
} |
||||
|
||||
static int eventfd_check_availability(void) { |
||||
/* TODO(klempner): Actually check if eventfd is available */ |
||||
return 1; |
||||
} |
||||
|
||||
const grpc_wakeup_fd_vtable specialized_wakeup_fd_vtable = { |
||||
eventfd_create, eventfd_consume, eventfd_wakeup, eventfd_destroy, |
||||
eventfd_check_availability |
||||
}; |
||||
|
||||
#endif /* GPR_LINUX_EVENTFD */ |
@ -0,0 +1,53 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, 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. |
||||
* |
||||
*/ |
||||
|
||||
/*
|
||||
* This is a dummy file to provide an invalid specialized_wakeup_fd_vtable on |
||||
* systems without anything better than pipe. |
||||
*/ |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifndef GPR_POSIX_HAS_SPECIAL_WAKEUP_FD |
||||
|
||||
#include "src/core/iomgr/wakeup_fd.h" |
||||
|
||||
static int check_availability_invalid(void) { |
||||
return 0; |
||||
} |
||||
|
||||
const grpc_wakeup_fd_vtable specialized_wakeup_fd_vtable = { |
||||
NULL, NULL, NULL, NULL, check_availability_invalid |
||||
}; |
||||
|
||||
#endif /* GPR_POSIX_HAS_SPECIAL_WAKEUP */ |
@ -0,0 +1,93 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, 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. |
||||
* |
||||
*/ |
||||
|
||||
/* TODO(klempner): Allow this code to be disabled. */ |
||||
#include "src/core/iomgr/wakeup_fd_posix.h" |
||||
|
||||
#include <errno.h> |
||||
#include <string.h> |
||||
#include <unistd.h> |
||||
|
||||
#include "src/core/iomgr/socket_utils_posix.h" |
||||
#include <grpc/support/log.h> |
||||
|
||||
static void pipe_create(grpc_wakeup_fd_info *fd_info) { |
||||
int pipefd[2]; |
||||
/* TODO(klempner): Make this nonfatal */ |
||||
GPR_ASSERT(0 == pipe(pipefd)); |
||||
GPR_ASSERT(grpc_set_socket_nonblocking(pipefd[0], 1)); |
||||
GPR_ASSERT(grpc_set_socket_nonblocking(pipefd[1], 1)); |
||||
fd_info->read_fd = pipefd[0]; |
||||
fd_info->write_fd = pipefd[1]; |
||||
} |
||||
|
||||
static void pipe_consume(grpc_wakeup_fd_info *fd_info) { |
||||
char buf[128]; |
||||
int r; |
||||
|
||||
for (;;) { |
||||
r = read(fd_info->read_fd, buf, sizeof(buf)); |
||||
if (r > 0) continue; |
||||
if (r == 0) return; |
||||
switch (errno) { |
||||
case EAGAIN: |
||||
return; |
||||
case EINTR: |
||||
continue; |
||||
default: |
||||
gpr_log(GPR_ERROR, "error reading pipe: %s", strerror(errno)); |
||||
return; |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void pipe_wakeup(grpc_wakeup_fd_info *fd_info) { |
||||
char c = 0; |
||||
while (write(fd_info->write_fd, &c, 1) != 1 && errno == EINTR) |
||||
; |
||||
} |
||||
|
||||
static void pipe_destroy(grpc_wakeup_fd_info *fd_info) { |
||||
close(fd_info->read_fd); |
||||
close(fd_info->write_fd); |
||||
} |
||||
|
||||
static int pipe_check_availability(void) { |
||||
/* Assume that pipes are always available. */ |
||||
return 1; |
||||
} |
||||
|
||||
const grpc_wakeup_fd_vtable pipe_wakeup_fd_vtable = { |
||||
pipe_create, pipe_consume, pipe_wakeup, pipe_destroy, pipe_check_availability |
||||
}; |
||||
|
@ -0,0 +1,41 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, 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_WAKEUP_FD_PIPE_H_ |
||||
#define __GRPC_INTERNAL_IOMGR_WAKEUP_FD_PIPE_H_ |
||||
|
||||
#include "src/core/iomgr/wakeup_fd_posix.h" |
||||
|
||||
extern grpc_wakeup_fd_vtable pipe_wakeup_fd_vtable; |
||||
|
||||
#endif /* __GRPC_INTERNAL_IOMGR_WAKEUP_FD_PIPE_H_ */ |
@ -0,0 +1,70 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, 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/wakeup_fd_posix.h" |
||||
#include "src/core/iomgr/wakeup_fd_pipe.h" |
||||
#include <stddef.h> |
||||
|
||||
static const grpc_wakeup_fd_vtable *wakeup_fd_vtable = NULL; |
||||
|
||||
void grpc_wakeup_fd_global_init(void) { |
||||
if (specialized_wakeup_fd_vtable.check_availability()) { |
||||
wakeup_fd_vtable = &specialized_wakeup_fd_vtable; |
||||
} else { |
||||
wakeup_fd_vtable = &pipe_wakeup_fd_vtable; |
||||
} |
||||
} |
||||
|
||||
void grpc_wakeup_fd_global_init_force_fallback(void) { |
||||
wakeup_fd_vtable = &pipe_wakeup_fd_vtable; |
||||
} |
||||
|
||||
void grpc_wakeup_fd_global_destroy(void) { |
||||
wakeup_fd_vtable = NULL; |
||||
} |
||||
|
||||
void grpc_wakeup_fd_create(grpc_wakeup_fd_info *fd_info) { |
||||
wakeup_fd_vtable->create(fd_info); |
||||
} |
||||
|
||||
void grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd_info *fd_info) { |
||||
wakeup_fd_vtable->consume(fd_info); |
||||
} |
||||
|
||||
void grpc_wakeup_fd_wakeup(grpc_wakeup_fd_info *fd_info) { |
||||
wakeup_fd_vtable->wakeup(fd_info); |
||||
} |
||||
|
||||
void grpc_wakeup_fd_destroy(grpc_wakeup_fd_info *fd_info) { |
||||
wakeup_fd_vtable->destroy(fd_info); |
||||
} |
@ -0,0 +1,102 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, 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. |
||||
* |
||||
*/ |
||||
|
||||
/*
|
||||
* wakeup_fd abstracts the concept of a file descriptor for the purpose of |
||||
* waking up a thread in select()/poll()/epoll_wait()/etc. |
||||
|
||||
* The poll() family of system calls provide a way for a thread to block until |
||||
* there is activity on one (or more) of a set of file descriptors. An |
||||
* application may wish to wake up this thread to do non file related work. The |
||||
* typical way to do this is to add a pipe to the set of file descriptors, then |
||||
* write to the pipe to wake up the thread in poll(). |
||||
* |
||||
* Linux has a lighter weight eventfd specifically designed for this purpose. |
||||
* wakeup_fd abstracts the difference between the two. |
||||
* |
||||
* Setup: |
||||
* 1. Before calling anything, call global_init() at least once. |
||||
* 1. Call grpc_wakeup_fd_create() to get a wakeup_fd. |
||||
* 2. Add the result of GRPC_WAKEUP_FD_FD to the set of monitored file |
||||
* descriptors for the poll() style API you are using. Monitor the file |
||||
* descriptor for readability. |
||||
* 3. To tear down, call grpc_wakeup_fd_destroy(). This closes the underlying |
||||
* file descriptor. |
||||
* |
||||
* Usage: |
||||
* 1. To wake up a polling thread, call grpc_wakeup_fd_wakeup() on a wakeup_fd |
||||
* it is monitoring. |
||||
* 2. If the polling thread was awakened by a wakeup_fd event, call |
||||
* grpc_wakeup_fd_consume_wakeup() on it. |
||||
*/ |
||||
#ifndef __GRPC_INTERNAL_IOMGR_WAKEUP_FD_POSIX_H_ |
||||
#define __GRPC_INTERNAL_IOMGR_WAKEUP_FD_POSIX_H_ |
||||
|
||||
typedef struct grpc_wakeup_fd_info grpc_wakeup_fd_info; |
||||
|
||||
void grpc_wakeup_fd_global_init(void); |
||||
void grpc_wakeup_fd_global_destroy(void); |
||||
|
||||
|
||||
void grpc_wakeup_fd_create(grpc_wakeup_fd_info *fd_info); |
||||
void grpc_wakeup_fd_consume_wakeup(grpc_wakeup_fd_info *fd_info); |
||||
void grpc_wakeup_fd_wakeup(grpc_wakeup_fd_info *fd_info); |
||||
void grpc_wakeup_fd_destroy(grpc_wakeup_fd_info *fd_info); |
||||
|
||||
#define GRPC_WAKEUP_FD_GET_READ_FD(fd_info) ((fd_info)->read_fd) |
||||
|
||||
/* Force using the fallback implementation. This is intended for testing
|
||||
* purposes only.*/ |
||||
void grpc_wakeup_fd_global_init_force_fallback(void); |
||||
|
||||
/* Private structures; don't access their fields directly outside of wakeup fd
|
||||
* code. */ |
||||
struct grpc_wakeup_fd_info { |
||||
int read_fd; |
||||
int write_fd; |
||||
}; |
||||
|
||||
typedef struct grpc_wakeup_fd_vtable { |
||||
void (*create)(grpc_wakeup_fd_info *fd_info); |
||||
void (*consume)(grpc_wakeup_fd_info *fd_info); |
||||
void (*wakeup)(grpc_wakeup_fd_info *fd_info); |
||||
void (*destroy)(grpc_wakeup_fd_info *fd_info); |
||||
/* Must be called before calling any other functions */ |
||||
int (*check_availability)(void); |
||||
} grpc_wakeup_fd_vtable; |
||||
|
||||
/* Defined in some specialized implementation's .c file, or by
|
||||
* wakeup_fd_nospecial.c if no such implementation exists. */ |
||||
extern const grpc_wakeup_fd_vtable specialized_wakeup_fd_vtable; |
||||
|
||||
#endif /* __GRPC_INTERNAL_IOMGR_WAKEUP_FD_POSIX_H_ */ |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue