aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/iomgr
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-09-16 10:04:36 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-09-16 10:04:36 -0700
commit36c86e2a8348a69dcddff4ce8dbfbaf155423234 (patch)
tree51cdaefd8d88efd598bf1382b40cf6c54b0b20a7 /src/core/iomgr
parent7d57ba138fc4dbde885c5a59231ae6de6968e557 (diff)
parent9ed4be48955e3b65b0540f70060b7191d8c1eef1 (diff)
Merge github.com:grpc/grpc into shindig
Diffstat (limited to 'src/core/iomgr')
-rw-r--r--src/core/iomgr/fd_posix.c3
-rw-r--r--src/core/iomgr/iomgr.c10
-rw-r--r--src/core/iomgr/pollset_multipoller_with_epoll.c2
-rw-r--r--src/core/iomgr/udp_server.c20
-rw-r--r--src/core/iomgr/udp_server.h12
5 files changed, 19 insertions, 28 deletions
diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c
index 4bca9f3f6e..69518597d5 100644
--- a/src/core/iomgr/fd_posix.c
+++ b/src/core/iomgr/fd_posix.c
@@ -222,10 +222,9 @@ void grpc_fd_orphan(grpc_fd *fd, grpc_iomgr_closure *on_done,
const char *reason) {
fd->on_done_closure = on_done;
shutdown(fd->fd, SHUT_RDWR);
- REF_BY(fd, 1, reason); /* remove active status, but keep referenced */
gpr_mu_lock(&fd->watcher_mu);
+ REF_BY(fd, 1, reason); /* remove active status, but keep referenced */
if (!has_watchers(fd)) {
- GPR_ASSERT(!fd->closed);
fd->closed = 1;
close(fd->fd);
if (fd->on_done_closure) {
diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c
index 66d7e9b110..5d1fc68767 100644
--- a/src/core/iomgr/iomgr.c
+++ b/src/core/iomgr/iomgr.c
@@ -34,16 +34,18 @@
#include "src/core/iomgr/iomgr.h"
#include <stdlib.h>
+#include <string.h>
-#include "src/core/iomgr/iomgr_internal.h"
-#include "src/core/iomgr/alarm_internal.h"
-#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>
+#include "src/core/iomgr/iomgr_internal.h"
+#include "src/core/iomgr/alarm_internal.h"
+#include "src/core/support/string.h"
+
static gpr_mu g_mu;
static gpr_cv g_rcv;
static int g_shutdown;
@@ -124,6 +126,8 @@ void grpc_iomgr_shutdown(void) {
}
gpr_mu_unlock(&g_mu);
+ memset(&g_root_object, 0, sizeof(g_root_object));
+
grpc_alarm_list_shutdown();
grpc_iomgr_platform_shutdown();
diff --git a/src/core/iomgr/pollset_multipoller_with_epoll.c b/src/core/iomgr/pollset_multipoller_with_epoll.c
index 971b7b4a01..12f34c1a19 100644
--- a/src/core/iomgr/pollset_multipoller_with_epoll.c
+++ b/src/core/iomgr/pollset_multipoller_with_epoll.c
@@ -72,7 +72,7 @@ static void finally_add_fd(grpc_pollset *pollset, grpc_fd *fd) {
to this pollset whilst adding, but that should be benign. */
GPR_ASSERT(grpc_fd_begin_poll(fd, pollset, 0, 0, &watcher) == 0);
if (watcher.fd != NULL) {
- ev.events = EPOLLIN | EPOLLOUT | EPOLLET;
+ ev.events = (uint32_t)(EPOLLIN | EPOLLOUT | EPOLLET);
ev.data.ptr = fd;
err = epoll_ctl(h->epoll_fd, EPOLL_CTL_ADD, fd->fd, &ev);
if (err < 0) {
diff --git a/src/core/iomgr/udp_server.c b/src/core/iomgr/udp_server.c
index d4e8e99bce..96688054fb 100644
--- a/src/core/iomgr/udp_server.c
+++ b/src/core/iomgr/udp_server.c
@@ -94,9 +94,6 @@ static void unlink_if_unix_domain_socket(const struct sockaddr_un *un) {
/* the overall server */
struct grpc_udp_server {
- grpc_udp_server_cb cb;
- void *cb_arg;
-
gpr_mu mu;
gpr_cv cv;
@@ -132,8 +129,6 @@ grpc_udp_server *grpc_udp_server_create(void) {
s->active_ports = 0;
s->destroyed_ports = 0;
s->shutdown = 0;
- s->cb = NULL;
- s->cb_arg = NULL;
s->ports = gpr_malloc(sizeof(server_port) * INIT_PORT_CAP);
s->nports = 0;
s->port_capacity = INIT_PORT_CAP;
@@ -236,6 +231,11 @@ static int prepare_socket(int fd, const struct sockaddr *addr,
goto error;
}
+ if (!grpc_set_socket_nonblocking(fd, 1) || !grpc_set_socket_cloexec(fd, 1)) {
+ gpr_log(GPR_ERROR, "Unable to configure socket %d: %s", fd,
+ strerror(errno));
+ }
+
get_local_ip = 1;
rc = setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &get_local_ip,
sizeof(get_local_ip));
@@ -286,7 +286,7 @@ static void on_read(void *arg, int success) {
/* Tell the registered callback that data is available to read. */
GPR_ASSERT(sp->read_cb);
- sp->read_cb(sp->fd, sp->server->cb, sp->server->cb_arg);
+ sp->read_cb(sp->fd);
/* Re-arm the notification event so we get another chance to read. */
grpc_fd_notify_on_read(sp->emfd, &sp->read_closure);
@@ -305,7 +305,6 @@ static int add_socket_to_server(grpc_udp_server *s, int fd,
grpc_sockaddr_to_string(&addr_str, (struct sockaddr *)&addr, 1);
gpr_asprintf(&name, "udp-server-listener:%s", addr_str);
gpr_mu_lock(&s->mu);
- GPR_ASSERT(!s->cb && "must add ports before starting server");
/* append it to the list under a lock */
if (s->nports == s->port_capacity) {
s->port_capacity *= 2;
@@ -411,15 +410,10 @@ int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned index) {
}
void grpc_udp_server_start(grpc_udp_server *s, grpc_pollset **pollsets,
- size_t pollset_count,
- grpc_udp_server_cb new_transport_cb, void *cb_arg) {
+ size_t pollset_count) {
size_t i, j;
- GPR_ASSERT(new_transport_cb);
gpr_mu_lock(&s->mu);
- GPR_ASSERT(!s->cb);
GPR_ASSERT(s->active_ports == 0);
- s->cb = new_transport_cb;
- s->cb_arg = cb_arg;
s->pollsets = pollsets;
for (i = 0; i < s->nports; i++) {
for (j = 0; j < pollset_count; j++) {
diff --git a/src/core/iomgr/udp_server.h b/src/core/iomgr/udp_server.h
index 389f84ecca..c930e81cbc 100644
--- a/src/core/iomgr/udp_server.h
+++ b/src/core/iomgr/udp_server.h
@@ -39,21 +39,15 @@
/* Forward decl of grpc_udp_server */
typedef struct grpc_udp_server grpc_udp_server;
-/* New server callback: ep is the newly connected connection */
-typedef void (*grpc_udp_server_cb)(void *arg, grpc_endpoint *ep);
-
/* Called when data is available to read from the socket. */
-typedef void (*grpc_udp_server_read_cb)(int fd,
- grpc_udp_server_cb new_transport_cb,
- void *cb_arg);
+typedef void (*grpc_udp_server_read_cb)(int fd);
/* Create a server, initially not bound to any ports */
grpc_udp_server *grpc_udp_server_create(void);
/* Start listening to bound ports */
-void grpc_udp_server_start(grpc_udp_server *server, grpc_pollset **pollsets,
- size_t pollset_count, grpc_udp_server_cb cb,
- void *cb_arg);
+void grpc_udp_server_start(grpc_udp_server *udp_server, grpc_pollset **pollsets,
+ size_t pollset_count);
int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned index);