Merge github.com:google/grpc into mac

pull/11/head
Craig Tiller 10 years ago
commit c5dcb6af74
  1. 65
      .clang-format
  2. 6
      .gitignore
  3. 638
      Makefile
  4. 15
      build.json
  5. 2
      include/grpc++/async_server_context.h
  6. 8
      include/grpc++/channel_interface.h
  7. 1
      include/grpc++/config.h
  8. 1
      include/grpc++/credentials.h
  9. 16
      include/grpc++/impl/rpc_service_method.h
  10. 1
      include/grpc++/status_code_enum.h
  11. 2
      include/grpc/byte_buffer.h
  12. 2
      include/grpc/byte_buffer_reader.h
  13. 2
      include/grpc/grpc.h
  14. 3
      include/grpc/status.h
  15. 2
      include/grpc/support/alloc.h
  16. 2
      include/grpc/support/atm.h
  17. 2
      include/grpc/support/atm_gcc_atomic.h
  18. 2
      include/grpc/support/atm_gcc_sync.h
  19. 4
      include/grpc/support/atm_win32.h
  20. 2
      include/grpc/support/cancellable_platform.h
  21. 2
      include/grpc/support/cmdline.h
  22. 2
      include/grpc/support/histogram.h
  23. 2
      include/grpc/support/log.h
  24. 2
      include/grpc/support/slice.h
  25. 2
      include/grpc/support/slice_buffer.h
  26. 2
      include/grpc/support/string.h
  27. 2
      include/grpc/support/sync.h
  28. 2
      include/grpc/support/sync_generic.h
  29. 2
      include/grpc/support/sync_posix.h
  30. 2
      include/grpc/support/sync_win32.h
  31. 2
      include/grpc/support/thd.h
  32. 2
      include/grpc/support/thd_posix.h
  33. 2
      include/grpc/support/thd_win32.h
  34. 2
      include/grpc/support/time.h
  35. 2
      include/grpc/support/time_posix.h
  36. 2
      include/grpc/support/time_win32.h
  37. 2
      include/grpc/support/useful.h
  38. 57
      src/compiler/cpp_generator.cc
  39. 3
      src/compiler/cpp_generator_helpers.h
  40. 7
      src/compiler/cpp_plugin.cc
  41. 218
      src/compiler/go_generator.cc
  42. 2
      src/compiler/go_generator.h
  43. 4
      src/compiler/go_plugin.cc
  44. 13
      src/compiler/ruby_generator.cc
  45. 8
      src/compiler/ruby_generator_helpers-inl.h
  46. 6
      src/compiler/ruby_generator_map-inl.h
  47. 6
      src/compiler/ruby_generator_string-inl.h
  48. 2
      src/core/channel/channel_args.h
  49. 11
      src/core/channel/channel_stack.c
  50. 2
      src/core/channel/channel_stack.h
  51. 2
      src/core/channel/client_channel.h
  52. 2
      src/core/channel/client_setup.h
  53. 6
      src/core/channel/connected_channel.c
  54. 2
      src/core/channel/connected_channel.h
  55. 2
      src/core/channel/metadata_buffer.c
  56. 2
      src/core/channel/metadata_buffer.h
  57. 4
      src/core/channel/noop_filter.c
  58. 2
      src/core/channel/noop_filter.h
  59. 2
      src/core/compression/algorithm.h
  60. 2
      src/core/compression/message_compress.h
  61. 2
      src/core/httpcli/format_request.h
  62. 2
      src/core/httpcli/httpcli.h
  63. 2
      src/core/httpcli/httpcli_security_context.h
  64. 2
      src/core/httpcli/parser.h
  65. 1
      src/core/iomgr/pollset.h
  66. 5
      src/core/security/auth.c
  67. 2
      src/core/security/auth.h
  68. 2
      src/core/security/credentials.h
  69. 2
      src/core/security/google_root_certs.h
  70. 2
      src/core/security/secure_endpoint.h
  71. 2
      src/core/security/secure_transport_setup.h
  72. 13
      src/core/security/security_context.c
  73. 2
      src/core/security/security_context.h
  74. 3
      src/core/security/server_secure_chttp2.c
  75. 2
      src/core/statistics/census_interface.h
  76. 2
      src/core/statistics/census_rpc_stats.h
  77. 4
      src/core/support/alloc.c
  78. 2
      src/core/support/cpu.h
  79. 2
      src/core/support/murmur_hash.h
  80. 2
      src/core/support/thd_internal.h
  81. 2
      src/core/surface/call.c
  82. 2
      src/core/surface/call.h
  83. 2
      src/core/surface/channel.c
  84. 2
      src/core/surface/channel.h
  85. 7
      src/core/surface/client.c
  86. 2
      src/core/surface/client.h
  87. 2
      src/core/surface/completion_queue.h
  88. 2
      src/core/surface/event_string.h
  89. 4
      src/core/surface/server.c
  90. 2
      src/core/surface/server.h
  91. 2
      src/core/surface/surface_trace.h
  92. 2
      src/core/transport/chttp2/frame.h
  93. 1
      src/core/transport/chttp2/frame_data.c
  94. 2
      src/core/transport/chttp2/frame_data.h
  95. 2
      src/core/transport/chttp2/frame_ping.h
  96. 2
      src/core/transport/chttp2/frame_rst_stream.h
  97. 2
      src/core/transport/chttp2/frame_settings.h
  98. 2
      src/core/transport/chttp2/frame_window_update.h
  99. 2
      src/core/transport/chttp2/hpack_parser.h
  100. 124
      src/core/transport/chttp2/hpack_table.c
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,65 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
BinPackArguments: true
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: true
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
SpacesBeforeTrailingComments: 2
Cpp11BracedListStyle: true
Standard: Auto
IndentWidth: 2
TabWidth: 8
UseTab: Never
BreakBeforeBraces: Attach
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: ControlStatements
DisableFormat: false
...

6
.gitignore vendored

@ -0,0 +1,6 @@
bins
deps
libs
objs
*.pyc

File diff suppressed because one or more lines are too long

@ -1341,6 +1341,7 @@
"test/cpp/end2end/sync_client_async_server_test.cc" "test/cpp/end2end/sync_client_async_server_test.cc"
], ],
"deps": [ "deps": [
"grpc++_test_util",
"grpc_test_util", "grpc_test_util",
"grpc++", "grpc++",
"grpc", "grpc",
@ -1353,9 +1354,7 @@
"build": "test", "build": "test",
"c++": true, "c++": true,
"src": [ "src": [
"test/cpp/interop/empty.proto", "test/cpp/qps/qpstest.proto",
"test/cpp/interop/messages.proto",
"test/cpp/interop/test.proto",
"test/cpp/qps/client.cc" "test/cpp/qps/client.cc"
], ],
"deps": [ "deps": [
@ -1372,9 +1371,7 @@
"build": "test", "build": "test",
"c++": true, "c++": true,
"src": [ "src": [
"test/cpp/interop/empty.proto", "test/cpp/qps/qpstest.proto",
"test/cpp/interop/messages.proto",
"test/cpp/interop/test.proto",
"test/cpp/qps/server.cc" "test/cpp/qps/server.cc"
], ],
"deps": [ "deps": [
@ -1451,7 +1448,8 @@
], ],
"deps": [ "deps": [
"grpc++", "grpc++",
"grpc" "grpc",
"gpr"
] ]
}, },
{ {
@ -1463,7 +1461,8 @@
], ],
"deps": [ "deps": [
"grpc++", "grpc++",
"grpc" "grpc",
"gpr"
] ]
}, },
{ {

@ -87,7 +87,7 @@ class AsyncServerContext {
system_clock::time_point absolute_deadline_; system_clock::time_point absolute_deadline_;
google::protobuf::Message* request_; // not owned google::protobuf::Message* request_; // not owned
grpc_call* call_; // owned grpc_call* call_; // owned
}; };
} // namespace grpc } // namespace grpc

@ -57,10 +57,10 @@ class ChannelInterface {
const google::protobuf::Message& request, const google::protobuf::Message& request,
google::protobuf::Message* result) = 0; google::protobuf::Message* result) = 0;
virtual StreamContextInterface* CreateStream(const RpcMethod& method, virtual StreamContextInterface* CreateStream(
ClientContext* context, const RpcMethod& method, ClientContext* context,
const google::protobuf::Message* request, const google::protobuf::Message* request,
google::protobuf::Message* result) = 0; google::protobuf::Message* result) = 0;
}; };
} // namespace grpc } // namespace grpc

@ -39,7 +39,6 @@
namespace grpc { namespace grpc {
typedef std::string string; typedef std::string string;
} }
#endif // __GRPCPP_CONFIG_H__ #endif // __GRPCPP_CONFIG_H__

@ -112,7 +112,6 @@ class CredentialsFactory {
const grpc::string& authorization_token, const grpc::string& authorization_token,
const grpc::string& authority_selector); const grpc::string& authority_selector);
// Combines two credentials objects into a composite credentials // Combines two credentials objects into a composite credentials
static std::unique_ptr<Credentials> ComposeCredentials( static std::unique_ptr<Credentials> ComposeCredentials(
const std::unique_ptr<Credentials>& creds1, const std::unique_ptr<Credentials>& creds1,

@ -55,14 +55,17 @@ class MethodHandler {
public: public:
virtual ~MethodHandler() {} virtual ~MethodHandler() {}
struct HandlerParameter { struct HandlerParameter {
HandlerParameter(ServerContext* context, const google::protobuf::Message* req, HandlerParameter(ServerContext* context,
const google::protobuf::Message* req,
google::protobuf::Message* resp) google::protobuf::Message* resp)
: server_context(context), : server_context(context),
request(req), request(req),
response(resp), response(resp),
stream_context(nullptr) {} stream_context(nullptr) {}
HandlerParameter(ServerContext* context, const google::protobuf::Message* req, HandlerParameter(ServerContext* context,
google::protobuf::Message* resp, StreamContextInterface* stream) const google::protobuf::Message* req,
google::protobuf::Message* resp,
StreamContextInterface* stream)
: server_context(context), : server_context(context),
request(req), request(req),
response(resp), response(resp),
@ -171,7 +174,8 @@ class RpcServiceMethod : public RpcMethod {
public: public:
// Takes ownership of the handler and two prototype objects. // Takes ownership of the handler and two prototype objects.
RpcServiceMethod(const char* name, RpcMethod::RpcType type, RpcServiceMethod(const char* name, RpcMethod::RpcType type,
MethodHandler* handler, google::protobuf::Message* request_prototype, MethodHandler* handler,
google::protobuf::Message* request_prototype,
google::protobuf::Message* response_prototype) google::protobuf::Message* response_prototype)
: RpcMethod(name, type), : RpcMethod(name, type),
handler_(handler), handler_(handler),
@ -180,7 +184,9 @@ class RpcServiceMethod : public RpcMethod {
MethodHandler* handler() { return handler_.get(); } MethodHandler* handler() { return handler_.get(); }
google::protobuf::Message* AllocateRequestProto() { return request_prototype_->New(); } google::protobuf::Message* AllocateRequestProto() {
return request_prototype_->New();
}
google::protobuf::Message* AllocateResponseProto() { google::protobuf::Message* AllocateResponseProto() {
return response_prototype_->New(); return response_prototype_->New();
} }

@ -34,7 +34,6 @@
#ifndef __GRPCPP_STATUS_CODE_ENUM_H__ #ifndef __GRPCPP_STATUS_CODE_ENUM_H__
#define __GRPCPP_STATUS_CODE_ENUM_H__ #define __GRPCPP_STATUS_CODE_ENUM_H__
namespace grpc { namespace grpc {
enum StatusCode { enum StatusCode {

@ -47,4 +47,4 @@ struct grpc_byte_buffer {
} data; } data;
}; };
#endif /* __GRPC_BYTE_BUFFER_H__ */ #endif /* __GRPC_BYTE_BUFFER_H__ */

@ -46,4 +46,4 @@ struct grpc_byte_buffer_reader {
} current; } current;
}; };
#endif /* __GRPC_BYTE_BUFFER_READER_H__ */ #endif /* __GRPC_BYTE_BUFFER_READER_H__ */

@ -453,4 +453,4 @@ void grpc_server_destroy(grpc_server *server);
} }
#endif #endif
#endif /* __GRPC_GRPC_H__ */ #endif /* __GRPC_GRPC_H__ */

@ -34,7 +34,6 @@
#ifndef __GRPC_STATUS_H__ #ifndef __GRPC_STATUS_H__
#define __GRPC_STATUS_H__ #define __GRPC_STATUS_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -200,4 +199,4 @@ typedef enum {
} }
#endif #endif
#endif /* __GRPC_STATUS_H__ */ #endif /* __GRPC_STATUS_H__ */

@ -55,4 +55,4 @@ void gpr_free_aligned(void *ptr);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_ALLOC_H__ */ #endif /* __GRPC_SUPPORT_ALLOC_H__ */

@ -89,4 +89,4 @@
#error could not determine platform for atm #error could not determine platform for atm
#endif #endif
#endif /* __GRPC_SUPPORT_ATM_H__ */ #endif /* __GRPC_SUPPORT_ATM_H__ */

@ -66,4 +66,4 @@ static __inline int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
__ATOMIC_RELAXED); __ATOMIC_RELAXED);
} }
#endif /* __GRPC_SUPPORT_ATM_GCC_ATOMIC_H__ */ #endif /* __GRPC_SUPPORT_ATM_GCC_ATOMIC_H__ */

@ -70,4 +70,4 @@ static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
#define gpr_atm_acq_cas(p, o, n) (__sync_bool_compare_and_swap((p), (o), (n))) #define gpr_atm_acq_cas(p, o, n) (__sync_bool_compare_and_swap((p), (o), (n)))
#define gpr_atm_rel_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n)) #define gpr_atm_rel_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n))
#endif /* __GRPC_SUPPORT_ATM_GCC_SYNC_H__ */ #endif /* __GRPC_SUPPORT_ATM_GCC_SYNC_H__ */

@ -55,8 +55,8 @@ static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
} }
static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) { static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
/* InterlockedCompareExchangePointerNoFence() not available on vista or /* InterlockedCompareExchangePointerNoFence() not available on vista or
windows7 */ windows7 */
#ifdef GPR_ARCH_64 #ifdef GPR_ARCH_64
return o == (gpr_atm)InterlockedCompareExchangeAcquire64(p, n, o); return o == (gpr_atm)InterlockedCompareExchangeAcquire64(p, n, o);
#else #else

@ -53,4 +53,4 @@ typedef struct {
struct gpr_cancellable_list_ waiters; struct gpr_cancellable_list_ waiters;
} gpr_cancellable; } gpr_cancellable;
#endif /* __GRPC_SUPPORT_CANCELLABLE_PLATFORM_H__ */ #endif /* __GRPC_SUPPORT_CANCELLABLE_PLATFORM_H__ */

@ -92,4 +92,4 @@ void gpr_cmdline_destroy(gpr_cmdline *cl);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_CMDLINE_H__ */ #endif /* __GRPC_SUPPORT_CMDLINE_H__ */

@ -63,4 +63,4 @@ double gpr_histogram_sum_of_squares(gpr_histogram *histogram);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_HISTOGRAM_H__ */ #endif /* __GRPC_SUPPORT_HISTOGRAM_H__ */

@ -105,4 +105,4 @@ void gpr_set_log_function(gpr_log_func func);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_LOG_H__ */ #endif /* __GRPC_SUPPORT_LOG_H__ */

@ -173,4 +173,4 @@ int gpr_slice_str_cmp(gpr_slice a, const char *b);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_SLICE_H__ */ #endif /* __GRPC_SUPPORT_SLICE_H__ */

@ -81,4 +81,4 @@ void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_SLICE_BUFFER_H__ */ #endif /* __GRPC_SUPPORT_SLICE_BUFFER_H__ */

@ -74,4 +74,4 @@ int gpr_asprintf(char **strp, const char *format, ...);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_STRING_H__ */ #endif /* __GRPC_SUPPORT_STRING_H__ */

@ -345,4 +345,4 @@ gpr_intptr gpr_stats_read(const gpr_stats_counter *c);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_SYNC_H__ */ #endif /* __GRPC_SUPPORT_SYNC_H__ */

@ -52,4 +52,4 @@ typedef struct { gpr_atm value; } gpr_stats_counter;
#define GPR_STATS_INIT \ #define GPR_STATS_INIT \
{ 0 } { 0 }
#endif /* __GRPC_SUPPORT_SYNC_GENERIC_H__ */ #endif /* __GRPC_SUPPORT_SYNC_GENERIC_H__ */

@ -45,4 +45,4 @@ typedef pthread_once_t gpr_once;
#define GPR_ONCE_INIT PTHREAD_ONCE_INIT #define GPR_ONCE_INIT PTHREAD_ONCE_INIT
#endif /* __GRPC_SUPPORT_SYNC_POSIX_H__ */ #endif /* __GRPC_SUPPORT_SYNC_POSIX_H__ */

@ -49,4 +49,4 @@ typedef CONDITION_VARIABLE gpr_cv;
typedef INIT_ONCE gpr_once; typedef INIT_ONCE gpr_once;
#define GPR_ONCE_INIT INIT_ONCE_STATIC_INIT #define GPR_ONCE_INIT INIT_ONCE_STATIC_INIT
#endif /* __GRPC_SUPPORT_SYNC_WIN32_H__ */ #endif /* __GRPC_SUPPORT_SYNC_WIN32_H__ */

@ -76,4 +76,4 @@ gpr_thd_options gpr_thd_options_default(void);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_THD_H__ */ #endif /* __GRPC_SUPPORT_THD_H__ */

@ -39,4 +39,4 @@
typedef pthread_t gpr_thd_id; typedef pthread_t gpr_thd_id;
#endif /* __GRPC_SUPPORT_THD_POSIX_H__ */ #endif /* __GRPC_SUPPORT_THD_POSIX_H__ */

@ -41,4 +41,4 @@
typedef int gpr_thd_id; typedef int gpr_thd_id;
#endif /* __GRPC_SUPPORT_THD_WIN32_H__ */ #endif /* __GRPC_SUPPORT_THD_WIN32_H__ */

@ -113,4 +113,4 @@ double gpr_timespec_to_micros(gpr_timespec t);
} }
#endif #endif
#endif /* __GRPC_SUPPORT_TIME_H__ */ #endif /* __GRPC_SUPPORT_TIME_H__ */

@ -40,4 +40,4 @@
typedef struct timespec gpr_timespec; typedef struct timespec gpr_timespec;
#endif /* __GRPC_SUPPORT_TIME_POSIX_H__ */ #endif /* __GRPC_SUPPORT_TIME_POSIX_H__ */

@ -43,4 +43,4 @@ typedef struct gpr_timespec {
long tv_nsec; long tv_nsec;
} gpr_timespec; } gpr_timespec;
#endif /* __GRPC_SUPPORT_TIME_WIN32_H__ */ #endif /* __GRPC_SUPPORT_TIME_WIN32_H__ */

@ -45,4 +45,4 @@
#define GPR_ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array))) #define GPR_ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array)))
#endif /* __GRPC_SUPPORT_USEFUL_H__ */ #endif /* __GRPC_SUPPORT_USEFUL_H__ */

@ -43,13 +43,11 @@ namespace grpc_cpp_generator {
namespace { namespace {
bool NoStreaming(const google::protobuf::MethodDescriptor* method) { bool NoStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() && return !method->client_streaming() && !method->server_streaming();
!method->server_streaming();
} }
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) { bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() && return method->client_streaming() && !method->server_streaming();
!method->server_streaming();
} }
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) { bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
@ -57,8 +55,7 @@ bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
} }
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) { bool BidiStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() && return method->client_streaming() && method->server_streaming();
method->server_streaming();
} }
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) { bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) {
@ -132,8 +129,8 @@ string GetSourceIncludes() {
} }
void PrintHeaderClientMethod(google::protobuf::io::Printer* printer, void PrintHeaderClientMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method, const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) { map<string, string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
(*vars)["Request"] = (*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true); grpc_cpp_generator::ClassName(method->input_type(), true);
@ -204,8 +201,9 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
printer->Indent(); printer->Indent();
// Client side // Client side
printer->Print("class Stub : public ::grpc::InternalStub {\n" printer->Print(
" public:\n"); "class Stub : public ::grpc::InternalStub {\n"
" public:\n");
printer->Indent(); printer->Indent();
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
PrintHeaderClientMethod(printer, service->method(i), vars); PrintHeaderClientMethod(printer, service->method(i), vars);
@ -219,8 +217,9 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
printer->Print("\n"); printer->Print("\n");
// Server side // Server side
printer->Print("class Service {\n" printer->Print(
" public:\n"); "class Service {\n"
" public:\n");
printer->Indent(); printer->Indent();
printer->Print("Service() : service_(nullptr) {}\n"); printer->Print("Service() : service_(nullptr) {}\n");
printer->Print("virtual ~Service();\n"); printer->Print("virtual ~Service();\n");
@ -229,8 +228,9 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
} }
printer->Print("::grpc::RpcService* service();\n"); printer->Print("::grpc::RpcService* service();\n");
printer->Outdent(); printer->Outdent();
printer->Print(" private:\n" printer->Print(
" ::grpc::RpcService* service_;\n"); " private:\n"
" ::grpc::RpcService* service_;\n");
printer->Print("};\n"); printer->Print("};\n");
printer->Outdent(); printer->Outdent();
@ -251,8 +251,8 @@ string GetHeaderServices(const google::protobuf::FileDescriptor* file) {
} }
void PrintSourceClientMethod(google::protobuf::io::Printer* printer, void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method, const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) { map<string, string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
(*vars)["Request"] = (*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true); grpc_cpp_generator::ClassName(method->input_type(), true);
@ -308,8 +308,8 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
} }
void PrintSourceServerMethod(google::protobuf::io::Printer* printer, void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method, const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) { map<string, string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
(*vars)["Request"] = (*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true); grpc_cpp_generator::ClassName(method->input_type(), true);
@ -362,12 +362,12 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
map<string, string>* vars) { map<string, string>* vars) {
(*vars)["Service"] = service->name(); (*vars)["Service"] = service->name();
printer->Print(*vars, printer->Print(*vars,
"$Service$::Stub* $Service$::NewStub(" "$Service$::Stub* $Service$::NewStub("
"const std::shared_ptr<::grpc::ChannelInterface>& channel) {\n" "const std::shared_ptr<::grpc::ChannelInterface>& channel) {\n"
" $Service$::Stub* stub = new $Service$::Stub();\n" " $Service$::Stub* stub = new $Service$::Stub();\n"
" stub->set_channel(channel);\n" " stub->set_channel(channel);\n"
" return stub;\n" " return stub;\n"
"};\n\n"); "};\n\n");
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
PrintSourceClientMethod(printer, service->method(i), vars); PrintSourceClientMethod(printer, service->method(i), vars);
} }
@ -380,11 +380,12 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
PrintSourceServerMethod(printer, service->method(i), vars); PrintSourceServerMethod(printer, service->method(i), vars);
} }
printer->Print(*vars, printer->Print(*vars,
"::grpc::RpcService* $Service$::Service::service() {\n"); "::grpc::RpcService* $Service$::Service::service() {\n");
printer->Indent(); printer->Indent();
printer->Print("if (service_ != nullptr) {\n" printer->Print(
" return service_;\n" "if (service_ != nullptr) {\n"
"}\n"); " return service_;\n"
"}\n");
printer->Print("service_ = new ::grpc::RpcService();\n"); printer->Print("service_ = new ::grpc::RpcService();\n");
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
const google::protobuf::MethodDescriptor* method = service->method(i); const google::protobuf::MethodDescriptor* method = service->method(i);

@ -85,7 +85,8 @@ inline string DotsToUnderscores(const string& name) {
return StringReplace(name, ".", "_"); return StringReplace(name, ".", "_");
} }
inline string ClassName(const google::protobuf::Descriptor* descriptor, bool qualified) { inline string ClassName(const google::protobuf::Descriptor* descriptor,
bool qualified) {
// Find "outer", the descriptor of the top-level message in which // Find "outer", the descriptor of the top-level message in which
// "descriptor" is embedded. // "descriptor" is embedded.
const google::protobuf::Descriptor* outer = descriptor; const google::protobuf::Descriptor* outer = descriptor;

@ -54,9 +54,10 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
google::protobuf::compiler::GeneratorContext* context, google::protobuf::compiler::GeneratorContext* context,
string* error) const { string* error) const {
if (file->options().cc_generic_services()) { if (file->options().cc_generic_services()) {
*error = "cpp grpc proto compiler plugin does not work with generic " *error =
"services. To generate cpp grpc APIs, please set \"" "cpp grpc proto compiler plugin does not work with generic "
"cc_generic_service = false\"."; "services. To generate cpp grpc APIs, please set \""
"cc_generic_service = false\".";
return false; return false;
} }

@ -31,8 +31,6 @@
* *
*/ */
using namespace std;
#include "src/compiler/go_generator.h" #include "src/compiler/go_generator.h"
#include <cctype> #include <cctype>
@ -42,26 +40,24 @@ using namespace std;
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
using namespace std;
namespace grpc_go_generator { namespace grpc_go_generator {
bool NoStreaming(const google::protobuf::MethodDescriptor* method) { bool NoStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() && return !method->client_streaming() && !method->server_streaming();
!method->server_streaming();
} }
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) { bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() && return method->client_streaming() && !method->server_streaming();
!method->server_streaming();
} }
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) { bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() && return !method->client_streaming() && method->server_streaming();
method->server_streaming();
} }
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) { bool BidiStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() && return method->client_streaming() && method->server_streaming();
method->server_streaming();
} }
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) { bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) {
@ -91,20 +87,22 @@ void PrintClientMethodDef(google::protobuf::io::Printer* printer,
(*vars)["Response"] = method->output_type()->name(); (*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) { if (NoStreaming(method)) {
printer->Print(*vars, printer->Print(*vars,
"\t$Method$(ctx context.Context, in *$Request$, opts ...rpc.CallOption) " "\t$Method$(ctx context.Context, in *$Request$, opts "
"(*$Response$, error)\n"); "...rpc.CallOption) "
"(*$Response$, error)\n");
} else if (BidiStreaming(method)) { } else if (BidiStreaming(method)) {
printer->Print(*vars, printer->Print(*vars,
"\t$Method$(ctx context.Context, opts ...rpc.CallOption) " "\t$Method$(ctx context.Context, opts ...rpc.CallOption) "
"($Service$_$Method$Client, error)\n"); "($Service$_$Method$Client, error)\n");
} else if (ServerOnlyStreaming(method)) { } else if (ServerOnlyStreaming(method)) {
printer->Print(*vars, printer->Print(
*vars,
"\t$Method$(ctx context.Context, m *$Request$, opts ...rpc.CallOption) " "\t$Method$(ctx context.Context, m *$Request$, opts ...rpc.CallOption) "
"($Service$_$Method$Client, error)\n"); "($Service$_$Method$Client, error)\n");
} else if (ClientOnlyStreaming(method)) { } else if (ClientOnlyStreaming(method)) {
printer->Print(*vars, printer->Print(*vars,
"\t$Method$(ctx context.Context, opts ...rpc.CallOption) " "\t$Method$(ctx context.Context, opts ...rpc.CallOption) "
"($Service$_$Method$Client, error)\n"); "($Service$_$Method$Client, error)\n");
} }
} }
@ -116,11 +114,11 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
(*vars)["Response"] = method->output_type()->name(); (*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) { if (NoStreaming(method)) {
printer->Print(*vars, printer->Print(
*vars,
"func (c *$ServiceStruct$Client) $Method$(ctx context.Context, " "func (c *$ServiceStruct$Client) $Method$(ctx context.Context, "
"in *$Request$, opts ...rpc.CallOption) (*$Response$, error) {\n"); "in *$Request$, opts ...rpc.CallOption) (*$Response$, error) {\n");
printer->Print(*vars, printer->Print(*vars, "\tout := new($Response$)\n");
"\tout := new($Response$)\n");
printer->Print(*vars, printer->Print(*vars,
"\terr := rpc.Invoke(ctx, \"/$Package$$Service$/$Method$\", " "\terr := rpc.Invoke(ctx, \"/$Package$$Service$/$Method$\", "
"in, out, c.cc, opts...)\n"); "in, out, c.cc, opts...)\n");
@ -142,20 +140,22 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
"\treturn &$ServiceStruct$$Method$Client{stream}, nil\n" "\treturn &$ServiceStruct$$Method$Client{stream}, nil\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $Service$_$Method$Client interface {\n" "type $Service$_$Method$Client interface {\n"
"\tSend(*$Request$) error\n" "\tSend(*$Request$) error\n"
"\tRecv() (*$Response$, error)\n" "\tRecv() (*$Response$, error)\n"
"\trpc.ClientStream\n" "\trpc.ClientStream\n"
"}\n\n"); "}\n\n");
printer->Print(*vars,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n" "func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n"
"\treturn x.ClientStream.SendProto(m)\n" "\treturn x.ClientStream.SendProto(m)\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) " "func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) "
"{\n" "{\n"
"\tm := new($Response$)\n" "\tm := new($Response$)\n"
@ -185,15 +185,16 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
"\treturn x, nil\n" "\treturn x, nil\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $Service$_$Method$Client interface {\n" "type $Service$_$Method$Client interface {\n"
"\tRecv() (*$Response$, error)\n" "\tRecv() (*$Response$, error)\n"
"\trpc.ClientStream\n" "\trpc.ClientStream\n"
"}\n\n"); "}\n\n");
printer->Print(*vars,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) " "func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) "
"{\n" "{\n"
"\tm := new($Response$)\n" "\tm := new($Response$)\n"
@ -215,20 +216,22 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
"\treturn &$ServiceStruct$$Method$Client{stream}, nil\n" "\treturn &$ServiceStruct$$Method$Client{stream}, nil\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $Service$_$Method$Client interface {\n" "type $Service$_$Method$Client interface {\n"
"\tSend(*$Request$) error\n" "\tSend(*$Request$) error\n"
"\tCloseAndRecv() (*$Response$, error)\n" "\tCloseAndRecv() (*$Response$, error)\n"
"\trpc.ClientStream\n" "\trpc.ClientStream\n"
"}\n\n"); "}\n\n");
printer->Print(*vars,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n" "func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n"
"\treturn x.ClientStream.SendProto(m)\n" "\treturn x.ClientStream.SendProto(m)\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) CloseAndRecv() (*$Response$, " "func (x *$ServiceStruct$$Method$Client) CloseAndRecv() (*$Response$, "
"error) {\n" "error) {\n"
"\tif err := x.ClientStream.CloseSend(); err != nil {\n" "\tif err := x.ClientStream.CloseSend(); err != nil {\n"
@ -264,7 +267,8 @@ void PrintClient(google::protobuf::io::Printer* printer,
"type $ServiceStruct$Client struct {\n" "type $ServiceStruct$Client struct {\n"
"\tcc *rpc.ClientConn\n" "\tcc *rpc.ClientConn\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(
*vars,
"func New$Service$Client(cc *rpc.ClientConn) $Service$Client {\n" "func New$Service$Client(cc *rpc.ClientConn) $Service$Client {\n"
"\treturn &$ServiceStruct$Client{cc}\n" "\treturn &$ServiceStruct$Client{cc}\n"
"}\n\n"); "}\n\n");
@ -280,17 +284,16 @@ void PrintServerMethodDef(google::protobuf::io::Printer* printer,
(*vars)["Request"] = method->input_type()->name(); (*vars)["Request"] = method->input_type()->name();
(*vars)["Response"] = method->output_type()->name(); (*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) { if (NoStreaming(method)) {
printer->Print(*vars, printer->Print(
*vars,
"\t$Method$(context.Context, *$Request$) (*$Response$, error)\n"); "\t$Method$(context.Context, *$Request$) (*$Response$, error)\n");
} else if (BidiStreaming(method)) { } else if (BidiStreaming(method)) {
printer->Print(*vars, printer->Print(*vars, "\t$Method$($Service$_$Method$Server) error\n");
"\t$Method$($Service$_$Method$Server) error\n");
} else if (ServerOnlyStreaming(method)) { } else if (ServerOnlyStreaming(method)) {
printer->Print(*vars, printer->Print(*vars,
"\t$Method$(*$Request$, $Service$_$Method$Server) error\n"); "\t$Method$(*$Request$, $Service$_$Method$Server) error\n");
} else if (ClientOnlyStreaming(method)) { } else if (ClientOnlyStreaming(method)) {
printer->Print(*vars, printer->Print(*vars, "\t$Method$($Service$_$Method$Server) error\n");
"\t$Method$($Service$_$Method$Server) error\n");
} }
} }
@ -301,11 +304,11 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
(*vars)["Request"] = method->input_type()->name(); (*vars)["Request"] = method->input_type()->name();
(*vars)["Response"] = method->output_type()->name(); (*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) { if (NoStreaming(method)) {
printer->Print(*vars, printer->Print(
*vars,
"func _$Service$_$Method$_Handler(srv interface{}, ctx context.Context," "func _$Service$_$Method$_Handler(srv interface{}, ctx context.Context,"
" buf []byte) (proto.Message, error) {\n"); " buf []byte) (proto.Message, error) {\n");
printer->Print(*vars, printer->Print(*vars, "\tin := new($Request$)\n");
"\tin := new($Request$)\n");
printer->Print("\tif err := proto.Unmarshal(buf, in); err != nil {\n"); printer->Print("\tif err := proto.Unmarshal(buf, in); err != nil {\n");
printer->Print("\t\treturn nil, err\n"); printer->Print("\t\treturn nil, err\n");
printer->Print("\t}\n"); printer->Print("\t}\n");
@ -317,27 +320,30 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
printer->Print("\treturn out, nil\n"); printer->Print("\treturn out, nil\n");
printer->Print("}\n\n"); printer->Print("}\n\n");
} else if (BidiStreaming(method)) { } else if (BidiStreaming(method)) {
printer->Print(*vars, printer->Print(
*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " "func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n" "error {\n"
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server" "\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server"
"{stream})\n" "{stream})\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $Service$_$Method$Server interface {\n" "type $Service$_$Method$Server interface {\n"
"\tSend(*$Response$) error\n" "\tSend(*$Response$) error\n"
"\tRecv() (*$Request$, error)\n" "\tRecv() (*$Request$, error)\n"
"\trpc.Stream\n" "\trpc.Stream\n"
"}\n\n"); "}\n\n");
printer->Print(*vars,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n" "func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n"
"\treturn x.Stream.SendProto(m)\n" "\treturn x.Stream.SendProto(m)\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) " "func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) "
"{\n" "{\n"
"\tm := new($Request$)\n" "\tm := new($Request$)\n"
@ -347,7 +353,8 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
"\treturn m, nil\n" "\treturn m, nil\n"
"}\n\n"); "}\n\n");
} else if (ServerOnlyStreaming(method)) { } else if (ServerOnlyStreaming(method)) {
printer->Print(*vars, printer->Print(
*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " "func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n" "error {\n"
"\tm := new($Request$)\n" "\tm := new($Request$)\n"
@ -358,36 +365,39 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
"&$ServiceStruct$$Method$Server{stream})\n" "&$ServiceStruct$$Method$Server{stream})\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $Service$_$Method$Server interface {\n" "type $Service$_$Method$Server interface {\n"
"\tSend(*$Response$) error\n" "\tSend(*$Response$) error\n"
"\trpc.Stream\n" "\trpc.Stream\n"
"}\n\n"); "}\n\n");
printer->Print(*vars,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n" "func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n"
"\treturn x.Stream.SendProto(m)\n" "\treturn x.Stream.SendProto(m)\n"
"}\n\n"); "}\n\n");
} else if (ClientOnlyStreaming(method)) { } else if (ClientOnlyStreaming(method)) {
printer->Print(*vars, printer->Print(
*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) " "func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n" "error {\n"
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server" "\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server"
"{stream})\n" "{stream})\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $Service$_$Method$Server interface {\n" "type $Service$_$Method$Server interface {\n"
"\tSendAndClose(*$Response$) error\n" "\tSendAndClose(*$Response$) error\n"
"\tRecv() (*$Request$, error)\n" "\tRecv() (*$Request$, error)\n"
"\trpc.Stream\n" "\trpc.Stream\n"
"}\n\n"); "}\n\n");
printer->Print(*vars,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(*vars, printer->Print(*vars,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Server) SendAndClose(m *$Response$) " "func (x *$ServiceStruct$$Method$Server) SendAndClose(m *$Response$) "
"error {\n" "error {\n"
"\tif err := x.Stream.SendProto(m); err != nil {\n" "\tif err := x.Stream.SendProto(m); err != nil {\n"
@ -395,7 +405,8 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
"\t}\n" "\t}\n"
"\treturn nil\n" "\treturn nil\n"
"}\n\n"); "}\n\n");
printer->Print(*vars, printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) {\n" "func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) {\n"
"\tm := new($Request$)\n" "\tm := new($Request$)\n"
"\tif err := x.Stream.RecvProto(m); err != nil {\n" "\tif err := x.Stream.RecvProto(m); err != nil {\n"
@ -411,22 +422,19 @@ void PrintServerMethodDesc(google::protobuf::io::Printer* printer,
map<string, string>* vars) { map<string, string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
printer->Print("\t\t{\n"); printer->Print("\t\t{\n");
printer->Print(*vars, printer->Print(*vars, "\t\t\tMethodName:\t\"$Method$\",\n");
"\t\t\tMethodName:\t\"$Method$\",\n"); printer->Print(*vars, "\t\t\tHandler:\t_$Service$_$Method$_Handler,\n");
printer->Print(*vars,
"\t\t\tHandler:\t_$Service$_$Method$_Handler,\n");
printer->Print("\t\t},\n"); printer->Print("\t\t},\n");
} }
void PrintServerStreamingMethodDesc(google::protobuf::io::Printer* printer, void PrintServerStreamingMethodDesc(
const google::protobuf::MethodDescriptor* method, google::protobuf::io::Printer* printer,
map<string, string>* vars) { const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
printer->Print("\t\t{\n"); printer->Print("\t\t{\n");
printer->Print(*vars, printer->Print(*vars, "\t\t\tStreamName:\t\"$Method$\",\n");
"\t\t\tStreamName:\t\"$Method$\",\n"); printer->Print(*vars, "\t\t\tHandler:\t_$Service$_$Method$_Handler,\n");
printer->Print(*vars,
"\t\t\tHandler:\t_$Service$_$Method$_Handler,\n");
printer->Print("\t\t},\n"); printer->Print("\t\t},\n");
} }
@ -467,8 +475,9 @@ void PrintServer(google::protobuf::io::Printer* printer,
PrintServerStreamingMethodDesc(printer, service->method(i), vars); PrintServerStreamingMethodDesc(printer, service->method(i), vars);
} }
} }
printer->Print("\t},\n" printer->Print(
"}\n\n"); "\t},\n"
"}\n\n");
} }
std::string BadToUnderscore(std::string str) { std::string BadToUnderscore(std::string str) {
@ -493,8 +502,9 @@ string GetServices(const google::protobuf::FileDescriptor* file) {
printer.Print(vars, "package $PackageName$\n\n"); printer.Print(vars, "package $PackageName$\n\n");
printer.Print("import (\n"); printer.Print("import (\n");
if (HasClientOnlyStreaming(file)) { if (HasClientOnlyStreaming(file)) {
printer.Print("\t\"fmt\"\n" printer.Print(
"\t\"io\"\n"); "\t\"fmt\"\n"
"\t\"io\"\n");
} }
printer.Print( printer.Print(
"\t\"google/net/grpc/go/rpc\"\n" "\t\"google/net/grpc/go/rpc\"\n"

@ -44,7 +44,7 @@ class FileDescriptor;
namespace grpc_go_generator { namespace grpc_go_generator {
string GetServices(const google::protobuf::FileDescriptor* file); std::string GetServices(const google::protobuf::FileDescriptor* file);
} // namespace grpc_go_generator } // namespace grpc_go_generator

@ -61,8 +61,8 @@ class GoGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
string file_name; string file_name;
if (file->name().size() > 6 && if (file->name().size() > 6 &&
file->name().find_last_of(".proto") == file->name().size() - 1) { file->name().find_last_of(".proto") == file->name().size() - 1) {
file_name = file->name().substr(0, file->name().size() - 6) + file_name =
"_grpc.pb.go"; file->name().substr(0, file->name().size() - 6) + "_grpc.pb.go";
} else { } else {
*error = "Invalid proto file name. Proto file must end with .proto"; *error = "Invalid proto file name. Proto file must end with .proto";
return false; return false;

@ -67,9 +67,8 @@ void PrintMethod(const MethodDescriptor* method, const string& package,
output_type = "stream(" + output_type + ")"; output_type = "stream(" + output_type + ")";
} }
map<string, string> method_vars = ListToDict({ map<string, string> method_vars = ListToDict({
"mth.name", method->name(), "mth.name", method->name(), "input.type", input_type, "output.type",
"input.type", input_type, output_type,
"output.type", output_type,
}); });
out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n"); out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n");
} }
@ -105,8 +104,7 @@ void PrintService(const ServiceDescriptor* service, const string& package,
out->Print("self.marshal_class_method = :encode\n"); out->Print("self.marshal_class_method = :encode\n");
out->Print("self.unmarshal_class_method = :decode\n"); out->Print("self.unmarshal_class_method = :decode\n");
map<string, string> pkg_vars = ListToDict({ map<string, string> pkg_vars = ListToDict({
"service.name", service->name(), "service.name", service->name(), "pkg.name", package,
"pkg.name", package,
}); });
out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n"); out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n");
out->Print("\n"); out->Print("\n");
@ -139,9 +137,8 @@ string GetServices(const FileDescriptor* file) {
// Write out a file header. // Write out a file header.
map<string, string> header_comment_vars = ListToDict({ map<string, string> header_comment_vars = ListToDict({
"file.name", file->name(), "file.name", file->name(), "file.package", file->package(),
"file.package", file->package(), });
});
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n"); out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
out.Print(header_comment_vars, out.Print(header_comment_vars,
"# Source: $file.name$ for package '$file.package$'\n"); "# Source: $file.name$ for package '$file.package$'\n");

@ -47,8 +47,9 @@ inline bool ServicesFilename(const google::protobuf::FileDescriptor* file,
static const unsigned proto_suffix_length = 6; // length of ".proto" static const unsigned proto_suffix_length = 6; // length of ".proto"
if (file->name().size() > proto_suffix_length && if (file->name().size() > proto_suffix_length &&
file->name().find_last_of(".proto") == file->name().size() - 1) { file->name().find_last_of(".proto") == file->name().size() - 1) {
*file_name_or_error = file->name().substr( *file_name_or_error =
0, file->name().size() - proto_suffix_length) + "_services.rb"; file->name().substr(0, file->name().size() - proto_suffix_length) +
"_services.rb";
return true; return true;
} else { } else {
*file_name_or_error = "Invalid proto file name: must end with .proto"; *file_name_or_error = "Invalid proto file name: must end with .proto";
@ -56,7 +57,8 @@ inline bool ServicesFilename(const google::protobuf::FileDescriptor* file,
} }
} }
inline string MessagesRequireName(const google::protobuf::FileDescriptor* file) { inline string MessagesRequireName(
const google::protobuf::FileDescriptor* file) {
return Replace(file->name(), ".proto", ""); return Replace(file->name(), ".proto", "");
} }

@ -40,7 +40,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
using std::initializer_list; using std::initializer_list;
using std::map; using std::map;
using std::vector; using std::vector;
@ -51,11 +50,12 @@ namespace grpc_ruby_generator {
// into a map of key* to value*. Is merely a readability helper for later code. // into a map of key* to value*. Is merely a readability helper for later code.
inline map<string, string> ListToDict(const initializer_list<string>& values) { inline map<string, string> ListToDict(const initializer_list<string>& values) {
if (values.size() % 2 != 0) { if (values.size() % 2 != 0) {
// MOE: insert std::cerr << "Not every 'key' has a value in `values`." << std::endl; // MOE: insert std::cerr << "Not every 'key' has a value in `values`."
// << std::endl;
} }
map<string, string> value_map; map<string, string> value_map;
auto value_iter = values.begin(); auto value_iter = values.begin();
for (unsigned i = 0; i < values.size()/2; ++i) { for (unsigned i = 0; i < values.size() / 2; ++i) {
string key = *value_iter; string key = *value_iter;
++value_iter; ++value_iter;
string value = *value_iter; string value = *value_iter;

@ -45,7 +45,7 @@ using std::transform;
namespace grpc_ruby_generator { namespace grpc_ruby_generator {
// Split splits a string using char into elems. // Split splits a string using char into elems.
inline vector<string> &Split(const string &s, char delim, inline vector<string>& Split(const string& s, char delim,
vector<string>* elems) { vector<string>* elems) {
stringstream ss(s); stringstream ss(s);
string item; string item;
@ -56,7 +56,7 @@ inline vector<string> &Split(const string &s, char delim,
} }
// Split splits a string using char, returning the result in a vector. // Split splits a string using char, returning the result in a vector.
inline vector<string> Split(const string &s, char delim) { inline vector<string> Split(const string& s, char delim) {
vector<string> elems; vector<string> elems;
Split(s, delim, &elems); Split(s, delim, &elems);
return elems; return elems;
@ -106,7 +106,7 @@ inline string CapitalizeFirst(string s) {
inline string RubyTypeOf(const string& a_type, const string& package) { inline string RubyTypeOf(const string& a_type, const string& package) {
string res(a_type); string res(a_type);
ReplacePrefix(&res, package, ""); // remove the leading package if present ReplacePrefix(&res, package, ""); // remove the leading package if present
ReplacePrefix(&res, ".", ""); // remove the leading . (no package) ReplacePrefix(&res, ".", ""); // remove the leading . (no package)
if (res.find('.') == string::npos) { if (res.find('.') == string::npos) {
return res; return res;
} else { } else {

@ -51,4 +51,4 @@ void grpc_channel_args_destroy(grpc_channel_args *a);
is specified in channel args, otherwise returns 0. */ is specified in channel args, otherwise returns 0. */
int grpc_channel_args_is_census_enabled(const grpc_channel_args *a); int grpc_channel_args_is_census_enabled(const grpc_channel_args *a);
#endif /* __GRPC_INTERNAL_CHANNEL_CHANNEL_ARGS_H__ */ #endif /* __GRPC_INTERNAL_CHANNEL_CHANNEL_ARGS_H__ */

@ -54,7 +54,7 @@
/* Given a size, round up to the next multiple of sizeof(void*) */ /* Given a size, round up to the next multiple of sizeof(void*) */
#define ROUND_UP_TO_ALIGNMENT_SIZE(x) \ #define ROUND_UP_TO_ALIGNMENT_SIZE(x) \
(((x)+GPR_MAX_ALIGNMENT - 1) & ~(GPR_MAX_ALIGNMENT - 1)) (((x) + GPR_MAX_ALIGNMENT - 1) & ~(GPR_MAX_ALIGNMENT - 1))
size_t grpc_channel_stack_size(const grpc_channel_filter **filters, size_t grpc_channel_stack_size(const grpc_channel_filter **filters,
size_t filter_count) { size_t filter_count) {
@ -190,14 +190,13 @@ void grpc_channel_next_op(grpc_channel_element *elem, grpc_channel_op *op) {
grpc_channel_stack *grpc_channel_stack_from_top_element( grpc_channel_stack *grpc_channel_stack_from_top_element(
grpc_channel_element *elem) { grpc_channel_element *elem) {
return (grpc_channel_stack *)((char *)(elem) - return (grpc_channel_stack *)((char *)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE(
ROUND_UP_TO_ALIGNMENT_SIZE( sizeof(grpc_channel_stack)));
sizeof(grpc_channel_stack)));
} }
grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem) { grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem) {
return (grpc_call_stack *)((char *)(elem) - ROUND_UP_TO_ALIGNMENT_SIZE( return (grpc_call_stack *)((char *)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE(
sizeof(grpc_call_stack))); sizeof(grpc_call_stack)));
} }
static void do_nothing(void *user_data, grpc_op_error error) {} static void do_nothing(void *user_data, grpc_op_error error) {}

@ -302,4 +302,4 @@ void grpc_call_element_send_cancel(grpc_call_element *cur_elem);
} while (0) } while (0)
#endif #endif
#endif /* __GRPC_INTERNAL_CHANNEL_CHANNEL_STACK_H__ */ #endif /* __GRPC_INTERNAL_CHANNEL_CHANNEL_STACK_H__ */

@ -59,4 +59,4 @@ grpc_transport_setup_result grpc_client_channel_transport_setup_complete(
grpc_channel_filter const **channel_filters, size_t num_channel_filters, grpc_channel_filter const **channel_filters, size_t num_channel_filters,
grpc_mdctx *mdctx); grpc_mdctx *mdctx);
#endif /* __GRPC_INTERNAL_CHANNEL_CLIENT_CHANNEL_H__ */ #endif /* __GRPC_INTERNAL_CHANNEL_CLIENT_CHANNEL_H__ */

@ -64,4 +64,4 @@ gpr_timespec grpc_client_setup_request_deadline(grpc_client_setup_request *r);
grpc_mdctx *grpc_client_setup_get_mdctx(grpc_client_setup_request *r); grpc_mdctx *grpc_client_setup_get_mdctx(grpc_client_setup_request *r);
#endif /* __GRPC_INTERNAL_CHANNEL_CLIENT_SETUP_H__ */ #endif /* __GRPC_INTERNAL_CHANNEL_CLIENT_SETUP_H__ */

@ -69,7 +69,7 @@ typedef struct {
/* We perform a small hack to locate transport data alongside the connected /* We perform a small hack to locate transport data alongside the connected
channel data in call allocations, to allow everything to be pulled in minimal channel data in call allocations, to allow everything to be pulled in minimal
cache line requests */ cache line requests */
#define TRANSPORT_STREAM_FROM_CALL_DATA(calld) ((grpc_stream *)((calld)+1)) #define TRANSPORT_STREAM_FROM_CALL_DATA(calld) ((grpc_stream *)((calld) + 1))
#define CALL_DATA_FROM_TRANSPORT_STREAM(transport_stream) \ #define CALL_DATA_FROM_TRANSPORT_STREAM(transport_stream) \
(((call_data *)(transport_stream)) - 1) (((call_data *)(transport_stream)) - 1)
@ -257,9 +257,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
} }
const grpc_channel_filter grpc_connected_channel_filter = { const grpc_channel_filter grpc_connected_channel_filter = {
call_op, channel_op, call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem, sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem, sizeof(channel_data), init_channel_elem, destroy_channel_elem,

@ -46,4 +46,4 @@ extern const grpc_channel_filter grpc_connected_channel_filter;
grpc_transport_setup_result grpc_connected_channel_bind_transport( grpc_transport_setup_result grpc_connected_channel_bind_transport(
grpc_channel_stack *channel_stack, grpc_transport *transport); grpc_channel_stack *channel_stack, grpc_transport *transport);
#endif /* __GRPC_INTERNAL_CHANNEL_CONNECTED_CHANNEL_H__ */ #endif /* __GRPC_INTERNAL_CHANNEL_CONNECTED_CHANNEL_H__ */

@ -61,7 +61,7 @@ struct grpc_metadata_buffer_impl {
size_t elem_cap; size_t elem_cap;
}; };
#define ELEMS(buffer) ((qelem *)((buffer)+1)) #define ELEMS(buffer) ((qelem *)((buffer) + 1))
void grpc_metadata_buffer_init(grpc_metadata_buffer *buffer) { void grpc_metadata_buffer_init(grpc_metadata_buffer *buffer) {
/* start buffer as NULL, indicating no elements */ /* start buffer as NULL, indicating no elements */

@ -67,4 +67,4 @@ grpc_metadata *grpc_metadata_buffer_extract_elements(
grpc_metadata_buffer *buffer); grpc_metadata_buffer *buffer);
void grpc_metadata_buffer_cleanup_elements(void *elements, grpc_op_error error); void grpc_metadata_buffer_cleanup_elements(void *elements, grpc_op_error error);
#endif /* __GRPC_INTERNAL_CHANNEL_METADATA_BUFFER_H__ */ #endif /* __GRPC_INTERNAL_CHANNEL_METADATA_BUFFER_H__ */

@ -131,9 +131,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
} }
const grpc_channel_filter grpc_no_op_filter = { const grpc_channel_filter grpc_no_op_filter = {
call_op, channel_op, call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem, sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem, sizeof(channel_data), init_channel_elem, destroy_channel_elem,

@ -41,4 +41,4 @@
customize for their own filters */ customize for their own filters */
extern const grpc_channel_filter grpc_no_op_filter; extern const grpc_channel_filter grpc_no_op_filter;
#endif /* __GRPC_INTERNAL_CHANNEL_NOOP_FILTER_H__ */ #endif /* __GRPC_INTERNAL_CHANNEL_NOOP_FILTER_H__ */

@ -46,4 +46,4 @@ typedef enum {
const char *grpc_compression_algorithm_name( const char *grpc_compression_algorithm_name(
grpc_compression_algorithm algorithm); grpc_compression_algorithm algorithm);
#endif /* __GRPC_INTERNAL_COMPRESSION_ALGORITHM_H__ */ #endif /* __GRPC_INTERNAL_COMPRESSION_ALGORITHM_H__ */

@ -49,4 +49,4 @@ int grpc_msg_compress(grpc_compression_algorithm algorithm,
int grpc_msg_decompress(grpc_compression_algorithm algorithm, int grpc_msg_decompress(grpc_compression_algorithm algorithm,
gpr_slice_buffer *input, gpr_slice_buffer *output); gpr_slice_buffer *input, gpr_slice_buffer *output);
#endif /* __GRPC_INTERNAL_COMPRESSION_MESSAGE_COMPRESS_H__ */ #endif /* __GRPC_INTERNAL_COMPRESSION_MESSAGE_COMPRESS_H__ */

@ -42,4 +42,4 @@ gpr_slice grpc_httpcli_format_post_request(const grpc_httpcli_request *request,
const char *body_bytes, const char *body_bytes,
size_t body_size); size_t body_size);
#endif /* __GRPC_INTERNAL_HTTPCLI_FORMAT_REQUEST_H__ */ #endif /* __GRPC_INTERNAL_HTTPCLI_FORMAT_REQUEST_H__ */

@ -115,4 +115,4 @@ typedef int (*grpc_httpcli_post_override)(const grpc_httpcli_request *request,
void grpc_httpcli_set_override(grpc_httpcli_get_override get, void grpc_httpcli_set_override(grpc_httpcli_get_override get,
grpc_httpcli_post_override post); grpc_httpcli_post_override post);
#endif /* __GRPC_INTERNAL_HTTPCLI_HTTPCLI_H__ */ #endif /* __GRPC_INTERNAL_HTTPCLI_HTTPCLI_H__ */

@ -40,4 +40,4 @@ grpc_security_status grpc_httpcli_ssl_channel_security_context_create(
const unsigned char *pem_root_certs, size_t pem_root_certs_size, const unsigned char *pem_root_certs, size_t pem_root_certs_size,
const char *secure_peer_name, grpc_channel_security_context **ctx); const char *secure_peer_name, grpc_channel_security_context **ctx);
#endif /* __GRPC_INTERNAL_HTTPCLI_HTTPCLI_SECURITY_CONTEXT_H__ */ #endif /* __GRPC_INTERNAL_HTTPCLI_HTTPCLI_SECURITY_CONTEXT_H__ */

@ -61,4 +61,4 @@ void grpc_httpcli_parser_destroy(grpc_httpcli_parser *parser);
int grpc_httpcli_parser_parse(grpc_httpcli_parser *parser, gpr_slice slice); int grpc_httpcli_parser_parse(grpc_httpcli_parser *parser, gpr_slice slice);
int grpc_httpcli_parser_eof(grpc_httpcli_parser *parser); int grpc_httpcli_parser_eof(grpc_httpcli_parser *parser);
#endif /* __GRPC_INTERNAL_HTTPCLI_PARSER_H__ */ #endif /* __GRPC_INTERNAL_HTTPCLI_PARSER_H__ */

@ -35,6 +35,7 @@
#define __GRPC_INTERNAL_IOMGR_POLLSET_H_ #define __GRPC_INTERNAL_IOMGR_POLLSET_H_
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include <grpc/support/time.h>
/* A grpc_pollset is a set of file descriptors that a higher level item is /* A grpc_pollset is a set of file descriptors that a higher level item is
interested in. For example: interested in. For example:

@ -157,6 +157,5 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
} }
const grpc_channel_filter grpc_client_auth_filter = { const grpc_channel_filter grpc_client_auth_filter = {
call_op, channel_op, sizeof(call_data), call_op, channel_op, sizeof(call_data), init_call_elem, destroy_call_elem,
init_call_elem, destroy_call_elem, sizeof(channel_data), sizeof(channel_data), init_channel_elem, destroy_channel_elem, "auth"};
init_channel_elem, destroy_channel_elem, "auth"};

@ -38,4 +38,4 @@
extern const grpc_channel_filter grpc_client_auth_filter; extern const grpc_channel_filter grpc_client_auth_filter;
#endif /* __GRPC_INTERNAL_SECURITY_AUTH_H__ */ #endif /* __GRPC_INTERNAL_SECURITY_AUTH_H__ */

@ -143,4 +143,4 @@ struct grpc_server_credentials {
const grpc_ssl_config *grpc_ssl_server_credentials_get_config( const grpc_ssl_config *grpc_ssl_server_credentials_get_config(
const grpc_server_credentials *ssl_creds); const grpc_server_credentials *ssl_creds);
#endif /* __GRPC_INTERNAL_SECURITY_CREDENTIALS_H__ */ #endif /* __GRPC_INTERNAL_SECURITY_CREDENTIALS_H__ */

@ -37,4 +37,4 @@
extern unsigned char grpc_google_root_certs[]; extern unsigned char grpc_google_root_certs[];
extern unsigned int grpc_google_root_certs_size; extern unsigned int grpc_google_root_certs_size;
#endif /* __GRPC_INTERNAL_SECURITY_GOOGLE_ROOT_CERTS_H__ */ #endif /* __GRPC_INTERNAL_SECURITY_GOOGLE_ROOT_CERTS_H__ */

@ -44,4 +44,4 @@ grpc_endpoint *grpc_secure_endpoint_create(
struct tsi_frame_protector *protector, grpc_endpoint *to_wrap, struct tsi_frame_protector *protector, grpc_endpoint *to_wrap,
gpr_slice *leftover_slices, size_t leftover_nslices); gpr_slice *leftover_slices, size_t leftover_nslices);
#endif /* __GRPC_INTERNAL_ENDPOINT_SECURE_ENDPOINT_H__ */ #endif /* __GRPC_INTERNAL_ENDPOINT_SECURE_ENDPOINT_H__ */

@ -50,4 +50,4 @@ void grpc_setup_secure_transport(grpc_security_context *ctx,
grpc_secure_transport_setup_done_cb cb, grpc_secure_transport_setup_done_cb cb,
void *user_data); void *user_data);
#endif /* __GRPC_INTERNAL_SECURITY_SECURE_TRANSPORT_SETUP_H__ */ #endif /* __GRPC_INTERNAL_SECURITY_SECURE_TRANSPORT_SETUP_H__ */

@ -100,8 +100,7 @@ grpc_arg grpc_security_context_to_arg(grpc_security_context *ctx) {
return result; return result;
} }
grpc_security_context *grpc_security_context_from_arg( grpc_security_context *grpc_security_context_from_arg(const grpc_arg *arg) {
const grpc_arg *arg) {
if (strcmp(arg->key, GRPC_SECURITY_CONTEXT_ARG)) return NULL; if (strcmp(arg->key, GRPC_SECURITY_CONTEXT_ARG)) return NULL;
if (arg->type != GRPC_ARG_POINTER) { if (arg->type != GRPC_ARG_POINTER) {
gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type, gpr_log(GPR_ERROR, "Invalid type %d for arg %s", arg->type,
@ -140,9 +139,7 @@ static void fake_channel_destroy(grpc_security_context *ctx) {
gpr_free(ctx); gpr_free(ctx);
} }
static void fake_server_destroy(grpc_security_context *ctx) { static void fake_server_destroy(grpc_security_context *ctx) { gpr_free(ctx); }
gpr_free(ctx);
}
static grpc_security_status fake_channel_create_handshaker( static grpc_security_status fake_channel_create_handshaker(
grpc_security_context *ctx, tsi_handshaker **handshaker) { grpc_security_context *ctx, tsi_handshaker **handshaker) {
@ -234,8 +231,7 @@ static void ssl_channel_destroy(grpc_security_context *ctx) {
} }
static void ssl_server_destroy(grpc_security_context *ctx) { static void ssl_server_destroy(grpc_security_context *ctx) {
grpc_ssl_server_security_context *c = grpc_ssl_server_security_context *c = (grpc_ssl_server_security_context *)ctx;
(grpc_ssl_server_security_context *)ctx;
if (c->handshaker_factory != NULL) { if (c->handshaker_factory != NULL) {
tsi_ssl_handshaker_factory_destroy(c->handshaker_factory); tsi_ssl_handshaker_factory_destroy(c->handshaker_factory);
} }
@ -267,8 +263,7 @@ static grpc_security_status ssl_channel_create_handshaker(
static grpc_security_status ssl_server_create_handshaker( static grpc_security_status ssl_server_create_handshaker(
grpc_security_context *ctx, tsi_handshaker **handshaker) { grpc_security_context *ctx, tsi_handshaker **handshaker) {
grpc_ssl_server_security_context *c = grpc_ssl_server_security_context *c = (grpc_ssl_server_security_context *)ctx;
(grpc_ssl_server_security_context *)ctx;
return ssl_create_handshaker(c->handshaker_factory, 0, NULL, handshaker); return ssl_create_handshaker(c->handshaker_factory, 0, NULL, handshaker);
} }

@ -118,7 +118,7 @@ grpc_security_context *grpc_find_security_context_in_args(
typedef struct grpc_channel_security_context grpc_channel_security_context; typedef struct grpc_channel_security_context grpc_channel_security_context;
struct grpc_channel_security_context { struct grpc_channel_security_context {
grpc_security_context base; /* requires is_client_side to be non 0. */ grpc_security_context base; /* requires is_client_side to be non 0. */
grpc_credentials *request_metadata_creds; grpc_credentials *request_metadata_creds;
}; };

@ -70,8 +70,7 @@ static void on_accept(void *server, grpc_endpoint *tcp) {
const grpc_channel_args *args = grpc_server_get_channel_args(server); const grpc_channel_args *args = grpc_server_get_channel_args(server);
grpc_security_context *ctx = grpc_find_security_context_in_args(args); grpc_security_context *ctx = grpc_find_security_context_in_args(args);
GPR_ASSERT(ctx); GPR_ASSERT(ctx);
grpc_setup_secure_transport(ctx, tcp, on_secure_transport_setup_done, grpc_setup_secure_transport(ctx, tcp, on_secure_transport_setup_done, server);
server);
} }
/* Note: the following code is the same with server_chttp2.c */ /* Note: the following code is the same with server_chttp2.c */

@ -73,4 +73,4 @@ census_op_id census_tracing_start_op();
/* Ends tracing. Calling this function will invalidate the input op_id. */ /* Ends tracing. Calling this function will invalidate the input op_id. */
void census_tracing_end_op(census_op_id op_id); void census_tracing_end_op(census_op_id op_id);
#endif /* __GRPC_INTERNAL_STATISTICS_CENSUS_INTERFACE_H__ */ #endif /* __GRPC_INTERNAL_STATISTICS_CENSUS_INTERFACE_H__ */

@ -98,4 +98,4 @@ void census_stats_store_shutdown();
} }
#endif #endif
#endif /* __GRPC_INTERNAL_STATISTICS_CENSUS_RPC_STATS_H__ */ #endif /* __GRPC_INTERNAL_STATISTICS_CENSUS_RPC_STATS_H__ */

@ -62,6 +62,4 @@ void *gpr_malloc_aligned(size_t size, size_t alignment) {
return (void *)ret; return (void *)ret;
} }
void gpr_free_aligned(void *ptr) { void gpr_free_aligned(void *ptr) { free(((void **)ptr)[-1]); }
free(((void **)ptr)[-1]);
}

@ -46,4 +46,4 @@ int gpr_cpu_num_cores();
[0, gpr_cpu_num_cores() - 1] */ [0, gpr_cpu_num_cores() - 1] */
int gpr_cpu_current_cpu(); int gpr_cpu_current_cpu();
#endif /* __GRPC_INTERNAL_SUPPORT_CPU_H__ */ #endif /* __GRPC_INTERNAL_SUPPORT_CPU_H__ */

@ -41,4 +41,4 @@
/* compute the hash of key (length len) */ /* compute the hash of key (length len) */
gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed); gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed);
#endif /* __GRPC_INTERNAL_SUPPORT_MURMUR_HASH_H__ */ #endif /* __GRPC_INTERNAL_SUPPORT_MURMUR_HASH_H__ */

@ -36,4 +36,4 @@
/* Internal interfaces between modules within the gpr support library. */ /* Internal interfaces between modules within the gpr support library. */
#endif /* __GRPC_INTERNAL_SUPPORT_THD_INTERNAL_H__ */ #endif /* __GRPC_INTERNAL_SUPPORT_THD_INTERNAL_H__ */

@ -197,7 +197,7 @@ struct grpc_call {
gpr_refcount internal_refcount; gpr_refcount internal_refcount;
}; };
#define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call)+1)) #define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1))
#define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1) #define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1)
#define CALL_ELEM_FROM_CALL(call, idx) \ #define CALL_ELEM_FROM_CALL(call, idx) \
grpc_call_stack_element(CALL_STACK_FROM_CALL(call), idx) grpc_call_stack_element(CALL_STACK_FROM_CALL(call), idx)

@ -73,4 +73,4 @@ grpc_metadata_buffer *grpc_call_get_metadata_buffer(grpc_call *call);
void grpc_call_add_mdelem(grpc_call *call, grpc_mdelem *mdelem, void grpc_call_add_mdelem(grpc_call *call, grpc_mdelem *mdelem,
gpr_uint32 flags); gpr_uint32 flags);
#endif /* __GRPC_INTERNAL_SURFACE_CALL_H__ */ #endif /* __GRPC_INTERNAL_SURFACE_CALL_H__ */

@ -51,7 +51,7 @@ struct grpc_channel {
grpc_mdstr *authority_string; grpc_mdstr *authority_string;
}; };
#define CHANNEL_STACK_FROM_CHANNEL(c) ((grpc_channel_stack *)((c)+1)) #define CHANNEL_STACK_FROM_CHANNEL(c) ((grpc_channel_stack *)((c) + 1))
grpc_channel *grpc_channel_create_from_filters( grpc_channel *grpc_channel_create_from_filters(
const grpc_channel_filter **filters, size_t num_filters, const grpc_channel_filter **filters, size_t num_filters,

@ -48,4 +48,4 @@ grpc_mdstr *grpc_channel_get_message_string(grpc_channel *channel);
void grpc_channel_internal_ref(grpc_channel *channel); void grpc_channel_internal_ref(grpc_channel *channel);
void grpc_channel_internal_unref(grpc_channel *channel); void grpc_channel_internal_unref(grpc_channel *channel);
#endif /* __GRPC_INTERNAL_SURFACE_CHANNEL_H__ */ #endif /* __GRPC_INTERNAL_SURFACE_CHANNEL_H__ */

@ -106,13 +106,12 @@ static void init_channel_elem(grpc_channel_element *elem,
GPR_ASSERT(!is_last); GPR_ASSERT(!is_last);
} }
static void destroy_channel_elem(grpc_channel_element *elem) { static void destroy_channel_elem(grpc_channel_element *elem) {}
}
const grpc_channel_filter grpc_client_surface_filter = { const grpc_channel_filter grpc_client_surface_filter = {
call_op, channel_op, call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem, sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem, sizeof(channel_data), init_channel_elem, destroy_channel_elem,

@ -38,4 +38,4 @@
extern const grpc_channel_filter grpc_client_surface_filter; extern const grpc_channel_filter grpc_client_surface_filter;
#endif /* __GRPC_INTERNAL_SURFACE_CLIENT_H__ */ #endif /* __GRPC_INTERNAL_SURFACE_CLIENT_H__ */

@ -104,4 +104,4 @@ void grpc_cq_dump_pending_ops(grpc_completion_queue *cc);
grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc); grpc_pollset *grpc_cq_pollset(grpc_completion_queue *cc);
#endif /* __GRPC_INTERNAL_SURFACE_COMPLETION_QUEUE_H__ */ #endif /* __GRPC_INTERNAL_SURFACE_COMPLETION_QUEUE_H__ */

@ -39,4 +39,4 @@
/* Returns a string describing an event. Must be later freed with gpr_free() */ /* Returns a string describing an event. Must be later freed with gpr_free() */
char *grpc_event_string(grpc_event *ev); char *grpc_event_string(grpc_event *ev);
#endif /* __GRPC_INTERNAL_SURFACE_EVENT_STRING_H__ */ #endif /* __GRPC_INTERNAL_SURFACE_EVENT_STRING_H__ */

@ -405,9 +405,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
} }
static const grpc_channel_filter server_surface_filter = { static const grpc_channel_filter server_surface_filter = {
call_op, channel_op, call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem, sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem, sizeof(channel_data), init_channel_elem, destroy_channel_elem,

@ -60,4 +60,4 @@ grpc_transport_setup_result grpc_server_setup_transport(
const grpc_channel_args *grpc_server_get_channel_args(grpc_server *server); const grpc_channel_args *grpc_server_get_channel_args(grpc_server *server);
#endif /* __GRPC_INTERNAL_SURFACE_SERVER_H__ */ #endif /* __GRPC_INTERNAL_SURFACE_SERVER_H__ */

@ -51,4 +51,4 @@
} while (0) } while (0)
#endif #endif
#endif /* __GRPC_INTERNAL_SURFACE_SURFACE_TRACE_H__ */ #endif /* __GRPC_INTERNAL_SURFACE_SURFACE_TRACE_H__ */

@ -77,4 +77,4 @@ typedef struct {
#define GRPC_CHTTP2_DATA_FLAG_PADDED 8 #define GRPC_CHTTP2_DATA_FLAG_PADDED 8
#define GRPC_CHTTP2_FLAG_HAS_PRIORITY 0x20 #define GRPC_CHTTP2_FLAG_HAS_PRIORITY 0x20
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_H__ */ #endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_H__ */

@ -161,4 +161,3 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
abort(); abort();
return GRPC_CHTTP2_CONNECTION_ERROR; return GRPC_CHTTP2_CONNECTION_ERROR;
} }

@ -77,4 +77,4 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
/* create a slice with an empty data frame and is_last set */ /* create a slice with an empty data frame and is_last set */
gpr_slice grpc_chttp2_data_frame_create_empty_close(gpr_uint32 id); gpr_slice grpc_chttp2_data_frame_create_empty_close(gpr_uint32 id);
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_DATA_H__ */ #endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_DATA_H__ */

@ -50,4 +50,4 @@ grpc_chttp2_parse_error grpc_chttp2_ping_parser_begin_frame(
grpc_chttp2_parse_error grpc_chttp2_ping_parser_parse( grpc_chttp2_parse_error grpc_chttp2_ping_parser_parse(
void *parser, grpc_chttp2_parse_state *state, gpr_slice slice, int is_last); void *parser, grpc_chttp2_parse_state *state, gpr_slice slice, int is_last);
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_PING_H__ */ #endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_PING_H__ */

@ -38,4 +38,4 @@
gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 stream_id, gpr_uint32 code); gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 stream_id, gpr_uint32 code);
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_RST_STREAM_H__ */ #endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_RST_STREAM_H__ */

@ -96,4 +96,4 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_begin_frame(
grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse( grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
void *parser, grpc_chttp2_parse_state *state, gpr_slice slice, int is_last); void *parser, grpc_chttp2_parse_state *state, gpr_slice slice, int is_last);
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_SETTINGS_H__ */ #endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_SETTINGS_H__ */

@ -52,4 +52,4 @@ grpc_chttp2_parse_error grpc_chttp2_window_update_parser_begin_frame(
grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse( grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse(
void *parser, grpc_chttp2_parse_state *state, gpr_slice slice, int is_last); void *parser, grpc_chttp2_parse_state *state, gpr_slice slice, int is_last);
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_WINDOW_UPDATE_H__ */ #endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_FRAME_WINDOW_UPDATE_H__ */

@ -108,4 +108,4 @@ grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
void *hpack_parser, grpc_chttp2_parse_state *state, gpr_slice slice, void *hpack_parser, grpc_chttp2_parse_state *state, gpr_slice slice,
int is_last); int is_last);
#endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_HPACK_PARSER_H__ */ #endif /* __GRPC_INTERNAL_TRANSPORT_CHTTP2_HPACK_PARSER_H__ */

@ -43,68 +43,68 @@ static struct {
const char *key; const char *key;
const char *value; const char *value;
} static_table[] = { } static_table[] = {
/* 0: */ {NULL, NULL}, /* 0: */ {NULL, NULL},
/* 1: */ {":authority", ""}, /* 1: */ {":authority", ""},
/* 2: */ {":method", "GET"}, /* 2: */ {":method", "GET"},
/* 3: */ {":method", "POST"}, /* 3: */ {":method", "POST"},
/* 4: */ {":path", "/"}, /* 4: */ {":path", "/"},
/* 5: */ {":path", "/index.html"}, /* 5: */ {":path", "/index.html"},
/* 6: */ {":scheme", "http"}, /* 6: */ {":scheme", "http"},
/* 7: */ {":scheme", "https"}, /* 7: */ {":scheme", "https"},
/* 8: */ {":status", "200"}, /* 8: */ {":status", "200"},
/* 9: */ {":status", "204"}, /* 9: */ {":status", "204"},
/* 10: */ {":status", "206"}, /* 10: */ {":status", "206"},
/* 11: */ {":status", "304"}, /* 11: */ {":status", "304"},
/* 12: */ {":status", "400"}, /* 12: */ {":status", "400"},
/* 13: */ {":status", "404"}, /* 13: */ {":status", "404"},
/* 14: */ {":status", "500"}, /* 14: */ {":status", "500"},
/* 15: */ {"accept-charset", ""}, /* 15: */ {"accept-charset", ""},
/* 16: */ {"accept-encoding", "gzip, deflate"}, /* 16: */ {"accept-encoding", "gzip, deflate"},
/* 17: */ {"accept-language", ""}, /* 17: */ {"accept-language", ""},
/* 18: */ {"accept-ranges", ""}, /* 18: */ {"accept-ranges", ""},
/* 19: */ {"accept", ""}, /* 19: */ {"accept", ""},
/* 20: */ {"access-control-allow-origin", ""}, /* 20: */ {"access-control-allow-origin", ""},
/* 21: */ {"age", ""}, /* 21: */ {"age", ""},
/* 22: */ {"allow", ""}, /* 22: */ {"allow", ""},
/* 23: */ {"authorization", ""}, /* 23: */ {"authorization", ""},
/* 24: */ {"cache-control", ""}, /* 24: */ {"cache-control", ""},
/* 25: */ {"content-disposition", ""}, /* 25: */ {"content-disposition", ""},
/* 26: */ {"content-encoding", ""}, /* 26: */ {"content-encoding", ""},
/* 27: */ {"content-language", ""}, /* 27: */ {"content-language", ""},
/* 28: */ {"content-length", ""}, /* 28: */ {"content-length", ""},
/* 29: */ {"content-location", ""}, /* 29: */ {"content-location", ""},
/* 30: */ {"content-range", ""}, /* 30: */ {"content-range", ""},
/* 31: */ {"content-type", ""}, /* 31: */ {"content-type", ""},
/* 32: */ {"cookie", ""}, /* 32: */ {"cookie", ""},
/* 33: */ {"date", ""}, /* 33: */ {"date", ""},
/* 34: */ {"etag", ""}, /* 34: */ {"etag", ""},
/* 35: */ {"expect", ""}, /* 35: */ {"expect", ""},
/* 36: */ {"expires", ""}, /* 36: */ {"expires", ""},
/* 37: */ {"from", ""}, /* 37: */ {"from", ""},
/* 38: */ {"host", ""}, /* 38: */ {"host", ""},
/* 39: */ {"if-match", ""}, /* 39: */ {"if-match", ""},
/* 40: */ {"if-modified-since", ""}, /* 40: */ {"if-modified-since", ""},
/* 41: */ {"if-none-match", ""}, /* 41: */ {"if-none-match", ""},
/* 42: */ {"if-range", ""}, /* 42: */ {"if-range", ""},
/* 43: */ {"if-unmodified-since", ""}, /* 43: */ {"if-unmodified-since", ""},
/* 44: */ {"last-modified", ""}, /* 44: */ {"last-modified", ""},
/* 45: */ {"link", ""}, /* 45: */ {"link", ""},
/* 46: */ {"location", ""}, /* 46: */ {"location", ""},
/* 47: */ {"max-forwards", ""}, /* 47: */ {"max-forwards", ""},
/* 48: */ {"proxy-authenticate", ""}, /* 48: */ {"proxy-authenticate", ""},
/* 49: */ {"proxy-authorization", ""}, /* 49: */ {"proxy-authorization", ""},
/* 50: */ {"range", ""}, /* 50: */ {"range", ""},
/* 51: */ {"referer", ""}, /* 51: */ {"referer", ""},
/* 52: */ {"refresh", ""}, /* 52: */ {"refresh", ""},
/* 53: */ {"retry-after", ""}, /* 53: */ {"retry-after", ""},
/* 54: */ {"server", ""}, /* 54: */ {"server", ""},
/* 55: */ {"set-cookie", ""}, /* 55: */ {"set-cookie", ""},
/* 56: */ {"strict-transport-security", ""}, /* 56: */ {"strict-transport-security", ""},
/* 57: */ {"transfer-encoding", ""}, /* 57: */ {"transfer-encoding", ""},
/* 58: */ {"user-agent", ""}, /* 58: */ {"user-agent", ""},
/* 59: */ {"vary", ""}, /* 59: */ {"vary", ""},
/* 60: */ {"via", ""}, /* 60: */ {"via", ""},
/* 61: */ {"www-authenticate", ""}, /* 61: */ {"www-authenticate", ""},
}; };
void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx) { void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx) {

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save