Merge github.com:grpc/grpc into flaky-timeouts

pull/3487/head
Craig Tiller 10 years ago
commit 6b870e2984
  1. 2
      BUILD
  2. 8
      Makefile
  3. 2216
      build.yaml
  4. 6
      gRPC.podspec
  5. 3
      include/grpc++/impl/call.h
  6. 1
      include/grpc++/security/auth_metadata_processor.h
  7. 7
      include/grpc++/server.h
  8. 4
      include/grpc/census.h
  9. 2
      include/grpc/compression.h
  10. 4
      include/grpc/grpc.h
  11. 4
      include/grpc/grpc_security.h
  12. 13
      include/grpc/support/port_platform.h
  13. 2
      include/grpc/support/slice_buffer.h
  14. 2
      src/core/census/grpc_filter.c
  15. 10
      src/core/channel/compress_filter.c
  16. 4
      src/core/channel/http_client_filter.c
  17. 6
      src/core/channel/http_server_filter.c
  18. 8
      src/core/client_config/subchannel.h
  19. 4
      src/core/iomgr/pollset_multipoller_with_epoll.c
  20. 3
      src/core/iomgr/pollset_multipoller_with_poll_posix.c
  21. 3
      src/core/iomgr/pollset_posix.c
  22. 6
      src/core/iomgr/resolve_address_posix.c
  23. 3
      src/core/iomgr/resolve_address_windows.c
  24. 9
      src/core/iomgr/tcp_posix.c
  25. 8
      src/core/iomgr/udp_server.c
  26. 8
      src/core/iomgr/udp_server.h
  27. 10
      src/core/security/client_auth_filter.c
  28. 48
      src/core/support/block_annotate.h
  29. 6
      src/core/support/file.c
  30. 9
      src/core/support/slice_buffer.c
  31. 7
      src/core/support/time_posix.c
  32. 2
      src/core/support/time_precise.h
  33. 4
      src/core/support/time_win32.c
  34. 6
      src/core/surface/call.c
  35. 25
      src/core/surface/channel.c
  36. 9
      src/core/surface/server.c
  37. 2
      src/core/transport/chttp2/incoming_metadata.c
  38. 4
      src/core/transport/chttp2/stream_encoder.c
  39. 2
      src/core/transport/chttp2_transport.c
  40. 44
      src/core/transport/metadata.c
  41. 6
      src/core/transport/metadata.h
  42. 17
      src/cpp/proto/proto_utils.cc
  43. 2
      src/cpp/server/secure_server_credentials.h
  44. 16
      src/ruby/spec/generic/rpc_server_spec.rb
  45. 8
      templates/Makefile.template
  46. 2
      templates/vsprojects/global.props.template
  47. 4
      test/core/end2end/tests/metadata.c
  48. 8
      test/core/iomgr/udp_server_test.c
  49. 16
      test/core/transport/metadata_test.c
  50. 43
      test/core/util/test_config.c
  51. 2
      test/cpp/end2end/streaming_throughput_test.cc
  52. 2
      test/cpp/interop/client_helper.h
  53. 2
      tools/buildgen/build-cleaner.py
  54. 13
      tools/distrib/clang_format_code.sh
  55. 6
      tools/dockerfile/grpc_clang_format/Dockerfile
  56. 30
      tools/dockerfile/grpc_clang_format/clang_format_all_the_things.sh
  57. 1
      tools/doxygen/Doxyfile.core.internal
  58. 2
      tools/jenkins/build_docker_and_run_tests.sh
  59. 14
      tools/jenkins/run_jenkins.sh
  60. 2
      tools/run_tests/jobset.py
  61. 2
      tools/run_tests/run_sanity.sh
  62. 16
      tools/run_tests/run_tests.py
  63. 2
      tools/run_tests/sources_and_headers.json
  64. 2
      vsprojects/global.props
  65. 1
      vsprojects/vcxproj/gpr/gpr.vcxproj
  66. 3
      vsprojects/vcxproj/gpr/gpr.vcxproj.filters

@ -44,6 +44,7 @@ package(default_visibility = ["//visibility:public"])
cc_library( cc_library(
name = "gpr", name = "gpr",
srcs = [ srcs = [
"src/core/support/block_annotate.h",
"src/core/support/env.h", "src/core/support/env.h",
"src/core/support/file.h", "src/core/support/file.h",
"src/core/support/murmur_hash.h", "src/core/support/murmur_hash.h",
@ -1023,6 +1024,7 @@ objc_library(
"include/grpc/support/tls_msvc.h", "include/grpc/support/tls_msvc.h",
"include/grpc/support/tls_pthread.h", "include/grpc/support/tls_pthread.h",
"include/grpc/support/useful.h", "include/grpc/support/useful.h",
"src/core/support/block_annotate.h",
"src/core/support/env.h", "src/core/support/env.h",
"src/core/support/file.h", "src/core/support/file.h",
"src/core/support/murmur_hash.h", "src/core/support/murmur_hash.h",

@ -92,7 +92,7 @@ CXX_opt = $(DEFAULT_CXX)
LD_opt = $(DEFAULT_CC) LD_opt = $(DEFAULT_CC)
LDXX_opt = $(DEFAULT_CXX) LDXX_opt = $(DEFAULT_CXX)
CPPFLAGS_opt = -O2 CPPFLAGS_opt = -O2
LDFLAGS_opt = LDFLAGS_opt = -rdynamic
DEFINES_opt = NDEBUG DEFINES_opt = NDEBUG
VALID_CONFIG_basicprof = 1 VALID_CONFIG_basicprof = 1
@ -119,7 +119,7 @@ CXX_dbg = $(DEFAULT_CXX)
LD_dbg = $(DEFAULT_CC) LD_dbg = $(DEFAULT_CC)
LDXX_dbg = $(DEFAULT_CXX) LDXX_dbg = $(DEFAULT_CXX)
CPPFLAGS_dbg = -O0 CPPFLAGS_dbg = -O0
LDFLAGS_dbg = LDFLAGS_dbg = -rdynamic
DEFINES_dbg = _DEBUG DEBUG DEFINES_dbg = _DEBUG DEBUG
VALID_CONFIG_mutrace = 1 VALID_CONFIG_mutrace = 1
@ -139,7 +139,7 @@ LD_valgrind = $(DEFAULT_CC)
LDXX_valgrind = $(DEFAULT_CXX) LDXX_valgrind = $(DEFAULT_CXX)
CPPFLAGS_valgrind = -O0 CPPFLAGS_valgrind = -O0
OPENSSL_CFLAGS_valgrind = -DPURIFY OPENSSL_CFLAGS_valgrind = -DPURIFY
LDFLAGS_valgrind = LDFLAGS_valgrind = -rdynamic
DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20 DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
VALID_CONFIG_tsan = 1 VALID_CONFIG_tsan = 1
@ -190,7 +190,7 @@ CXX_gcov = g++
LD_gcov = gcc LD_gcov = gcc
LDXX_gcov = g++ LDXX_gcov = g++
CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
LDFLAGS_gcov = -fprofile-arcs -ftest-coverage LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic
DEFINES_gcov = _DEBUG DEBUG DEFINES_gcov = _DEBUG DEBUG

File diff suppressed because it is too large Load Diff

@ -61,7 +61,8 @@ Pod::Spec.new do |s|
# Core cross-platform gRPC library, written in C. # Core cross-platform gRPC library, written in C.
s.subspec 'C-Core' do |ss| s.subspec 'C-Core' do |ss|
ss.source_files = 'src/core/support/env.h', ss.source_files = 'src/core/support/block_annotate.h',
'src/core/support/env.h',
'src/core/support/file.h', 'src/core/support/file.h',
'src/core/support/murmur_hash.h', 'src/core/support/murmur_hash.h',
'src/core/support/stack_lockfree.h', 'src/core/support/stack_lockfree.h',
@ -414,7 +415,8 @@ Pod::Spec.new do |s|
'src/core/census/operation.c', 'src/core/census/operation.c',
'src/core/census/tracing.c' 'src/core/census/tracing.c'
ss.private_header_files = 'src/core/support/env.h', ss.private_header_files = 'src/core/support/block_annotate.h',
'src/core/support/env.h',
'src/core/support/file.h', 'src/core/support/file.h',
'src/core/support/murmur_hash.h', 'src/core/support/murmur_hash.h',
'src/core/support/stack_lockfree.h', 'src/core/support/stack_lockfree.h',

@ -248,8 +248,7 @@ class CallOpRecvMessage {
if (*status) { if (*status) {
got_message = true; got_message = true;
*status = SerializationTraits<R>::Deserialize(recv_buf_, message_, *status = SerializationTraits<R>::Deserialize(recv_buf_, message_,
max_message_size) max_message_size).ok();
.ok();
} else { } else {
got_message = false; got_message = false;
grpc_byte_buffer_destroy(recv_buf_); grpc_byte_buffer_destroy(recv_buf_);

@ -71,4 +71,3 @@ class AuthMetadataProcessor {
} // namespace grpc } // namespace grpc
#endif // GRPCXX_AUTH_METADATA_PROCESSOR_H_ #endif // GRPCXX_AUTH_METADATA_PROCESSOR_H_

@ -215,11 +215,10 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE { bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE {
bool serialization_status = bool serialization_status =
*status && payload_ && *status && payload_ &&
SerializationTraits<Message>::Deserialize(payload_, request_, SerializationTraits<Message>::Deserialize(
server_->max_message_size_) payload_, request_, server_->max_message_size_).ok();
.ok();
bool ret = RegisteredAsyncRequest::FinalizeResult(tag, status); bool ret = RegisteredAsyncRequest::FinalizeResult(tag, status);
*status = serialization_status && *status; *status = serialization_status&&* status;
return ret; return ret;
} }

@ -424,8 +424,8 @@ extern census_aggregation_ops census_agg_window;
construction via census_define_view(). */ construction via census_define_view(). */
typedef struct { typedef struct {
const census_aggregation_ops *ops; const census_aggregation_ops *ops;
const void const void *
*create_arg; /* Argument to be used for aggregation initialization. */ create_arg; /* Argument to be used for aggregation initialization. */
} census_aggregation; } census_aggregation;
/** A census view type. Opaque. */ /** A census view type. Opaque. */

@ -95,7 +95,7 @@ void grpc_compression_options_init(grpc_compression_options *opts);
/** Mark \a algorithm as enabled in \a opts. */ /** Mark \a algorithm as enabled in \a opts. */
void grpc_compression_options_enable_algorithm( void grpc_compression_options_enable_algorithm(
grpc_compression_options *opts, grpc_compression_algorithm algorithm); grpc_compression_options *opts, grpc_compression_algorithm algorithm);
/** Mark \a algorithm as disabled in \a opts. */ /** Mark \a algorithm as disabled in \a opts. */
void grpc_compression_options_disable_algorithm( void grpc_compression_options_disable_algorithm(

@ -595,8 +595,8 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
void grpc_call_destroy(grpc_call *call); void grpc_call_destroy(grpc_call *call);
/** Request notification of a new call. /** Request notification of a new call.
Once a call is received, a notification tagged with \a tag_new is added to Once a call is received, a notification tagged with \a tag_new is added to
\a cq_for_notification. \a call, \a details and \a request_metadata are \a cq_for_notification. \a call, \a details and \a request_metadata are
updated with the appropriate call information. \a cq_bound_to_call is bound updated with the appropriate call information. \a cq_bound_to_call is bound
to \a call, and batch operation notifications for that call will be posted to \a call, and batch operation notifications for that call will be posted
to \a cq_bound_to_call. to \a cq_bound_to_call.

@ -123,8 +123,8 @@ grpc_credentials *grpc_google_refresh_token_credentials_create(
/* Creates an Oauth2 Access Token credentials with an access token that was /* Creates an Oauth2 Access Token credentials with an access token that was
aquired by an out of band mechanism. */ aquired by an out of band mechanism. */
grpc_credentials *grpc_access_token_credentials_create( grpc_credentials *grpc_access_token_credentials_create(const char *access_token,
const char *access_token, void *reserved); void *reserved);
/* Creates an IAM credentials object for connecting to Google. */ /* Creates an IAM credentials object for connecting to Google. */
grpc_credentials *grpc_google_iam_credentials_create( grpc_credentials *grpc_google_iam_credentials_create(

@ -46,10 +46,13 @@
#define NOMINMAX #define NOMINMAX
#endif /* NOMINMAX */ #endif /* NOMINMAX */
#if defined(_WIN32_WINNT) #ifndef _WIN32_WINNT
#if _WIN32_WINNT < 0x0600 #error \
#undef _WIN32_WINNT "Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
#define _WIN32_WINNT 0x0600 #else /* !defined(_WIN32_WINNT) */
#if (_WIN32_WINNT < 0x0600)
#error \
"Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)"
#endif /* _WIN32_WINNT < 0x0600 */ #endif /* _WIN32_WINNT < 0x0600 */
#endif /* defined(_WIN32_WINNT) */ #endif /* defined(_WIN32_WINNT) */
@ -121,6 +124,7 @@
#define GPR_GETPID_IN_UNISTD_H 1 #define GPR_GETPID_IN_UNISTD_H 1
#define GPR_HAVE_MSG_NOSIGNAL 1 #define GPR_HAVE_MSG_NOSIGNAL 1
#elif defined(__linux__) #elif defined(__linux__)
#define GPR_POSIX_CRASH_HANDLER 1
#define GPR_PLATFORM_STRING "linux" #define GPR_PLATFORM_STRING "linux"
#ifndef _BSD_SOURCE #ifndef _BSD_SOURCE
#define _BSD_SOURCE #define _BSD_SOURCE
@ -188,6 +192,7 @@
#define GPR_PLATFORM_STRING "osx" #define GPR_PLATFORM_STRING "osx"
#define GPR_CPU_POSIX 1 #define GPR_CPU_POSIX 1
#define GPR_GCC_TLS 1 #define GPR_GCC_TLS 1
#define GPR_POSIX_CRASH_HANDLER 1
#endif #endif
#define GPR_GCC_ATOMIC 1 #define GPR_GCC_ATOMIC 1
#define GPR_POSIX_LOG 1 #define GPR_POSIX_LOG 1

@ -87,7 +87,7 @@ void gpr_slice_buffer_swap(gpr_slice_buffer *a, gpr_slice_buffer *b);
/* move all of the elements of src into dst */ /* move all of the elements of src into dst */
void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst); void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst);
/* remove n bytes from the end of a slice buffer */ /* remove n bytes from the end of a slice buffer */
void gpr_slice_buffer_trim_end(gpr_slice_buffer *src, size_t n); void gpr_slice_buffer_trim_end(gpr_slice_buffer *src, size_t n, gpr_slice_buffer *garbage);
#ifdef __cplusplus #ifdef __cplusplus
} }

@ -168,7 +168,7 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
int is_first, int is_last) { int is_first, int is_last) {
channel_data *chand = elem->channel_data; channel_data *chand = elem->channel_data;
GPR_ASSERT(chand != NULL); GPR_ASSERT(chand != NULL);
chand->path_str = grpc_mdstr_from_string(mdctx, ":path", 0); chand->path_str = grpc_mdstr_from_string(mdctx, ":path");
} }
static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,

@ -331,13 +331,13 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
channeld->default_compression_algorithm; channeld->default_compression_algorithm;
channeld->mdstr_request_compression_algorithm_key = channeld->mdstr_request_compression_algorithm_key =
grpc_mdstr_from_string(mdctx, GRPC_COMPRESS_REQUEST_ALGORITHM_KEY, 0); grpc_mdstr_from_string(mdctx, GRPC_COMPRESS_REQUEST_ALGORITHM_KEY);
channeld->mdstr_outgoing_compression_algorithm_key = channeld->mdstr_outgoing_compression_algorithm_key =
grpc_mdstr_from_string(mdctx, "grpc-encoding", 0); grpc_mdstr_from_string(mdctx, "grpc-encoding");
channeld->mdstr_compression_capabilities_key = channeld->mdstr_compression_capabilities_key =
grpc_mdstr_from_string(mdctx, "grpc-accept-encoding", 0); grpc_mdstr_from_string(mdctx, "grpc-accept-encoding");
for (algo_idx = 0; algo_idx < GRPC_COMPRESS_ALGORITHMS_COUNT; ++algo_idx) { for (algo_idx = 0; algo_idx < GRPC_COMPRESS_ALGORITHMS_COUNT; ++algo_idx) {
char *algorithm_name; char *algorithm_name;
@ -351,7 +351,7 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
grpc_mdelem_from_metadata_strings( grpc_mdelem_from_metadata_strings(
mdctx, mdctx,
GRPC_MDSTR_REF(channeld->mdstr_outgoing_compression_algorithm_key), GRPC_MDSTR_REF(channeld->mdstr_outgoing_compression_algorithm_key),
grpc_mdstr_from_string(mdctx, algorithm_name, 0)); grpc_mdstr_from_string(mdctx, algorithm_name));
if (algo_idx > 0) { if (algo_idx > 0) {
supported_algorithms_names[supported_algorithms_idx++] = algorithm_name; supported_algorithms_names[supported_algorithms_idx++] = algorithm_name;
} }
@ -365,7 +365,7 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
channeld->mdelem_accept_encoding = grpc_mdelem_from_metadata_strings( channeld->mdelem_accept_encoding = grpc_mdelem_from_metadata_strings(
mdctx, GRPC_MDSTR_REF(channeld->mdstr_compression_capabilities_key), mdctx, GRPC_MDSTR_REF(channeld->mdstr_compression_capabilities_key),
grpc_mdstr_from_string(mdctx, accept_encoding_str, 0)); grpc_mdstr_from_string(mdctx, accept_encoding_str));
gpr_free(accept_encoding_str); gpr_free(accept_encoding_str);
GPR_ASSERT(!is_last); GPR_ASSERT(!is_last);

@ -239,7 +239,7 @@ static grpc_mdstr *user_agent_from_args(grpc_mdctx *mdctx,
tmp = gpr_strvec_flatten(&v, NULL); tmp = gpr_strvec_flatten(&v, NULL);
gpr_strvec_destroy(&v); gpr_strvec_destroy(&v);
result = grpc_mdstr_from_string(mdctx, tmp, 0); result = grpc_mdstr_from_string(mdctx, tmp);
gpr_free(tmp); gpr_free(tmp);
return result; return result;
@ -267,7 +267,7 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc"); grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc");
channeld->status = grpc_mdelem_from_strings(mdctx, ":status", "200"); channeld->status = grpc_mdelem_from_strings(mdctx, ":status", "200");
channeld->user_agent = grpc_mdelem_from_metadata_strings( channeld->user_agent = grpc_mdelem_from_metadata_strings(
mdctx, grpc_mdstr_from_string(mdctx, "user-agent", 0), mdctx, grpc_mdstr_from_string(mdctx, "user-agent"),
user_agent_from_args(mdctx, channel_args)); user_agent_from_args(mdctx, channel_args));
} }

@ -273,9 +273,9 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
channeld->http_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "http"); channeld->http_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "http");
channeld->https_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "https"); channeld->https_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "https");
channeld->grpc_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "grpc"); channeld->grpc_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "grpc");
channeld->path_key = grpc_mdstr_from_string(mdctx, ":path", 0); channeld->path_key = grpc_mdstr_from_string(mdctx, ":path");
channeld->authority_key = grpc_mdstr_from_string(mdctx, ":authority", 0); channeld->authority_key = grpc_mdstr_from_string(mdctx, ":authority");
channeld->host_key = grpc_mdstr_from_string(mdctx, "host", 0); channeld->host_key = grpc_mdstr_from_string(mdctx, "host");
channeld->content_type = channeld->content_type =
grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc"); grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc");

@ -64,13 +64,13 @@ typedef struct grpc_subchannel_args grpc_subchannel_args;
#define GRPC_SUBCHANNEL_REF_EXTRA_ARGS #define GRPC_SUBCHANNEL_REF_EXTRA_ARGS
#endif #endif
void grpc_subchannel_ref( void grpc_subchannel_ref(grpc_subchannel *channel
grpc_subchannel *channel GRPC_SUBCHANNEL_REF_EXTRA_ARGS); GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx, void grpc_subchannel_unref(grpc_exec_ctx *exec_ctx,
grpc_subchannel *channel grpc_subchannel *channel
GRPC_SUBCHANNEL_REF_EXTRA_ARGS); GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
void grpc_subchannel_call_ref( void grpc_subchannel_call_ref(grpc_subchannel_call *call
grpc_subchannel_call *call GRPC_SUBCHANNEL_REF_EXTRA_ARGS); GRPC_SUBCHANNEL_REF_EXTRA_ARGS);
void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx,
grpc_subchannel_call *call grpc_subchannel_call *call
GRPC_SUBCHANNEL_REF_EXTRA_ARGS); GRPC_SUBCHANNEL_REF_EXTRA_ARGS);

@ -42,6 +42,7 @@
#include <unistd.h> #include <unistd.h>
#include "src/core/iomgr/fd_posix.h" #include "src/core/iomgr/fd_posix.h"
#include "src/core/support/block_annotate.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
@ -179,7 +180,9 @@ static void multipoll_with_epoll_pollset_maybe_work_and_unlock(
pfds[1].events = POLLIN; pfds[1].events = POLLIN;
pfds[1].revents = 0; pfds[1].revents = 0;
GRPC_SCHEDULING_START_BLOCKING_REGION;
poll_rv = grpc_poll_function(pfds, 2, timeout_ms); poll_rv = grpc_poll_function(pfds, 2, timeout_ms);
GRPC_SCHEDULING_END_BLOCKING_REGION;
if (poll_rv < 0) { if (poll_rv < 0) {
if (errno != EINTR) { if (errno != EINTR) {
@ -193,6 +196,7 @@ static void multipoll_with_epoll_pollset_maybe_work_and_unlock(
} }
if (pfds[1].revents) { if (pfds[1].revents) {
do { do {
/* The following epoll_wait never blocks; it has a timeout of 0 */
ep_rv = epoll_wait(h->epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, 0); ep_rv = epoll_wait(h->epoll_fd, ep_ev, GRPC_EPOLL_MAX_EVENTS, 0);
if (ep_rv < 0) { if (ep_rv < 0) {
if (errno != EINTR) { if (errno != EINTR) {

@ -44,6 +44,7 @@
#include "src/core/iomgr/fd_posix.h" #include "src/core/iomgr/fd_posix.h"
#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/iomgr_internal.h"
#include "src/core/support/block_annotate.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/useful.h> #include <grpc/support/useful.h>
@ -147,7 +148,9 @@ static void multipoll_with_poll_pollset_maybe_work_and_unlock(
POLLOUT, &watchers[i]); POLLOUT, &watchers[i]);
} }
GRPC_SCHEDULING_START_BLOCKING_REGION;
r = grpc_poll_function(pfds, pfd_count, timeout); r = grpc_poll_function(pfds, pfd_count, timeout);
GRPC_SCHEDULING_END_BLOCKING_REGION;
for (i = 1; i < pfd_count; i++) { for (i = 1; i < pfd_count; i++) {
grpc_fd_end_poll(exec_ctx, &watchers[i], pfds[i].revents & POLLIN, grpc_fd_end_poll(exec_ctx, &watchers[i], pfds[i].revents & POLLIN,

@ -47,6 +47,7 @@
#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/socket_utils_posix.h" #include "src/core/iomgr/socket_utils_posix.h"
#include "src/core/profiling/timers.h" #include "src/core/profiling/timers.h"
#include "src/core/support/block_annotate.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/thd.h> #include <grpc/support/thd.h>
@ -468,7 +469,9 @@ static void basic_pollset_maybe_work_and_unlock(grpc_exec_ctx *exec_ctx,
/* poll fd count (argument 2) is shortened by one if we have no events /* poll fd count (argument 2) is shortened by one if we have no events
to poll on - such that it only includes the kicker */ to poll on - such that it only includes the kicker */
GRPC_SCHEDULING_START_BLOCKING_REGION;
r = grpc_poll_function(pfd, nfds, timeout); r = grpc_poll_function(pfd, nfds, timeout);
GRPC_SCHEDULING_END_BLOCKING_REGION;
GRPC_TIMER_MARK(GRPC_PTAG_POLL_FINISHED, r); GRPC_TIMER_MARK(GRPC_PTAG_POLL_FINISHED, r);
if (fd) { if (fd) {

@ -43,6 +43,7 @@
#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/sockaddr_utils.h" #include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/support/block_annotate.h"
#include "src/core/support/string.h" #include "src/core/support/string.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/host_port.h> #include <grpc/support/host_port.h>
@ -103,13 +104,18 @@ grpc_resolved_addresses *grpc_blocking_resolve_address(
hints.ai_socktype = SOCK_STREAM; /* stream socket */ hints.ai_socktype = SOCK_STREAM; /* stream socket */
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
GRPC_SCHEDULING_START_BLOCKING_REGION;
s = getaddrinfo(host, port, &hints, &result); s = getaddrinfo(host, port, &hints, &result);
GRPC_SCHEDULING_END_BLOCKING_REGION;
if (s != 0) { if (s != 0) {
/* Retry if well-known service name is recognized */ /* Retry if well-known service name is recognized */
char *svc[][2] = {{"http", "80"}, {"https", "443"}}; char *svc[][2] = {{"http", "80"}, {"https", "443"}};
for (i = 0; i < GPR_ARRAY_SIZE(svc); i++) { for (i = 0; i < GPR_ARRAY_SIZE(svc); i++) {
if (strcmp(port, svc[i][0]) == 0) { if (strcmp(port, svc[i][0]) == 0) {
GRPC_SCHEDULING_START_BLOCKING_REGION;
s = getaddrinfo(host, svc[i][1], &hints, &result); s = getaddrinfo(host, svc[i][1], &hints, &result);
GRPC_SCHEDULING_END_BLOCKING_REGION;
break; break;
} }
} }

@ -42,6 +42,7 @@
#include "src/core/iomgr/iomgr_internal.h" #include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/sockaddr_utils.h" #include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/support/block_annotate.h"
#include "src/core/support/string.h" #include "src/core/support/string.h"
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/host_port.h> #include <grpc/support/host_port.h>
@ -88,7 +89,9 @@ grpc_resolved_addresses *grpc_blocking_resolve_address(
hints.ai_socktype = SOCK_STREAM; /* stream socket */ hints.ai_socktype = SOCK_STREAM; /* stream socket */
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
GRPC_SCHEDULING_START_BLOCKING_REGION;
s = getaddrinfo(host, port, &hints, &result); s = getaddrinfo(host, port, &hints, &result);
GRPC_SCHEDULING_END_BLOCKING_REGION;
if (s != 0) { if (s != 0) {
gpr_log(GPR_ERROR, "getaddrinfo: %s", gai_strerror(s)); gpr_log(GPR_ERROR, "getaddrinfo: %s", gai_strerror(s));
goto done; goto done;

@ -78,6 +78,9 @@ typedef struct {
size_t slice_size; size_t slice_size;
gpr_refcount refcount; gpr_refcount refcount;
/* garbage after the last read */
gpr_slice_buffer last_read_buffer;
gpr_slice_buffer *incoming_buffer; gpr_slice_buffer *incoming_buffer;
gpr_slice_buffer *outgoing_buffer; gpr_slice_buffer *outgoing_buffer;
/** slice within outgoing_buffer to write next */ /** slice within outgoing_buffer to write next */
@ -106,6 +109,7 @@ static void tcp_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) {
static void tcp_free(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { static void tcp_free(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
grpc_fd_orphan(exec_ctx, tcp->em_fd, NULL, "tcp_unref_orphan"); grpc_fd_orphan(exec_ctx, tcp->em_fd, NULL, "tcp_unref_orphan");
gpr_slice_buffer_destroy(&tcp->last_read_buffer);
gpr_free(tcp->peer_string); gpr_free(tcp->peer_string);
gpr_free(tcp); gpr_free(tcp);
} }
@ -226,7 +230,8 @@ static void tcp_continue_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) {
if ((size_t)read_bytes < tcp->incoming_buffer->length) { if ((size_t)read_bytes < tcp->incoming_buffer->length) {
gpr_slice_buffer_trim_end( gpr_slice_buffer_trim_end(
tcp->incoming_buffer, tcp->incoming_buffer,
tcp->incoming_buffer->length - (size_t)read_bytes); tcp->incoming_buffer->length - (size_t)read_bytes,
&tcp->last_read_buffer);
} else if (tcp->iov_size < MAX_READ_IOVEC) { } else if (tcp->iov_size < MAX_READ_IOVEC) {
++tcp->iov_size; ++tcp->iov_size;
} }
@ -259,6 +264,7 @@ static void tcp_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
tcp->read_cb = cb; tcp->read_cb = cb;
tcp->incoming_buffer = incoming_buffer; tcp->incoming_buffer = incoming_buffer;
gpr_slice_buffer_reset_and_unref(incoming_buffer); gpr_slice_buffer_reset_and_unref(incoming_buffer);
gpr_slice_buffer_swap(incoming_buffer, &tcp->last_read_buffer);
TCP_REF(tcp, "read"); TCP_REF(tcp, "read");
if (tcp->finished_edge) { if (tcp->finished_edge) {
tcp->finished_edge = 0; tcp->finished_edge = 0;
@ -457,6 +463,7 @@ grpc_endpoint *grpc_tcp_create(grpc_fd *em_fd, size_t slice_size,
tcp->read_closure.cb_arg = tcp; tcp->read_closure.cb_arg = tcp;
tcp->write_closure.cb = tcp_handle_write; tcp->write_closure.cb = tcp_handle_write;
tcp->write_closure.cb_arg = tcp; tcp->write_closure.cb_arg = tcp;
gpr_slice_buffer_init(&tcp->last_read_buffer);
return &tcp->base; return &tcp->base;
} }

@ -117,6 +117,8 @@ struct grpc_udp_server {
grpc_pollset **pollsets; grpc_pollset **pollsets;
/* number of pollsets in the pollsets array */ /* number of pollsets in the pollsets array */
size_t pollset_count; size_t pollset_count;
/* The parent grpc server */
grpc_server* grpc_server;
}; };
grpc_udp_server *grpc_udp_server_create(void) { grpc_udp_server *grpc_udp_server_create(void) {
@ -276,7 +278,7 @@ static void on_read(grpc_exec_ctx *exec_ctx, void *arg, int success) {
/* Tell the registered callback that data is available to read. */ /* Tell the registered callback that data is available to read. */
GPR_ASSERT(sp->read_cb); GPR_ASSERT(sp->read_cb);
sp->read_cb(sp->fd); sp->read_cb(sp->fd, sp->server->grpc_server);
/* Re-arm the notification event so we get another chance to read. */ /* Re-arm the notification event so we get another chance to read. */
grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure); grpc_fd_notify_on_read(exec_ctx, sp->emfd, &sp->read_closure);
@ -402,11 +404,13 @@ int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned index) {
} }
void grpc_udp_server_start(grpc_exec_ctx *exec_ctx, grpc_udp_server *s, void grpc_udp_server_start(grpc_exec_ctx *exec_ctx, grpc_udp_server *s,
grpc_pollset **pollsets, size_t pollset_count) { grpc_pollset **pollsets, size_t pollset_count,
grpc_server *server) {
size_t i, j; size_t i, j;
gpr_mu_lock(&s->mu); gpr_mu_lock(&s->mu);
GPR_ASSERT(s->active_ports == 0); GPR_ASSERT(s->active_ports == 0);
s->pollsets = pollsets; s->pollsets = pollsets;
s->grpc_server = server;
for (i = 0; i < s->nports; i++) { for (i = 0; i < s->nports; i++) {
for (j = 0; j < pollset_count; j++) { for (j = 0; j < pollset_count; j++) {
grpc_pollset_add_fd(exec_ctx, pollsets[j], s->ports[i].emfd); grpc_pollset_add_fd(exec_ctx, pollsets[j], s->ports[i].emfd);

@ -36,18 +36,22 @@
#include "src/core/iomgr/endpoint.h" #include "src/core/iomgr/endpoint.h"
/* Forward decl of grpc_server */
typedef struct grpc_server grpc_server;
/* Forward decl of grpc_udp_server */ /* Forward decl of grpc_udp_server */
typedef struct grpc_udp_server grpc_udp_server; typedef struct grpc_udp_server grpc_udp_server;
/* Called when data is available to read from the socket. */ /* Called when data is available to read from the socket. */
typedef void (*grpc_udp_server_read_cb)(int fd); typedef void (*grpc_udp_server_read_cb)(int fd, grpc_server *server);
/* Create a server, initially not bound to any ports */ /* Create a server, initially not bound to any ports */
grpc_udp_server *grpc_udp_server_create(void); grpc_udp_server *grpc_udp_server_create(void);
/* Start listening to bound ports */ /* Start listening to bound ports */
void grpc_udp_server_start(grpc_exec_ctx *exec_ctx, grpc_udp_server *udp_server, void grpc_udp_server_start(grpc_exec_ctx *exec_ctx, grpc_udp_server *udp_server,
grpc_pollset **pollsets, size_t pollset_count); grpc_pollset **pollsets, size_t pollset_count,
grpc_server *server);
int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned index); int grpc_udp_server_get_fd(grpc_udp_server *s, unsigned index);

@ -326,12 +326,10 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
(grpc_channel_security_connector *)GRPC_SECURITY_CONNECTOR_REF( (grpc_channel_security_connector *)GRPC_SECURITY_CONNECTOR_REF(
sc, "client_auth_filter"); sc, "client_auth_filter");
chand->md_ctx = metadata_context; chand->md_ctx = metadata_context;
chand->authority_string = chand->authority_string = grpc_mdstr_from_string(chand->md_ctx, ":authority");
grpc_mdstr_from_string(chand->md_ctx, ":authority", 0); chand->path_string = grpc_mdstr_from_string(chand->md_ctx, ":path");
chand->path_string = grpc_mdstr_from_string(chand->md_ctx, ":path", 0); chand->error_msg_key = grpc_mdstr_from_string(chand->md_ctx, "grpc-message");
chand->error_msg_key = chand->status_key = grpc_mdstr_from_string(chand->md_ctx, "grpc-status");
grpc_mdstr_from_string(chand->md_ctx, "grpc-message", 0);
chand->status_key = grpc_mdstr_from_string(chand->md_ctx, "grpc-status", 0);
} }
/* Destructor for channel data */ /* Destructor for channel data */

@ -0,0 +1,48 @@
/*
*
* 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_CORE_SUPPORT_BLOCK_ANNOTATE_H
#define GRPC_INTERNAL_CORE_SUPPORT_BLOCK_ANNOTATE_H
/* These annotations identify the beginning and end of regions where
the code may block for reasons other than synchronization functions.
These include poll, epoll, and getaddrinfo. */
#define GRPC_SCHEDULING_START_BLOCKING_REGION \
do { \
} while (0)
#define GRPC_SCHEDULING_END_BLOCKING_REGION \
do { \
} while (0)
#endif /* GRPC_INTERNAL_CORE_SUPPORT_BLOCK_ANNOTATE_H */

@ -40,6 +40,7 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/support/block_annotate.h"
#include "src/core/support/string.h" #include "src/core/support/string.h"
gpr_slice gpr_load_file(const char *filename, int add_null_terminator, gpr_slice gpr_load_file(const char *filename, int add_null_terminator,
@ -48,9 +49,11 @@ gpr_slice gpr_load_file(const char *filename, int add_null_terminator,
size_t contents_size = 0; size_t contents_size = 0;
char *error_msg = NULL; char *error_msg = NULL;
gpr_slice result = gpr_empty_slice(); gpr_slice result = gpr_empty_slice();
FILE *file = fopen(filename, "rb"); FILE *file;
size_t bytes_read = 0; size_t bytes_read = 0;
GRPC_SCHEDULING_START_BLOCKING_REGION;
file = fopen(filename, "rb");
if (file == NULL) { if (file == NULL) {
gpr_asprintf(&error_msg, "Could not open file %s (error = %s).", filename, gpr_asprintf(&error_msg, "Could not open file %s (error = %s).", filename,
strerror(errno)); strerror(errno));
@ -83,5 +86,6 @@ end:
if (success != NULL) *success = 0; if (success != NULL) *success = 0;
} }
if (file != NULL) fclose(file); if (file != NULL) fclose(file);
GRPC_SCHEDULING_END_BLOCKING_REGION;
return result; return result;
} }

@ -208,7 +208,7 @@ void gpr_slice_buffer_move_into(gpr_slice_buffer *src, gpr_slice_buffer *dst) {
src->length = 0; src->length = 0;
} }
void gpr_slice_buffer_trim_end(gpr_slice_buffer *sb, size_t n) { void gpr_slice_buffer_trim_end(gpr_slice_buffer *sb, size_t n, gpr_slice_buffer *garbage) {
GPR_ASSERT(n <= sb->length); GPR_ASSERT(n <= sb->length);
sb->length -= n; sb->length -= n;
for (;;) { for (;;) {
@ -216,14 +216,15 @@ void gpr_slice_buffer_trim_end(gpr_slice_buffer *sb, size_t n) {
gpr_slice slice = sb->slices[idx]; gpr_slice slice = sb->slices[idx];
size_t slice_len = GPR_SLICE_LENGTH(slice); size_t slice_len = GPR_SLICE_LENGTH(slice);
if (slice_len > n) { if (slice_len > n) {
sb->slices[idx] = gpr_slice_sub_no_ref(slice, 0, slice_len - n); sb->slices[idx] = gpr_slice_split_head(&slice, slice_len - n);
gpr_slice_buffer_add_indexed(garbage, slice);
return; return;
} else if (slice_len == n) { } else if (slice_len == n) {
gpr_slice_unref(slice); gpr_slice_buffer_add_indexed(garbage, slice);
sb->count = idx; sb->count = idx;
return; return;
} else { } else {
gpr_slice_unref(slice); gpr_slice_buffer_add_indexed(garbage, slice);
n -= slice_len; n -= slice_len;
sb->count = idx; sb->count = idx;
} }

@ -41,6 +41,7 @@
#include <unistd.h> #include <unistd.h>
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/time.h> #include <grpc/support/time.h>
#include "src/core/support/block_annotate.h"
static struct timespec timespec_from_gpr(gpr_timespec gts) { static struct timespec timespec_from_gpr(gpr_timespec gts) {
struct timespec rv; struct timespec rv;
@ -126,6 +127,7 @@ void gpr_sleep_until(gpr_timespec until) {
gpr_timespec now; gpr_timespec now;
gpr_timespec delta; gpr_timespec delta;
struct timespec delta_ts; struct timespec delta_ts;
int ns_result;
for (;;) { for (;;) {
/* We could simplify by using clock_nanosleep instead, but it might be /* We could simplify by using clock_nanosleep instead, but it might be
@ -137,7 +139,10 @@ void gpr_sleep_until(gpr_timespec until) {
delta = gpr_time_sub(until, now); delta = gpr_time_sub(until, now);
delta_ts = timespec_from_gpr(delta); delta_ts = timespec_from_gpr(delta);
if (nanosleep(&delta_ts, NULL) == 0) { GRPC_SCHEDULING_START_BLOCKING_REGION;
ns_result = nanosleep(&delta_ts, NULL);
GRPC_SCHEDULING_END_BLOCKING_REGION;
if (ns_result == 0) {
break; break;
} }
} }

@ -84,7 +84,7 @@ static void gpr_precise_clock_now(gpr_timespec *clk) {
} }
#else /* GRPC_TIMERS_RDTSC */ #else /* GRPC_TIMERS_RDTSC */
static void gpr_precise_clock_now(gpr_timespec* clk) { static void gpr_precise_clock_now(gpr_timespec *clk) {
*clk = gpr_now(GPR_CLOCK_REALTIME); *clk = gpr_now(GPR_CLOCK_REALTIME);
clk->clock_type = GPR_CLOCK_PRECISE; clk->clock_type = GPR_CLOCK_PRECISE;
} }

@ -41,6 +41,8 @@
#include <src/core/support/time_precise.h> #include <src/core/support/time_precise.h>
#include <sys/timeb.h> #include <sys/timeb.h>
#include "src/core/support/block_annotate.h"
static LARGE_INTEGER g_start_time; static LARGE_INTEGER g_start_time;
static double g_time_scale; static double g_time_scale;
@ -92,7 +94,9 @@ void gpr_sleep_until(gpr_timespec until) {
delta = gpr_time_sub(until, now); delta = gpr_time_sub(until, now);
sleep_millis = sleep_millis =
(DWORD)delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS; (DWORD)delta.tv_sec * GPR_MS_PER_SEC + delta.tv_nsec / GPR_NS_PER_MS;
GRPC_SCHEDULING_START_BLOCKING_REGION;
Sleep(sleep_millis); Sleep(sleep_millis);
GRPC_SCHEDULING_END_BLOCKING_REGION;
} }
} }

@ -1030,7 +1030,7 @@ static int prepare_application_metadata(grpc_call *call, size_t count,
GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data));
l->md = grpc_mdelem_from_string_and_buffer(call->metadata_context, md->key, l->md = grpc_mdelem_from_string_and_buffer(call->metadata_context, md->key,
(const gpr_uint8 *)md->value, (const gpr_uint8 *)md->value,
md->value_length, 1); md->value_length);
if (!grpc_mdstr_is_legal_header(l->md->key)) { if (!grpc_mdstr_is_legal_header(l->md->key)) {
gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s",
grpc_mdstr_as_c_string(l->md->key)); grpc_mdstr_as_c_string(l->md->key));
@ -1330,7 +1330,7 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call *c,
static grpc_call_error cancel_with_status(grpc_call *c, grpc_status_code status, static grpc_call_error cancel_with_status(grpc_call *c, grpc_status_code status,
const char *description) { const char *description) {
grpc_mdstr *details = grpc_mdstr *details =
description ? grpc_mdstr_from_string(c->metadata_context, description, 0) description ? grpc_mdstr_from_string(c->metadata_context, description)
: NULL; : NULL;
GPR_ASSERT(status != GRPC_STATUS_OK); GPR_ASSERT(status != GRPC_STATUS_OK);
@ -1689,7 +1689,7 @@ grpc_call_error grpc_call_start_batch(grpc_call *call, const grpc_op *ops,
op->data.send_status_from_server.status_details != NULL op->data.send_status_from_server.status_details != NULL
? grpc_mdstr_from_string( ? grpc_mdstr_from_string(
call->metadata_context, call->metadata_context,
op->data.send_status_from_server.status_details, 0) op->data.send_status_from_server.status_details)
: NULL; : NULL;
req = &reqs[out++]; req = &reqs[out++];
if (out > GRPC_IOREQ_OP_COUNT) { if (out > GRPC_IOREQ_OP_COUNT) {

@ -104,22 +104,21 @@ grpc_channel *grpc_channel_create_from_filters(
/* decremented by grpc_channel_destroy */ /* decremented by grpc_channel_destroy */
gpr_ref_init(&channel->refs, 1); gpr_ref_init(&channel->refs, 1);
channel->metadata_context = mdctx; channel->metadata_context = mdctx;
channel->grpc_status_string = grpc_mdstr_from_string(mdctx, "grpc-status", 0); channel->grpc_status_string = grpc_mdstr_from_string(mdctx, "grpc-status");
channel->grpc_compression_algorithm_string = channel->grpc_compression_algorithm_string =
grpc_mdstr_from_string(mdctx, "grpc-encoding", 0); grpc_mdstr_from_string(mdctx, "grpc-encoding");
channel->grpc_encodings_accepted_by_peer_string = channel->grpc_encodings_accepted_by_peer_string =
grpc_mdstr_from_string(mdctx, "grpc-accept-encoding", 0); grpc_mdstr_from_string(mdctx, "grpc-accept-encoding");
channel->grpc_message_string = channel->grpc_message_string = grpc_mdstr_from_string(mdctx, "grpc-message");
grpc_mdstr_from_string(mdctx, "grpc-message", 0);
for (i = 0; i < NUM_CACHED_STATUS_ELEMS; i++) { for (i = 0; i < NUM_CACHED_STATUS_ELEMS; i++) {
char buf[GPR_LTOA_MIN_BUFSIZE]; char buf[GPR_LTOA_MIN_BUFSIZE];
gpr_ltoa((long)i, buf); gpr_ltoa((long)i, buf);
channel->grpc_status_elem[i] = grpc_mdelem_from_metadata_strings( channel->grpc_status_elem[i] = grpc_mdelem_from_metadata_strings(
mdctx, GRPC_MDSTR_REF(channel->grpc_status_string), mdctx, GRPC_MDSTR_REF(channel->grpc_status_string),
grpc_mdstr_from_string(mdctx, buf, 0)); grpc_mdstr_from_string(mdctx, buf));
} }
channel->path_string = grpc_mdstr_from_string(mdctx, ":path", 0); channel->path_string = grpc_mdstr_from_string(mdctx, ":path");
channel->authority_string = grpc_mdstr_from_string(mdctx, ":authority", 0); channel->authority_string = grpc_mdstr_from_string(mdctx, ":authority");
gpr_mu_init(&channel->registered_call_mu); gpr_mu_init(&channel->registered_call_mu);
channel->registered_calls = NULL; channel->registered_calls = NULL;
@ -219,11 +218,11 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel,
channel, parent_call, propagation_mask, cq, channel, parent_call, propagation_mask, cq,
grpc_mdelem_from_metadata_strings( grpc_mdelem_from_metadata_strings(
channel->metadata_context, GRPC_MDSTR_REF(channel->path_string), channel->metadata_context, GRPC_MDSTR_REF(channel->path_string),
grpc_mdstr_from_string(channel->metadata_context, method, 0)), grpc_mdstr_from_string(channel->metadata_context, method)),
host ? grpc_mdelem_from_metadata_strings( host ? grpc_mdelem_from_metadata_strings(
channel->metadata_context, channel->metadata_context,
GRPC_MDSTR_REF(channel->authority_string), GRPC_MDSTR_REF(channel->authority_string),
grpc_mdstr_from_string(channel->metadata_context, host, 0)) grpc_mdstr_from_string(channel->metadata_context, host))
: NULL, : NULL,
deadline); deadline);
} }
@ -234,12 +233,12 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method,
GPR_ASSERT(!reserved); GPR_ASSERT(!reserved);
rc->path = grpc_mdelem_from_metadata_strings( rc->path = grpc_mdelem_from_metadata_strings(
channel->metadata_context, GRPC_MDSTR_REF(channel->path_string), channel->metadata_context, GRPC_MDSTR_REF(channel->path_string),
grpc_mdstr_from_string(channel->metadata_context, method, 0)); grpc_mdstr_from_string(channel->metadata_context, method));
rc->authority = rc->authority =
host ? grpc_mdelem_from_metadata_strings( host ? grpc_mdelem_from_metadata_strings(
channel->metadata_context, channel->metadata_context,
GRPC_MDSTR_REF(channel->authority_string), GRPC_MDSTR_REF(channel->authority_string),
grpc_mdstr_from_string(channel->metadata_context, host, 0)) grpc_mdstr_from_string(channel->metadata_context, host))
: NULL; : NULL;
gpr_mu_lock(&channel->registered_call_mu); gpr_mu_lock(&channel->registered_call_mu);
rc->next = channel->registered_calls; rc->next = channel->registered_calls;
@ -358,7 +357,7 @@ grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_channel *channel, int i) {
gpr_ltoa(i, tmp); gpr_ltoa(i, tmp);
return grpc_mdelem_from_metadata_strings( return grpc_mdelem_from_metadata_strings(
channel->metadata_context, GRPC_MDSTR_REF(channel->grpc_status_string), channel->metadata_context, GRPC_MDSTR_REF(channel->grpc_status_string),
grpc_mdstr_from_string(channel->metadata_context, tmp, 0)); grpc_mdstr_from_string(channel->metadata_context, tmp));
} }
} }

@ -729,9 +729,8 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
GPR_ASSERT(!is_last); GPR_ASSERT(!is_last);
chand->server = NULL; chand->server = NULL;
chand->channel = NULL; chand->channel = NULL;
chand->path_key = grpc_mdstr_from_string(metadata_context, ":path", 0); chand->path_key = grpc_mdstr_from_string(metadata_context, ":path");
chand->authority_key = chand->authority_key = grpc_mdstr_from_string(metadata_context, ":authority");
grpc_mdstr_from_string(metadata_context, ":authority", 0);
chand->next = chand->prev = chand; chand->next = chand->prev = chand;
chand->registered_methods = NULL; chand->registered_methods = NULL;
chand->connectivity_state = GRPC_CHANNEL_IDLE; chand->connectivity_state = GRPC_CHANNEL_IDLE;
@ -959,8 +958,8 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s,
chand->registered_methods = gpr_malloc(alloc); chand->registered_methods = gpr_malloc(alloc);
memset(chand->registered_methods, 0, alloc); memset(chand->registered_methods, 0, alloc);
for (rm = s->registered_methods; rm; rm = rm->next) { for (rm = s->registered_methods; rm; rm = rm->next) {
host = rm->host ? grpc_mdstr_from_string(mdctx, rm->host, 0) : NULL; host = rm->host ? grpc_mdstr_from_string(mdctx, rm->host) : NULL;
method = grpc_mdstr_from_string(mdctx, rm->method, 0); method = grpc_mdstr_from_string(mdctx, rm->method);
hash = GRPC_MDSTR_KV_HASH(host ? host->hash : 0, method->hash); hash = GRPC_MDSTR_KV_HASH(host ? host->hash : 0, method->hash);
for (probes = 0; chand->registered_methods[(hash + probes) % slots] for (probes = 0; chand->registered_methods[(hash + probes) % slots]
.server_registered_method != NULL; .server_registered_method != NULL;

@ -171,7 +171,7 @@ void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op(
size_t copy_bytes = sizeof(*buffer->elems) * new_count; size_t copy_bytes = sizeof(*buffer->elems) * new_count;
GPR_ASSERT(mdidx < buffer->count); GPR_ASSERT(mdidx < buffer->count);
buffer->elems = gpr_malloc(copy_bytes); buffer->elems = gpr_malloc(copy_bytes);
memcpy(live_op_buffer->elems + mdidx, buffer->elems, copy_bytes); memcpy(buffer->elems, live_op_buffer->elems + mdidx, copy_bytes);
buffer->count = buffer->capacity = new_count; buffer->count = buffer->capacity = new_count;
} else { } else {
buffer->elems = NULL; buffer->elems = NULL;

@ -466,7 +466,7 @@ static void deadline_enc(grpc_chttp2_hpack_compressor *c, gpr_timespec deadline,
gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str); gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str);
mdelem = grpc_mdelem_from_metadata_strings( mdelem = grpc_mdelem_from_metadata_strings(
c->mdctx, GRPC_MDSTR_REF(c->timeout_key_str), c->mdctx, GRPC_MDSTR_REF(c->timeout_key_str),
grpc_mdstr_from_string(c->mdctx, timeout_str, 0)); grpc_mdstr_from_string(c->mdctx, timeout_str));
mdelem = hpack_enc(c, mdelem, st); mdelem = hpack_enc(c, mdelem, st);
if (mdelem) GRPC_MDELEM_UNREF(mdelem); if (mdelem) GRPC_MDELEM_UNREF(mdelem);
} }
@ -481,7 +481,7 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c,
grpc_mdctx *ctx) { grpc_mdctx *ctx) {
memset(c, 0, sizeof(*c)); memset(c, 0, sizeof(*c));
c->mdctx = ctx; c->mdctx = ctx;
c->timeout_key_str = grpc_mdstr_from_string(ctx, "grpc-timeout", 0); c->timeout_key_str = grpc_mdstr_from_string(ctx, "grpc-timeout");
} }
void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c) { void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c) {

@ -243,7 +243,7 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
t->global.pings.next = t->global.pings.prev = &t->global.pings; t->global.pings.next = t->global.pings.prev = &t->global.pings;
t->parsing.is_client = is_client; t->parsing.is_client = is_client;
t->parsing.str_grpc_timeout = t->parsing.str_grpc_timeout =
grpc_mdstr_from_string(t->metadata_context, "grpc-timeout", 0); grpc_mdstr_from_string(t->metadata_context, "grpc-timeout");
t->parsing.deframe_state = t->parsing.deframe_state =
is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0; is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0;
t->writing.is_client = is_client; t->writing.is_client = is_client;

@ -312,38 +312,7 @@ static void slice_unref(void *p) {
unlock(ctx); unlock(ctx);
} }
grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str, grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str) {
int canonicalize_key) {
if (canonicalize_key) {
size_t len;
size_t i;
int canonical = 1;
for (i = 0; str[i]; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
canonical = 0;
/* Keep going in loop just to get string length */
}
}
len = i;
if (canonical) {
return grpc_mdstr_from_buffer(ctx, (const gpr_uint8 *)str, len);
} else {
char *copy = gpr_malloc(len);
grpc_mdstr *ret;
for (i = 0; i < len; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
copy[i] = (char)(str[i] - 'A' + 'a');
} else {
copy[i] = str[i];
}
}
ret = grpc_mdstr_from_buffer(ctx, (const gpr_uint8 *)copy, len);
gpr_free(copy);
return ret;
}
}
return grpc_mdstr_from_buffer(ctx, (const gpr_uint8 *)str, strlen(str)); return grpc_mdstr_from_buffer(ctx, (const gpr_uint8 *)str, strlen(str));
} }
@ -524,9 +493,9 @@ grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_mdctx *ctx,
grpc_mdelem *grpc_mdelem_from_strings(grpc_mdctx *ctx, const char *key, grpc_mdelem *grpc_mdelem_from_strings(grpc_mdctx *ctx, const char *key,
const char *value) { const char *value) {
return grpc_mdelem_from_metadata_strings( return grpc_mdelem_from_metadata_strings(ctx,
ctx, grpc_mdstr_from_string(ctx, key, 0), grpc_mdstr_from_string(ctx, key),
grpc_mdstr_from_string(ctx, value, 0)); grpc_mdstr_from_string(ctx, value));
} }
grpc_mdelem *grpc_mdelem_from_slices(grpc_mdctx *ctx, gpr_slice key, grpc_mdelem *grpc_mdelem_from_slices(grpc_mdctx *ctx, gpr_slice key,
@ -538,10 +507,9 @@ grpc_mdelem *grpc_mdelem_from_slices(grpc_mdctx *ctx, gpr_slice key,
grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_mdctx *ctx, grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_mdctx *ctx,
const char *key, const char *key,
const gpr_uint8 *value, const gpr_uint8 *value,
size_t value_length, size_t value_length) {
int canonicalize_key) {
return grpc_mdelem_from_metadata_strings( return grpc_mdelem_from_metadata_strings(
ctx, grpc_mdstr_from_string(ctx, key, canonicalize_key), ctx, grpc_mdstr_from_string(ctx, key),
grpc_mdstr_from_buffer(ctx, value, value_length)); grpc_mdstr_from_buffer(ctx, value, value_length));
} }

@ -95,8 +95,7 @@ size_t grpc_mdctx_get_mdtab_free_test_only(grpc_mdctx *mdctx);
/* Constructors for grpc_mdstr instances; take a variety of data types that /* Constructors for grpc_mdstr instances; take a variety of data types that
clients may have handy */ clients may have handy */
grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str, grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str);
int perform_key_canonicalization);
/* Unrefs the slice. */ /* Unrefs the slice. */
grpc_mdstr *grpc_mdstr_from_slice(grpc_mdctx *ctx, gpr_slice slice); grpc_mdstr *grpc_mdstr_from_slice(grpc_mdctx *ctx, gpr_slice slice);
grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *str, grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *str,
@ -118,8 +117,7 @@ grpc_mdelem *grpc_mdelem_from_slices(grpc_mdctx *ctx, gpr_slice key,
grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_mdctx *ctx, grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_mdctx *ctx,
const char *key, const char *key,
const gpr_uint8 *value, const gpr_uint8 *value,
size_t value_length, size_t value_length);
int canonicalize_key);
/* Mutator and accessor for grpc_mdelem user data. The destructor function /* Mutator and accessor for grpc_mdelem user data. The destructor function
is used as a type tag and is checked during user_data fetch. */ is used as a type tag and is checked during user_data fetch. */

@ -158,10 +158,19 @@ namespace grpc {
Status SerializeProto(const grpc::protobuf::Message& msg, Status SerializeProto(const grpc::protobuf::Message& msg,
grpc_byte_buffer** bp) { grpc_byte_buffer** bp) {
GrpcBufferWriter writer(bp); int byte_size = msg.ByteSize();
return msg.SerializeToZeroCopyStream(&writer) if (byte_size <= kMaxBufferLength) {
? Status::OK gpr_slice slice = gpr_slice_malloc(byte_size);
: Status(StatusCode::INTERNAL, "Failed to serialize message"); GPR_ASSERT(GPR_SLICE_END_PTR(slice) == msg.SerializeWithCachedSizesToArray(GPR_SLICE_START_PTR(slice)));
*bp = grpc_raw_byte_buffer_create(&slice, 1);
gpr_slice_unref(slice);
return Status::OK;
} else {
GrpcBufferWriter writer(bp);
return msg.SerializeToZeroCopyStream(&writer)
? Status::OK
: Status(StatusCode::INTERNAL, "Failed to serialize message");
}
} }
Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg, Status DeserializeProto(grpc_byte_buffer* buffer, grpc::protobuf::Message* msg,

@ -46,7 +46,7 @@ namespace grpc {
class AuthMetadataProcessorAyncWrapper GRPC_FINAL { class AuthMetadataProcessorAyncWrapper GRPC_FINAL {
public: public:
static void Destroy(void *wrapper); static void Destroy(void* wrapper);
static void Process(void* wrapper, grpc_auth_context* context, static void Process(void* wrapper, grpc_auth_context* context,
const grpc_metadata* md, size_t num_md, const grpc_metadata* md, size_t num_md,

@ -405,22 +405,6 @@ describe GRPC::RpcServer do
t.join t.join
end end
it 'should not receive metadata if the client times out', server: true do
service = SlowService.new
@srv.handle(service)
t = Thread.new { @srv.run }
@srv.wait_till_running
req = EchoMsg.new
stub = SlowStub.new(@host, **client_opts)
timeout = 0.1 # too short for SlowService to respond
blk = proc { stub.an_rpc(req, timeout: timeout, k1: 'v1', k2: 'v2') }
expect(&blk).to raise_error GRPC::BadStatus
wanted_md = []
expect(service.received_md).to eq(wanted_md)
@srv.stop
t.join
end
it 'should handle cancellation correctly', server: true do it 'should handle cancellation correctly', server: true do
service = SlowService.new service = SlowService.new
@srv.handle(service) @srv.handle(service)

@ -108,7 +108,7 @@
LD_opt = $(DEFAULT_CC) LD_opt = $(DEFAULT_CC)
LDXX_opt = $(DEFAULT_CXX) LDXX_opt = $(DEFAULT_CXX)
CPPFLAGS_opt = -O2 CPPFLAGS_opt = -O2
LDFLAGS_opt = LDFLAGS_opt = -rdynamic
DEFINES_opt = NDEBUG DEFINES_opt = NDEBUG
VALID_CONFIG_basicprof = 1 VALID_CONFIG_basicprof = 1
@ -135,7 +135,7 @@
LD_dbg = $(DEFAULT_CC) LD_dbg = $(DEFAULT_CC)
LDXX_dbg = $(DEFAULT_CXX) LDXX_dbg = $(DEFAULT_CXX)
CPPFLAGS_dbg = -O0 CPPFLAGS_dbg = -O0
LDFLAGS_dbg = LDFLAGS_dbg = -rdynamic
DEFINES_dbg = _DEBUG DEBUG DEFINES_dbg = _DEBUG DEBUG
VALID_CONFIG_mutrace = 1 VALID_CONFIG_mutrace = 1
@ -155,7 +155,7 @@
LDXX_valgrind = $(DEFAULT_CXX) LDXX_valgrind = $(DEFAULT_CXX)
CPPFLAGS_valgrind = -O0 CPPFLAGS_valgrind = -O0
OPENSSL_CFLAGS_valgrind = -DPURIFY OPENSSL_CFLAGS_valgrind = -DPURIFY
LDFLAGS_valgrind = LDFLAGS_valgrind = -rdynamic
DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20 DEFINES_valgrind = _DEBUG DEBUG GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20
VALID_CONFIG_tsan = 1 VALID_CONFIG_tsan = 1
@ -206,7 +206,7 @@
LD_gcov = gcc LD_gcov = gcc
LDXX_gcov = g++ LDXX_gcov = g++
CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage
LDFLAGS_gcov = -fprofile-arcs -ftest-coverage LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic
DEFINES_gcov = _DEBUG DEBUG DEFINES_gcov = _DEBUG DEBUG

@ -10,7 +10,7 @@
<ItemDefinitionGroup> <ItemDefinitionGroup>
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)\..;$(SolutionDir)\..\include;$(SolutionDir)\..\third_party\protobuf\src;${';'.join('$(SolutionDir)\\packages\\%s.%s\\build\\native\\include' % (p.name, p.version) for p in vspackages)};%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)\..;$(SolutionDir)\..\include;$(SolutionDir)\..\third_party\protobuf\src;${';'.join('$(SolutionDir)\\packages\\%s.%s\\build\\native\\include' % (p.name, p.version) for p in vspackages)};%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_WIN32_WINNT=0x600;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>EnableAllWarnings</WarningLevel> <WarningLevel>EnableAllWarnings</WarningLevel>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>

@ -113,8 +113,8 @@ static void test_request_response_with_metadata_and_payload(
{"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}},
{"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}};
grpc_metadata meta_s[2] = { grpc_metadata meta_s[2] = {
{"KeY3", "val3", 4, 0, {{NULL, NULL, NULL, NULL}}}, {"key3", "val3", 4, 0, {{NULL, NULL, NULL, NULL}}},
{"KeY4", "val4", 4, 0, {{NULL, NULL, NULL, NULL}}}}; {"key4", "val4", 4, 0, {{NULL, NULL, NULL, NULL}}}};
grpc_end2end_test_fixture f = begin_test( grpc_end2end_test_fixture f = begin_test(
config, "test_request_response_with_metadata_and_payload", NULL, NULL); config, "test_request_response_with_metadata_and_payload", NULL, NULL);
cq_verifier *cqv = cq_verifier_create(f.cq); cq_verifier *cqv = cq_verifier_create(f.cq);

@ -49,7 +49,7 @@ static grpc_pollset g_pollset;
static int g_number_of_reads = 0; static int g_number_of_reads = 0;
static int g_number_of_bytes_read = 0; static int g_number_of_bytes_read = 0;
static void on_read(int fd) { static void on_read(int fd, grpc_server *server) {
char read_buffer[512]; char read_buffer[512];
ssize_t byte_count; ssize_t byte_count;
@ -74,7 +74,7 @@ static void test_no_op_with_start(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_udp_server *s = grpc_udp_server_create(); grpc_udp_server *s = grpc_udp_server_create();
LOG_TEST("test_no_op_with_start"); LOG_TEST("test_no_op_with_start");
grpc_udp_server_start(&exec_ctx, s, NULL, 0); grpc_udp_server_start(&exec_ctx, s, NULL, 0, NULL);
grpc_udp_server_destroy(&exec_ctx, s, NULL); grpc_udp_server_destroy(&exec_ctx, s, NULL);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
} }
@ -105,7 +105,7 @@ static void test_no_op_with_port_and_start(void) {
GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr), GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
on_read)); on_read));
grpc_udp_server_start(&exec_ctx, s, NULL, 0); grpc_udp_server_start(&exec_ctx, s, NULL, 0, NULL);
grpc_udp_server_destroy(&exec_ctx, s, NULL); grpc_udp_server_destroy(&exec_ctx, s, NULL);
grpc_exec_ctx_finish(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx);
@ -137,7 +137,7 @@ static void test_receive(int number_of_clients) {
GPR_ASSERT(addr_len <= sizeof(addr)); GPR_ASSERT(addr_len <= sizeof(addr));
pollsets[0] = &g_pollset; pollsets[0] = &g_pollset;
grpc_udp_server_start(&exec_ctx, s, pollsets, 1); grpc_udp_server_start(&exec_ctx, s, pollsets, 1, NULL);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));

@ -63,9 +63,9 @@ static void test_create_string(void) {
LOG_TEST("test_create_string"); LOG_TEST("test_create_string");
ctx = grpc_mdctx_create(); ctx = grpc_mdctx_create();
s1 = grpc_mdstr_from_string(ctx, "hello", 0); s1 = grpc_mdstr_from_string(ctx, "hello");
s2 = grpc_mdstr_from_string(ctx, "hello", 0); s2 = grpc_mdstr_from_string(ctx, "hello");
s3 = grpc_mdstr_from_string(ctx, "very much not hello", 0); s3 = grpc_mdstr_from_string(ctx, "very much not hello");
GPR_ASSERT(s1 == s2); GPR_ASSERT(s1 == s2);
GPR_ASSERT(s3 != s1); GPR_ASSERT(s3 != s1);
GPR_ASSERT(gpr_slice_str_cmp(s1->slice, "hello") == 0); GPR_ASSERT(gpr_slice_str_cmp(s1->slice, "hello") == 0);
@ -190,7 +190,7 @@ static void test_things_stick_around(void) {
for (i = 0; i < nstrs; i++) { for (i = 0; i < nstrs; i++) {
gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", i); gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", i);
strs[i] = grpc_mdstr_from_string(ctx, buffer, 0); strs[i] = grpc_mdstr_from_string(ctx, buffer);
shuf[i] = i; shuf[i] = i;
gpr_free(buffer); gpr_free(buffer);
} }
@ -212,7 +212,7 @@ static void test_things_stick_around(void) {
GRPC_MDSTR_UNREF(strs[shuf[i]]); GRPC_MDSTR_UNREF(strs[shuf[i]]);
for (j = i + 1; j < nstrs; j++) { for (j = i + 1; j < nstrs; j++) {
gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", shuf[j]); gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", shuf[j]);
test = grpc_mdstr_from_string(ctx, buffer, 0); test = grpc_mdstr_from_string(ctx, buffer);
GPR_ASSERT(test == strs[shuf[j]]); GPR_ASSERT(test == strs[shuf[j]]);
GRPC_MDSTR_UNREF(test); GRPC_MDSTR_UNREF(test);
gpr_free(buffer); gpr_free(buffer);
@ -235,13 +235,13 @@ static void test_slices_work(void) {
ctx = grpc_mdctx_create(); ctx = grpc_mdctx_create();
str = grpc_mdstr_from_string( str = grpc_mdstr_from_string(
ctx, "123456789012345678901234567890123456789012345678901234567890", 0); ctx, "123456789012345678901234567890123456789012345678901234567890");
slice = gpr_slice_ref(str->slice); slice = gpr_slice_ref(str->slice);
GRPC_MDSTR_UNREF(str); GRPC_MDSTR_UNREF(str);
gpr_slice_unref(slice); gpr_slice_unref(slice);
str = grpc_mdstr_from_string( str = grpc_mdstr_from_string(
ctx, "123456789012345678901234567890123456789012345678901234567890", 0); ctx, "123456789012345678901234567890123456789012345678901234567890");
slice = gpr_slice_ref(str->slice); slice = gpr_slice_ref(str->slice);
gpr_slice_unref(slice); gpr_slice_unref(slice);
GRPC_MDSTR_UNREF(str); GRPC_MDSTR_UNREF(str);
@ -258,7 +258,7 @@ static void test_base64_and_huffman_works(void) {
LOG_TEST("test_base64_and_huffman_works"); LOG_TEST("test_base64_and_huffman_works");
ctx = grpc_mdctx_create(); ctx = grpc_mdctx_create();
str = grpc_mdstr_from_string(ctx, "abcdefg", 0); str = grpc_mdstr_from_string(ctx, "abcdefg");
slice1 = grpc_mdstr_as_base64_encoded_and_huffman_compressed(str); slice1 = grpc_mdstr_as_base64_encoded_and_huffman_compressed(str);
slice2 = grpc_chttp2_base64_encode_and_huffman_compress(str->slice); slice2 = grpc_chttp2_base64_encode_and_huffman_compress(str->slice);
GPR_ASSERT(0 == gpr_slice_cmp(slice1, slice2)); GPR_ASSERT(0 == gpr_slice_cmp(slice1, slice2));

@ -83,6 +83,49 @@ static void install_crash_handler() {
_set_abort_behavior(0, _CALL_REPORTFAULT); _set_abort_behavior(0, _CALL_REPORTFAULT);
signal(SIGABRT, abort_handler); signal(SIGABRT, abort_handler);
} }
#elif GPR_POSIX_CRASH_HANDLER
#include <execinfo.h>
#include <stdio.h>
#include <string.h>
#include <grpc/support/useful.h>
static char g_alt_stack[8192];
#define MAX_FRAMES 32
static void crash_handler(int signum, siginfo_t *info, void *data) {
void *addrlist[MAX_FRAMES + 1];
int addrlen;
int i;
char **symlist;
fprintf(stderr, "Caught signal %d\n", signum);
addrlen = backtrace(addrlist, GPR_ARRAY_SIZE(addrlist));
symlist = backtrace_symbols(addrlist, addrlen);
for (i = 0; i < addrlen; i++) {
fprintf(stderr, " %s\n", symlist[i]);
}
free(symlist);
raise(signum);
}
static void install_crash_handler() {
stack_t ss;
struct sigaction sa;
memset(&ss, 0, sizeof(ss));
memset(&sa, 0, sizeof(sa));
ss.ss_size = sizeof(g_alt_stack);
ss.ss_sp = g_alt_stack;
GPR_ASSERT(sigaltstack(&ss, NULL) == 0);
sa.sa_flags = (int)(SA_SIGINFO | SA_ONSTACK | SA_RESETHAND);
sa.sa_sigaction = crash_handler;
GPR_ASSERT(sigaction(SIGILL, &sa, NULL) == 0);
GPR_ASSERT(sigaction(SIGABRT, &sa, NULL) == 0);
GPR_ASSERT(sigaction(SIGBUS, &sa, NULL) == 0);
GPR_ASSERT(sigaction(SIGSEGV, &sa, NULL) == 0);
}
#else #else
static void install_crash_handler() {} static void install_crash_handler() {}
#endif #endif

@ -103,6 +103,7 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
EchoResponse response; EchoResponse response;
response.set_message(kLargeString); response.set_message(kLargeString);
while (!should_exit->load()) { while (!should_exit->load()) {
// TODO(vpai): Decide if the below requires blocking annotation
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::milliseconds(1));
stream->Write(response); stream->Write(response);
} }
@ -117,6 +118,7 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
std::thread sender(std::bind(&TestServiceImpl::BidiStream_Sender, stream, &should_exit)); std::thread sender(std::bind(&TestServiceImpl::BidiStream_Sender, stream, &should_exit));
while (stream->Read(&request)) { while (stream->Read(&request)) {
// TODO(vpai): Decide if the below requires blocking annotation
std::this_thread::sleep_for(std::chrono::milliseconds(3)); std::this_thread::sleep_for(std::chrono::milliseconds(3));
} }
should_exit.store(true); should_exit.store(true);

@ -53,7 +53,7 @@ std::shared_ptr<Channel> CreateChannelForTestCase(
class InteropClientContextInspector { class InteropClientContextInspector {
public: public:
InteropClientContextInspector(const ::grpc::ClientContext& context) InteropClientContextInspector(const ::grpc::ClientContext& context)
: context_(context) {} : context_(context) {}
// Inspector methods, able to peek inside ClientContext, follow. // Inspector methods, able to peek inside ClientContext, follow.
grpc_compression_algorithm GetCallCompressionAlgorithm() const { grpc_compression_algorithm GetCallCompressionAlgorithm() const {

@ -88,7 +88,7 @@ for filename in sys.argv[1:]:
if grp not in js: continue if grp not in js: continue
js[grp] = sorted([clean_elem(x) for x in js[grp]], js[grp] = sorted([clean_elem(x) for x in js[grp]],
key=lambda x: (x.get('language', '_'), x['name'])) key=lambda x: (x.get('language', '_'), x['name']))
output = yaml.dump(js, indent=2, width=80) output = yaml.dump(js, indent=2, width=80, default_flow_style=False)
# massage out trailing whitespace # massage out trailing whitespace
lines = [] lines = []
for line in output.splitlines(): for line in output.splitlines():

@ -0,0 +1,13 @@
#!/bin/bash
set -ex
# change to root directory
cd $(dirname $0)/../..
# build clang-format docker image
docker build -t grpc_clang_format tools/dockerfile/grpc_clang_format
# run clang-format against the checked out codebase
docker run -e TEST=$TEST --rm=true -v `pwd`:/local-code -t grpc_clang_format /clang_format_all_the_things.sh

@ -0,0 +1,6 @@
FROM ubuntu:vivid
RUN apt-get update
RUN apt-get -y install clang-format-3.6
ADD clang_format_all_the_things.sh /
CMD ["echo 'Run with tools/distrib/clang_format_code.sh'"]

@ -0,0 +1,30 @@
#!/bin/bash
# directories to run against
DIRS="src/core src/cpp test/core test/cpp include"
# file matching patterns to check
GLOB="*.h *.cpp"
# clang format command
CLANG_FORMAT=clang-format-3.6
files=
for dir in $DIRS
do
for glob in $GLOB
do
files="$files `find /local-code/$dir -name $glob`"
done
done
if [ "x$TEST" = "x" ]
then
echo $files | xargs $CLANG_FORMAT -i
else
for file in $files
do
$CLANG_FORMAT $file | diff $file -
done
fi

@ -1067,6 +1067,7 @@ include/grpc/support/tls_gcc.h \
include/grpc/support/tls_msvc.h \ include/grpc/support/tls_msvc.h \
include/grpc/support/tls_pthread.h \ include/grpc/support/tls_pthread.h \
include/grpc/support/useful.h \ include/grpc/support/useful.h \
src/core/support/block_annotate.h \
src/core/support/env.h \ src/core/support/env.h \
src/core/support/file.h \ src/core/support/file.h \
src/core/support/murmur_hash.h \ src/core/support/murmur_hash.h \

@ -60,6 +60,8 @@ docker run \
-i $TTY_FLAG \ -i $TTY_FLAG \
-v "$git_root:/var/local/jenkins/grpc" \ -v "$git_root:/var/local/jenkins/grpc" \
-v /tmp/ccache:/tmp/ccache \ -v /tmp/ccache:/tmp/ccache \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(which docker):/bin/docker \
-w /var/local/git/grpc \ -w /var/local/git/grpc \
--cidfile=docker.cid \ --cidfile=docker.cid \
$DOCKER_IMAGE_NAME \ $DOCKER_IMAGE_NAME \

@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
# Copyright 2015, Google Inc. # Copyright 2015, Google Inc.
# All rights reserved. # All rights reserved.
# #
@ -31,8 +31,6 @@
# This script is invoked by Jenkins and triggers a test run based on # This script is invoked by Jenkins and triggers a test run based on
# env variable settings. # env variable settings.
# #
# Bootstrap into bash
[ -z $1 ] && exec bash $0 bootstrapped
# Setting up rvm environment BEFORE we set -ex. # Setting up rvm environment BEFORE we set -ex.
[[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh [[ -s /etc/profile.d/rvm.sh ]] && . /etc/profile.d/rvm.sh
# To prevent cygwin bash complaining about empty lines ending with \r # To prevent cygwin bash complaining about empty lines ending with \r
@ -56,11 +54,11 @@ if [ "$platform" == "linux" ]
then then
echo "building $language on Linux" echo "building $language on Linux"
./tools/run_tests/run_tests.py --use_docker -t -l $language -c $config -x report.xml || true ./tools/run_tests/run_tests.py --use_docker -t -l $language -c $config -x report.xml $@ || true
elif [ "$platform" == "interop" ] elif [ "$platform" == "interop" ]
then then
python tools/run_tests/run_interops.py --language=$language python tools/run_tests/run_interops.py --language=$language $@
elif [ "$platform" == "windows" ] elif [ "$platform" == "windows" ]
then then
echo "building $language on Windows" echo "building $language on Windows"
@ -72,19 +70,19 @@ then
/cygdrive/c/nuget/nuget.exe restore vsprojects/grpc.sln /cygdrive/c/nuget/nuget.exe restore vsprojects/grpc.sln
/cygdrive/c/nuget/nuget.exe restore src/csharp/Grpc.sln /cygdrive/c/nuget/nuget.exe restore src/csharp/Grpc.sln
python tools/run_tests/run_tests.py -t -l $language -x report.xml || true python tools/run_tests/run_tests.py -t -l $language -x report.xml $@ || true
elif [ "$platform" == "macos" ] elif [ "$platform" == "macos" ]
then then
echo "building $language on MacOS" echo "building $language on MacOS"
./tools/run_tests/run_tests.py -t -l $language -c $config -x report.xml || true ./tools/run_tests/run_tests.py -t -l $language -c $config -x report.xml $@ || true
elif [ "$platform" == "freebsd" ] elif [ "$platform" == "freebsd" ]
then then
echo "building $language on FreeBSD" echo "building $language on FreeBSD"
MAKE=gmake ./tools/run_tests/run_tests.py -t -l $language -c $config -x report.xml || true MAKE=gmake ./tools/run_tests/run_tests.py -t -l $language -c $config -x report.xml $@ || true
else else
echo "Unknown platform $platform" echo "Unknown platform $platform"
exit 1 exit 1

@ -134,7 +134,7 @@ class JobSpec(object):
"""Specifies what to run for a job.""" """Specifies what to run for a job."""
def __init__(self, cmdline, shortname=None, environ=None, hash_targets=None, def __init__(self, cmdline, shortname=None, environ=None, hash_targets=None,
cwd=None, shell=False, timeout_seconds=5*60, flake_retries=5): cwd=None, shell=False, timeout_seconds=5*60, flake_retries=0):
""" """
Arguments: Arguments:
cmdline: a list of arguments to pass as the command line cmdline: a list of arguments to pass as the command line

@ -58,3 +58,5 @@ if [ -f cache.mk ] ; then
fi fi
./tools/buildgen/generate_projects.sh ./tools/buildgen/generate_projects.sh
./tools/distrib/clang_format_code.sh

@ -40,6 +40,7 @@ import os
import platform import platform
import random import random
import re import re
import socket
import subprocess import subprocess
import sys import sys
import time import time
@ -99,7 +100,8 @@ class SimpleConfig(object):
environ=actual_environ, environ=actual_environ,
timeout_seconds=self.timeout_seconds, timeout_seconds=self.timeout_seconds,
hash_targets=hash_targets hash_targets=hash_targets
if self.allow_hashing else None) if self.allow_hashing else None,
flake_retries=5 if args.allow_flakes else 0)
# ValgrindConfig: compile with some CONFIG=config, but use valgrind to run # ValgrindConfig: compile with some CONFIG=config, but use valgrind to run
@ -117,7 +119,8 @@ class ValgrindConfig(object):
return jobset.JobSpec(cmdline=['valgrind', '--tool=%s' % self.tool] + return jobset.JobSpec(cmdline=['valgrind', '--tool=%s' % self.tool] +
self.args + cmdline, self.args + cmdline,
shortname='valgrind %s' % cmdline[0], shortname='valgrind %s' % cmdline[0],
hash_targets=None) hash_targets=None,
flake_retries=5 if args.allow_flakes else 0)
def get_c_tests(travis, test_lang) : def get_c_tests(travis, test_lang) :
@ -555,6 +558,11 @@ argp.add_argument('--use_docker',
help="Run all the tests under docker. That provides " + help="Run all the tests under docker. That provides " +
"additional isolation and prevents the need to installs " + "additional isolation and prevents the need to installs " +
"language specific prerequisites. Only available on Linux.") "language specific prerequisites. Only available on Linux.")
argp.add_argument('--allow_flakes',
default=False,
action='store_const',
const=True,
help="Allow flaky tests to show as passing (re-runs failed tests up to five times)")
argp.add_argument('-a', '--antagonists', default=0, type=int) argp.add_argument('-a', '--antagonists', default=0, type=int)
argp.add_argument('-x', '--xml_report', default=None, type=str, argp.add_argument('-x', '--xml_report', default=None, type=str,
help='Generates a JUnit-compatible XML report') help='Generates a JUnit-compatible XML report')
@ -736,6 +744,10 @@ def _start_port_server(port_server_port):
urllib2.urlopen('http://localhost:%d/get' % port_server_port, urllib2.urlopen('http://localhost:%d/get' % port_server_port,
timeout=1).read() timeout=1).read()
break break
except socket.timeout:
print "waiting for port_server"
time.sleep(0.5)
waits += 1
except urllib2.URLError: except urllib2.URLError:
print "waiting for port_server" print "waiting for port_server"
time.sleep(0.5) time.sleep(0.5)

@ -12161,6 +12161,7 @@
"include/grpc/support/tls_msvc.h", "include/grpc/support/tls_msvc.h",
"include/grpc/support/tls_pthread.h", "include/grpc/support/tls_pthread.h",
"include/grpc/support/useful.h", "include/grpc/support/useful.h",
"src/core/support/block_annotate.h",
"src/core/support/env.h", "src/core/support/env.h",
"src/core/support/file.h", "src/core/support/file.h",
"src/core/support/murmur_hash.h", "src/core/support/murmur_hash.h",
@ -12201,6 +12202,7 @@
"include/grpc/support/tls_pthread.h", "include/grpc/support/tls_pthread.h",
"include/grpc/support/useful.h", "include/grpc/support/useful.h",
"src/core/support/alloc.c", "src/core/support/alloc.c",
"src/core/support/block_annotate.h",
"src/core/support/cmdline.c", "src/core/support/cmdline.c",
"src/core/support/cpu_iphone.c", "src/core/support/cpu_iphone.c",
"src/core/support/cpu_linux.c", "src/core/support/cpu_linux.c",

@ -8,7 +8,7 @@
<ItemDefinitionGroup> <ItemDefinitionGroup>
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)\..;$(SolutionDir)\..\include;$(SolutionDir)\..\third_party\protobuf\src;$(SolutionDir)\packages\grpc.dependencies.zlib.1.2.8.9\build\native\include;$(SolutionDir)\packages\grpc.dependencies.openssl.1.0.2.3\build\native\include;$(SolutionDir)\packages\gflags.2.1.2.1\build\native\include;$(SolutionDir)\packages\gtest.1.7.0.1\build\native\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)\..;$(SolutionDir)\..\include;$(SolutionDir)\..\third_party\protobuf\src;$(SolutionDir)\packages\grpc.dependencies.zlib.1.2.8.9\build\native\include;$(SolutionDir)\packages\grpc.dependencies.openssl.1.0.2.3\build\native\include;$(SolutionDir)\packages\gflags.2.1.2.1\build\native\include;$(SolutionDir)\packages\gtest.1.7.0.1\build\native\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_WIN32_WINNT=0x600;_SCL_SECURE_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>EnableAllWarnings</WarningLevel> <WarningLevel>EnableAllWarnings</WarningLevel>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>

@ -163,6 +163,7 @@
<ClInclude Include="..\..\..\include\grpc\support\useful.h" /> <ClInclude Include="..\..\..\include\grpc\support\useful.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\src\core\support\block_annotate.h" />
<ClInclude Include="..\..\..\src\core\support\env.h" /> <ClInclude Include="..\..\..\src\core\support\env.h" />
<ClInclude Include="..\..\..\src\core\support\file.h" /> <ClInclude Include="..\..\..\src\core\support\file.h" />
<ClInclude Include="..\..\..\src\core\support\murmur_hash.h" /> <ClInclude Include="..\..\..\src\core\support\murmur_hash.h" />

@ -197,6 +197,9 @@
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\..\src\core\support\block_annotate.h">
<Filter>src\core\support</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\core\support\env.h"> <ClInclude Include="..\..\..\src\core\support\env.h">
<Filter>src\core\support</Filter> <Filter>src\core\support</Filter>
</ClInclude> </ClInclude>

Loading…
Cancel
Save