aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-02-17 22:02:34 -0800
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-02-17 22:02:34 -0800
commit1ece67cba24c9872ae8fbd2218c57bac8ff9794d (patch)
treefc1333e10143161860d2be8734dd0b5c47301956 /src/core
parenta94beff94c26c8940c6c224943c53ffda73025bb (diff)
parent560292ab6720aebe6fd40cc1f96e28faa92761d7 (diff)
Merge github.com:grpc/grpc into c++api
Diffstat (limited to 'src/core')
-rw-r--r--src/core/iomgr/fd_posix.c7
-rw-r--r--src/core/iomgr/pollset_posix.c1
-rw-r--r--src/core/iomgr/tcp_server_posix.c23
-rw-r--r--src/core/security/security_context.c10
-rw-r--r--src/core/transport/chttp2_transport.c11
5 files changed, 41 insertions, 11 deletions
diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c
index 737ee016aa..cc57830551 100644
--- a/src/core/iomgr/fd_posix.c
+++ b/src/core/iomgr/fd_posix.c
@@ -104,14 +104,17 @@ static void destroy(grpc_fd *fd) {
}
static void ref_by(grpc_fd *fd, int n) {
- gpr_atm_no_barrier_fetch_add(&fd->refst, n);
+ GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0);
}
static void unref_by(grpc_fd *fd, int n) {
- if (gpr_atm_full_fetch_add(&fd->refst, -n) == n) {
+ gpr_atm old = gpr_atm_full_fetch_add(&fd->refst, -n);
+ if (old == n) {
grpc_iomgr_add_callback(fd->on_done, fd->on_done_user_data);
freelist_fd(fd);
grpc_iomgr_unref();
+ } else {
+ GPR_ASSERT(old > n);
}
}
diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c
index 53c9806fb9..1245d22dde 100644
--- a/src/core/iomgr/pollset_posix.c
+++ b/src/core/iomgr/pollset_posix.c
@@ -214,6 +214,7 @@ static void unary_poll_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) {
* unary poller */
grpc_fd_unref(fds[0]);
pollset->data.ptr = fd;
+ grpc_fd_ref(fd);
}
}
diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c
index a4c766eba4..c8df07c917 100644
--- a/src/core/iomgr/tcp_server_posix.c
+++ b/src/core/iomgr/tcp_server_posix.c
@@ -42,17 +42,18 @@
#include "src/core/iomgr/tcp_server.h"
-#include <limits.h>
+#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
-#include <sys/socket.h>
#include <unistd.h>
-#include <string.h>
-#include <errno.h>
#include "src/core/iomgr/pollset_posix.h"
#include "src/core/iomgr/resolve_address.h"
@@ -83,6 +84,14 @@ typedef struct {
int addr_len;
} server_port;
+static void unlink_if_unix_domain_socket(const struct sockaddr_un *un) {
+ struct stat st;
+
+ if (stat(un->sun_path, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) {
+ unlink(un->sun_path);
+ }
+}
+
/* the overall server */
struct grpc_tcp_server {
grpc_tcp_server_cb cb;
@@ -130,7 +139,7 @@ void grpc_tcp_server_destroy(grpc_tcp_server *s) {
for (i = 0; i < s->nports; i++) {
server_port *sp = &s->ports[i];
if (sp->addr.sockaddr.sa_family == AF_UNIX) {
- unlink(sp->addr.un.sun_path);
+ unlink_if_unix_domain_socket(&sp->addr.un);
}
grpc_fd_orphan(sp->emfd, NULL, NULL);
}
@@ -301,6 +310,10 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
socklen_t sockname_len;
int port;
+ if (((struct sockaddr *)addr)->sa_family == AF_UNIX) {
+ unlink_if_unix_domain_socket(addr);
+ }
+
/* Check if this is a wildcard port, and if so, try to keep the port the same
as some previously created listener. */
if (grpc_sockaddr_get_port(addr) == 0) {
diff --git a/src/core/security/security_context.c b/src/core/security/security_context.c
index adb0269792..1909617614 100644
--- a/src/core/security/security_context.c
+++ b/src/core/security/security_context.c
@@ -349,11 +349,13 @@ static grpc_security_status ssl_channel_check_peer(grpc_security_context *ctx,
void *user_data) {
grpc_ssl_channel_security_context *c =
(grpc_ssl_channel_security_context *)ctx;
- grpc_security_status status = ssl_check_peer(c->overridden_target_name != NULL
- ? c->overridden_target_name
- : c->target_name,
- &peer);
+ grpc_security_status status;
+ tsi_peer_destruct(&c->peer);
c->peer = peer;
+ status = ssl_check_peer(c->overridden_target_name != NULL
+ ? c->overridden_target_name
+ : c->target_name,
+ &peer);
return status;
}
diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c
index d15962e5c5..dcd01718a0 100644
--- a/src/core/transport/chttp2_transport.c
+++ b/src/core/transport/chttp2_transport.c
@@ -184,11 +184,13 @@ struct transport {
gpr_uint8 is_client;
gpr_mu mu;
+ gpr_cv cv;
/* basic state management - what are we doing at the moment? */
gpr_uint8 reading;
gpr_uint8 writing;
gpr_uint8 calling_back;
+ gpr_uint8 destroying;
error_state error_state;
/* stream indexing */
@@ -362,6 +364,7 @@ static void unref_transport(transport *t) {
gpr_mu_unlock(&t->mu);
gpr_mu_destroy(&t->mu);
+ gpr_cv_destroy(&t->cv);
/* callback remaining pings: they're not allowed to call into the transpot,
and maybe they hold resources that need to be freed */
@@ -397,6 +400,7 @@ static void init_transport(transport *t, grpc_transport_setup_callback setup,
/* one ref is for destroy, the other for when ep becomes NULL */
gpr_ref_init(&t->refs, 2);
gpr_mu_init(&t->mu);
+ gpr_cv_init(&t->cv);
t->metadata_context = mdctx;
t->str_grpc_timeout =
grpc_mdstr_from_string(t->metadata_context, "grpc-timeout");
@@ -405,6 +409,7 @@ static void init_transport(transport *t, grpc_transport_setup_callback setup,
t->error_state = ERROR_STATE_NONE;
t->next_stream_id = is_client ? 1 : 2;
t->last_incoming_stream_id = 0;
+ t->destroying = 0;
t->is_client = is_client;
t->outgoing_window = DEFAULT_WINDOW;
t->incoming_window = DEFAULT_WINDOW;
@@ -484,6 +489,7 @@ static void init_transport(transport *t, grpc_transport_setup_callback setup,
t->cb = sr.callbacks;
t->cb_user_data = sr.user_data;
t->calling_back = 0;
+ if (t->destroying) gpr_cv_signal(&t->cv);
unlock(t);
ref_transport(t);
@@ -496,6 +502,10 @@ static void destroy_transport(grpc_transport *gt) {
transport *t = (transport *)gt;
gpr_mu_lock(&t->mu);
+ t->destroying = 1;
+ while (t->calling_back) {
+ gpr_cv_wait(&t->cv, &t->mu, gpr_inf_future);
+ }
t->cb = NULL;
gpr_mu_unlock(&t->mu);
@@ -755,6 +765,7 @@ static void unlock(transport *t) {
if (perform_callbacks || call_closed || num_goaways) {
lock(t);
t->calling_back = 0;
+ if (t->destroying) gpr_cv_signal(&t->cv);
unlock(t);
unref_transport(t);
}