diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-02-04 17:35:17 -0800 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-02-04 17:35:17 -0800 |
commit | 027afee27799352539dae087e60a45290a9c70a1 (patch) | |
tree | 3d613959c10656c36fd5e82bb897ea2edbe26220 /src/core | |
parent | 6a09ca80d62e291163409d27cc78c8371d3af32e (diff) | |
parent | 53476f1d0e52dfa21fa5363fe29396e96748ab14 (diff) |
Merge github.com:google/grpc into http3
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/iomgr/resolve_address.c | 2 | ||||
-rw-r--r-- | src/core/iomgr/socket_utils_linux.c | 2 | ||||
-rw-r--r-- | src/core/iomgr/socket_utils_posix.c | 1 | ||||
-rw-r--r-- | src/core/iomgr/tcp_server_posix.c | 6 | ||||
-rw-r--r-- | src/core/support/log_linux.c | 6 | ||||
-rw-r--r-- | src/core/support/log_posix.c | 7 | ||||
-rw-r--r-- | src/core/support/string_posix.c | 3 | ||||
-rw-r--r-- | src/core/support/sync_posix.c | 11 | ||||
-rw-r--r-- | src/core/support/thd_posix.c | 8 | ||||
-rw-r--r-- | src/core/support/thd_win32.c | 8 | ||||
-rw-r--r-- | src/core/support/time.c | 16 | ||||
-rw-r--r-- | src/core/support/time_posix.c | 25 | ||||
-rw-r--r-- | src/core/surface/call.c | 7 | ||||
-rw-r--r-- | src/core/transport/chttp2_transport.c | 17 | ||||
-rw-r--r-- | src/core/tsi/ssl_transport_security.c | 22 |
15 files changed, 104 insertions, 37 deletions
diff --git a/src/core/iomgr/resolve_address.c b/src/core/iomgr/resolve_address.c index 01681168ce..575f884d91 100644 --- a/src/core/iomgr/resolve_address.c +++ b/src/core/iomgr/resolve_address.c @@ -31,7 +31,9 @@ * */ +#ifndef _POSIX_SOURCE #define _POSIX_SOURCE +#endif #include "src/core/iomgr/sockaddr.h" #include "src/core/iomgr/resolve_address.h" diff --git a/src/core/iomgr/socket_utils_linux.c b/src/core/iomgr/socket_utils_linux.c index f971cb33bc..7ef58940c2 100644 --- a/src/core/iomgr/socket_utils_linux.c +++ b/src/core/iomgr/socket_utils_linux.c @@ -31,7 +31,9 @@ * */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include <grpc/support/port_platform.h> #ifdef GPR_LINUX diff --git a/src/core/iomgr/socket_utils_posix.c b/src/core/iomgr/socket_utils_posix.c index 06c5033d45..9184b2a47c 100644 --- a/src/core/iomgr/socket_utils_posix.c +++ b/src/core/iomgr/socket_utils_posix.c @@ -35,7 +35,6 @@ #ifdef GPR_POSIX_SOCKETUTILS -#define _BSD_SOURCE #include "src/core/iomgr/socket_utils_posix.h" #include <fcntl.h> diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c index d169d23271..091f0aab1a 100644 --- a/src/core/iomgr/tcp_server_posix.c +++ b/src/core/iomgr/tcp_server_posix.c @@ -31,11 +31,15 @@ * */ +/* FIXME: "posix" files shouldn't be depending on _GNU_SOURCE */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include <grpc/support/port_platform.h> #ifdef GPR_POSIX_SOCKET -#define _GNU_SOURCE #include "src/core/iomgr/tcp_server.h" #include <limits.h> diff --git a/src/core/support/log_linux.c b/src/core/support/log_linux.c index a0307e1a9a..a64faa98bd 100644 --- a/src/core/support/log_linux.c +++ b/src/core/support/log_linux.c @@ -31,8 +31,14 @@ * */ +#ifndef _POSIX_SOURCE #define _POSIX_SOURCE +#endif + +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif + #include <grpc/support/port_platform.h> #ifdef GPR_LINUX diff --git a/src/core/support/log_posix.c b/src/core/support/log_posix.c index ab2d2e5a74..05f45de130 100644 --- a/src/core/support/log_posix.c +++ b/src/core/support/log_posix.c @@ -31,11 +31,16 @@ * */ -#ifndef _POSIX_C_SOURCE +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 200112L +#undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L #endif +/* FIXME: "posix" files probably shouldn't depend on _GNU_SOURCE */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif + #include <grpc/support/port_platform.h> #if defined(GPR_POSIX_LOG) diff --git a/src/core/support/string_posix.c b/src/core/support/string_posix.c index 57832810ad..a6bb8058e6 100644 --- a/src/core/support/string_posix.c +++ b/src/core/support/string_posix.c @@ -33,7 +33,8 @@ /* Posix code for gpr snprintf support. */ -#ifndef _POSIX_C_SOURCE +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 200112L +#undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L #endif diff --git a/src/core/support/sync_posix.c b/src/core/support/sync_posix.c index 7f0e4a95a4..a28a4c6bf4 100644 --- a/src/core/support/sync_posix.c +++ b/src/core/support/sync_posix.c @@ -33,11 +33,17 @@ /* Posix gpr synchroization support code. */ +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199309L +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 199309L +#endif + #include <grpc/support/port_platform.h> #ifdef GPR_POSIX_SYNC #include <errno.h> +#include <time.h> #include <grpc/support/log.h> #include <grpc/support/sync.h> #include <grpc/support/time.h> @@ -67,7 +73,10 @@ int gpr_cv_wait(gpr_cv *cv, gpr_mu *mu, gpr_timespec abs_deadline) { if (gpr_time_cmp(abs_deadline, gpr_inf_future) == 0) { err = pthread_cond_wait(cv, mu); } else { - err = pthread_cond_timedwait(cv, mu, &abs_deadline); + struct timespec abs_deadline_ts; + abs_deadline_ts.tv_sec = abs_deadline.tv_sec; + abs_deadline_ts.tv_nsec = abs_deadline.tv_nsec; + err = pthread_cond_timedwait(cv, mu, &abs_deadline_ts); } GPR_ASSERT(err == 0 || err == ETIMEDOUT || err == EAGAIN); return err == ETIMEDOUT; diff --git a/src/core/support/thd_posix.c b/src/core/support/thd_posix.c index bac1d9c220..74ca9424bb 100644 --- a/src/core/support/thd_posix.c +++ b/src/core/support/thd_posix.c @@ -62,17 +62,19 @@ int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg, const gpr_thd_options *options) { int thread_started; pthread_attr_t attr; + pthread_t p; struct thd_arg *a = gpr_malloc(sizeof(*a)); a->body = thd_body; a->arg = arg; GPR_ASSERT(pthread_attr_init(&attr) == 0); GPR_ASSERT(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0); - thread_started = (pthread_create(t, &attr, &thread_body, a) == 0); + thread_started = (pthread_create(&p, &attr, &thread_body, a) == 0); GPR_ASSERT(pthread_attr_destroy(&attr) == 0); if (!thread_started) { gpr_free(a); } + *t = (gpr_thd_id)p; return thread_started; } @@ -82,4 +84,8 @@ gpr_thd_options gpr_thd_options_default(void) { return options; } +gpr_thd_id gpr_thd_currentid(void) { + return (gpr_thd_id)pthread_self(); +} + #endif /* GPR_POSIX_SYNC */ diff --git a/src/core/support/thd_win32.c b/src/core/support/thd_win32.c index 1762f87f3c..2ee1417048 100644 --- a/src/core/support/thd_win32.c +++ b/src/core/support/thd_win32.c @@ -58,16 +58,18 @@ static DWORD WINAPI thread_body(void *v) { int gpr_thd_new(gpr_thd_id *t, void (*thd_body)(void *arg), void *arg, const gpr_thd_options *options) { HANDLE handle; + DWORD thread_id; struct thd_arg *a = gpr_malloc(sizeof(*a)); a->body = thd_body; a->arg = arg; *t = 0; - handle = CreateThread(NULL, 64 * 1024, thread_body, a, 0, NULL); + handle = CreateThread(NULL, 64 * 1024, thread_body, a, 0, &thread_id); if (handle == NULL) { gpr_free(a); } else { CloseHandle(handle); /* threads are "detached" */ } + *t = (gpr_thd_id)thread_id; return handle != NULL; } @@ -77,4 +79,8 @@ gpr_thd_options gpr_thd_options_default(void) { return options; } +gpr_thd_id gpr_thd_currentid(void) { + return (gpr_thd_id)GetCurrentThreadId(); +} + #endif /* GPR_WIN32 */ diff --git a/src/core/support/time.c b/src/core/support/time.c index 97243318fd..268a43c677 100644 --- a/src/core/support/time.c +++ b/src/core/support/time.c @@ -234,22 +234,6 @@ int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold) { } } -struct timeval gpr_timeval_from_timespec(gpr_timespec t) { - /* TODO(klempner): Consider whether this should round up, since it is likely - to be used for delays */ - struct timeval tv; - tv.tv_sec = t.tv_sec; - tv.tv_usec = t.tv_nsec / 1000; - return tv; -} - -gpr_timespec gpr_timespec_from_timeval(struct timeval t) { - gpr_timespec ts; - ts.tv_sec = t.tv_sec; - ts.tv_nsec = t.tv_usec * 1000; - return ts; -} - gpr_int32 gpr_time_to_millis(gpr_timespec t) { if (t.tv_sec >= 2147483) { if (t.tv_sec == 2147483 && t.tv_nsec < 648 * GPR_NS_PER_MS) { diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c index 9e11f8a865..7f0f028183 100644 --- a/src/core/support/time_posix.c +++ b/src/core/support/time_posix.c @@ -34,7 +34,8 @@ /* Posix code for gpr time support. */ /* So we get nanosleep and clock_* */ -#ifndef _POSIX_C_SOURCE +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 199309L +#undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199309L #endif @@ -47,11 +48,25 @@ #include <unistd.h> #include <grpc/support/time.h> +static struct timespec timespec_from_gpr(gpr_timespec gts) { + struct timespec rv; + rv.tv_sec = gts.tv_sec; + rv.tv_nsec = gts.tv_nsec; + return rv; +} + #if _POSIX_TIMERS > 0 +static gpr_timespec gpr_from_timespec(struct timespec ts) { + gpr_timespec rv; + rv.tv_sec = ts.tv_sec; + rv.tv_nsec = ts.tv_nsec; + return rv; +} + gpr_timespec gpr_now(void) { - gpr_timespec now; + struct timespec now; clock_gettime(CLOCK_REALTIME, &now); - return now; + return gpr_from_timespec(now); } #else /* For some reason Apple's OSes haven't implemented clock_gettime. */ @@ -69,6 +84,7 @@ gpr_timespec gpr_now(void) { void gpr_sleep_until(gpr_timespec until) { gpr_timespec now; gpr_timespec delta; + struct timespec delta_ts; for (;;) { /* We could simplify by using clock_nanosleep instead, but it might be @@ -79,7 +95,8 @@ void gpr_sleep_until(gpr_timespec until) { } delta = gpr_time_sub(until, now); - if (nanosleep(&delta, NULL) == 0) { + delta_ts = timespec_from_gpr(delta); + if (nanosleep(&delta_ts, NULL) == 0) { break; } } diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 8221401a70..ebd6ace962 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -495,17 +495,16 @@ static void finish_start_step(void *pc, grpc_op_error error) { static send_action choose_send_action(grpc_call *call) { switch (call->write_state) { case WRITE_STATE_INITIAL: - if (call->request_set[GRPC_IOREQ_SEND_INITIAL_METADATA] != - REQSET_EMPTY) { + if (is_op_live(call, GRPC_IOREQ_SEND_INITIAL_METADATA)) { call->write_state = WRITE_STATE_STARTED; return SEND_INITIAL_METADATA; } return SEND_NOTHING; case WRITE_STATE_STARTED: - if (call->request_set[GRPC_IOREQ_SEND_MESSAGE] != REQSET_EMPTY) { + if (is_op_live(call, GRPC_IOREQ_SEND_MESSAGE)) { return SEND_MESSAGE; } - if (call->request_set[GRPC_IOREQ_SEND_CLOSE] != REQSET_EMPTY) { + if (is_op_live(call, GRPC_IOREQ_SEND_CLOSE)) { call->write_state = WRITE_STATE_WRITE_CLOSED; finish_ioreq_op(call, GRPC_IOREQ_SEND_TRAILING_METADATA, GRPC_OP_OK); finish_ioreq_op(call, GRPC_IOREQ_SEND_STATUS, GRPC_OP_OK); diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index 0446e0ab9e..ea579cf4a5 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -327,6 +327,9 @@ static void maybe_start_some_streams(transport *t); static void become_skip_parser(transport *t); +static void recv_data(void *tp, gpr_slice *slices, size_t nslices, + grpc_endpoint_cb_status error); + /* * CONSTRUCTION/DESTRUCTION/REFCOUNTING */ @@ -381,8 +384,8 @@ static void ref_transport(transport *t) { gpr_ref(&t->refs); } static void init_transport(transport *t, grpc_transport_setup_callback setup, void *arg, const grpc_channel_args *channel_args, - grpc_endpoint *ep, grpc_mdctx *mdctx, - int is_client) { + grpc_endpoint *ep, gpr_slice *slices, size_t nslices, + grpc_mdctx *mdctx, int is_client) { size_t i; int j; grpc_transport_setup_result sr; @@ -420,6 +423,7 @@ static void init_transport(transport *t, grpc_transport_setup_callback setup, gpr_slice_buffer_init(&t->outbuf); gpr_slice_buffer_init(&t->qbuf); grpc_sopb_init(&t->nuke_later_sopb); + grpc_chttp2_hpack_parser_init(&t->hpack_parser, t->metadata_context); if (is_client) { gpr_slice_buffer_add(&t->qbuf, gpr_slice_from_copied_string(CLIENT_CONNECT_STRING)); @@ -474,12 +478,14 @@ static void init_transport(transport *t, grpc_transport_setup_callback setup, ref_transport(t); gpr_mu_unlock(&t->mu); + ref_transport(t); + recv_data(t, slices, nslices, GRPC_ENDPOINT_CB_OK); + sr = setup(arg, &t->base, t->metadata_context); lock(t); t->cb = sr.callbacks; t->cb_user_data = sr.user_data; - grpc_chttp2_hpack_parser_init(&t->hpack_parser, t->metadata_context); t->calling_back = 0; unlock(t); unref_transport(t); @@ -1752,7 +1758,6 @@ void grpc_create_chttp2_transport(grpc_transport_setup_callback setup, size_t nslices, grpc_mdctx *mdctx, int is_client) { transport *t = gpr_malloc(sizeof(transport)); - init_transport(t, setup, arg, channel_args, ep, mdctx, is_client); - ref_transport(t); - recv_data(t, slices, nslices, GRPC_ENDPOINT_CB_OK); + init_transport(t, setup, arg, channel_args, ep, slices, nslices, mdctx, + is_client); } diff --git a/src/core/tsi/ssl_transport_security.c b/src/core/tsi/ssl_transport_security.c index 0f8cbccb62..e23421fc15 100644 --- a/src/core/tsi/ssl_transport_security.c +++ b/src/core/tsi/ssl_transport_security.c @@ -37,6 +37,7 @@ #include <grpc/support/log.h> #include <grpc/support/sync.h> +#include <grpc/support/thd.h> #include <grpc/support/useful.h> #include "src/core/tsi/transport_security.h" @@ -103,11 +104,32 @@ typedef struct { /* --- Library Initialization. ---*/ static gpr_once init_openssl_once = GPR_ONCE_INIT; +static gpr_mu *openssl_mutexes = NULL; + +static void openssl_locking_cb(int mode, int type, const char* file, int line) { + if (mode & CRYPTO_LOCK) { + gpr_mu_lock(&openssl_mutexes[type]); + } else { + gpr_mu_unlock(&openssl_mutexes[type]); + } +} + +static unsigned long openssl_thread_id_cb(void) { + return (unsigned long)gpr_thd_currentid(); +} static void init_openssl(void) { + int i; SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_all_algorithms(); + openssl_mutexes = malloc(CRYPTO_num_locks() * sizeof(gpr_mu)); + GPR_ASSERT(openssl_mutexes != NULL); + for (i = 0; i < CRYPTO_num_locks(); i++) { + gpr_mu_init(&openssl_mutexes[i]); + } + CRYPTO_set_locking_callback(openssl_locking_cb); + CRYPTO_set_id_callback(openssl_thread_id_cb); } /* --- Ssl utils. ---*/ |