Merge branch 'master' of github.com:ctiller/grpc

changes/47/217547/1
Craig Tiller 10 years ago
commit 43db6265c9
  1. 57
      .clang-format
  2. 15
      .gitignore
  3. 4
      .gitmodules
  4. 5
      INSTALL
  5. 5998
      Makefile
  6. 1042
      build.json
  7. 2
      include/grpc++/async_server_context.h
  8. 8
      include/grpc++/channel_interface.h
  9. 1
      include/grpc++/config.h
  10. 1
      include/grpc++/credentials.h
  11. 16
      include/grpc++/impl/rpc_service_method.h
  12. 1
      include/grpc++/status_code_enum.h
  13. 6
      include/grpc++/stream.h
  14. 2
      include/grpc++/stream_context_interface.h
  15. 2
      include/grpc/byte_buffer.h
  16. 2
      include/grpc/byte_buffer_reader.h
  17. 39
      include/grpc/grpc.h
  18. 3
      include/grpc/status.h
  19. 2
      include/grpc/support/alloc.h
  20. 2
      include/grpc/support/atm.h
  21. 2
      include/grpc/support/atm_gcc_atomic.h
  22. 2
      include/grpc/support/atm_gcc_sync.h
  23. 4
      include/grpc/support/atm_win32.h
  24. 2
      include/grpc/support/cancellable_platform.h
  25. 2
      include/grpc/support/cmdline.h
  26. 2
      include/grpc/support/histogram.h
  27. 2
      include/grpc/support/log.h
  28. 8
      include/grpc/support/port_platform.h
  29. 4
      include/grpc/support/slice.h
  30. 2
      include/grpc/support/slice_buffer.h
  31. 2
      include/grpc/support/string.h
  32. 2
      include/grpc/support/sync.h
  33. 2
      include/grpc/support/sync_generic.h
  34. 2
      include/grpc/support/sync_posix.h
  35. 2
      include/grpc/support/sync_win32.h
  36. 2
      include/grpc/support/thd.h
  37. 2
      include/grpc/support/thd_posix.h
  38. 2
      include/grpc/support/thd_win32.h
  39. 2
      include/grpc/support/time.h
  40. 2
      include/grpc/support/time_posix.h
  41. 2
      include/grpc/support/time_win32.h
  42. 2
      include/grpc/support/useful.h
  43. 179
      src/compiler/cpp_generator.cc
  44. 10
      src/compiler/cpp_generator.h
  45. 26
      src/compiler/cpp_generator_helpers.h
  46. 27
      src/compiler/cpp_plugin.cc
  47. 520
      src/compiler/go_generator.cc
  48. 83
      src/compiler/go_plugin.cc
  49. 48
      src/compiler/ruby_generator.cc
  50. 4
      src/compiler/ruby_generator.h
  51. 12
      src/compiler/ruby_generator_helpers-inl.h
  52. 15
      src/compiler/ruby_generator_map-inl.h
  53. 41
      src/compiler/ruby_generator_string-inl.h
  54. 15
      src/compiler/ruby_plugin.cc
  55. 12
      src/core/channel/census_filter.c
  56. 2
      src/core/channel/channel_args.h
  57. 2
      src/core/channel/channel_stack.h
  58. 4
      src/core/channel/child_channel.c
  59. 2
      src/core/channel/child_channel.h
  60. 4
      src/core/channel/client_channel.c
  61. 2
      src/core/channel/client_channel.h
  62. 2
      src/core/channel/client_setup.h
  63. 2
      src/core/channel/connected_channel.h
  64. 21
      src/core/channel/http_client_filter.c
  65. 2
      src/core/channel/http_client_filter.h
  66. 4
      src/core/channel/http_filter.c
  67. 4
      src/core/channel/http_server_filter.c
  68. 2
      src/core/channel/metadata_buffer.h
  69. 2
      src/core/channel/noop_filter.h
  70. 2
      src/core/compression/algorithm.h
  71. 2
      src/core/compression/message_compress.h
  72. 2
      src/core/httpcli/format_request.h
  73. 2
      src/core/httpcli/httpcli.h
  74. 2
      src/core/httpcli/httpcli_security_context.h
  75. 2
      src/core/httpcli/parser.h
  76. 4
      src/core/iomgr/alarm.c
  77. 6
      src/core/iomgr/alarm_internal.h
  78. 10
      src/core/iomgr/iomgr.c
  79. 4
      src/core/iomgr/iomgr.h
  80. 8
      src/core/iomgr/iomgr_internal.h
  81. 4
      src/core/iomgr/iomgr_posix.c
  82. 4
      src/core/iomgr/iomgr_posix.h
  83. 68
      src/core/iomgr/pollset_kick.h
  84. 161
      src/core/iomgr/pollset_kick_posix.c
  85. 47
      src/core/iomgr/pollset_kick_posix.h
  86. 9
      src/core/iomgr/pollset_multipoller_with_poll_posix.c
  87. 90
      src/core/iomgr/pollset_posix.c
  88. 5
      src/core/iomgr/pollset_posix.h
  89. 4
      src/core/iomgr/socket_utils_common_posix.c
  90. 2
      src/core/iomgr/socket_utils_posix.h
  91. 2
      src/core/iomgr/tcp_server.h
  92. 6
      src/core/iomgr/tcp_server_posix.c
  93. 2
      src/core/security/auth.h
  94. 4
      src/core/security/credentials.c
  95. 2
      src/core/security/credentials.h
  96. 2
      src/core/security/google_root_certs.h
  97. 12
      src/core/security/secure_endpoint.c
  98. 2
      src/core/security/secure_endpoint.h
  99. 4
      src/core/security/secure_transport_setup.c
  100. 2
      src/core/security/secure_transport_setup.h
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,57 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
ConstructorInitializerIndentWidth: 4
AlignEscapedNewlinesLeft: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerAlignment: true
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: None
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
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: ControlStatements
DisableFormat: false
...

15
.gitignore vendored

@ -1,6 +1,19 @@
# C/C++ build outputs
bins
deps
gens
libs
objs
# gcov coverage data
coverage
*.gcno
# profiler output
*.prof
# python compiled objects
*.pyc
# cache for run_tests.py
.run_tests_cache

4
.gitmodules vendored

@ -9,10 +9,6 @@
path = third_party/protobuf
url = https://github.com/google/protobuf.git
branch = v3.0.0-alpha-1
[submodule "third_party/libevent"]
path = third_party/libevent
url = https://github.com/libevent/libevent.git
branch = patches-2.0
[submodule "third_party/gflags"]
path = third_party/gflags
url = https://code.google.com/p/gflags

@ -12,8 +12,7 @@ Note that the Makefile makes it much easier for you to compile from sources
if you were to clone recursively our git repository.
grpc core currently depends on zlib and OpenSSL 1.0.2beta3, and also requires
libevent2 for the Linux port.
grpc core currently depends on zlib and OpenSSL 1.0.2beta3.
grpc++'s tests depends on protobuf 3.0.0, gtests and gflags.
@ -46,7 +45,7 @@ and let the Makefile build them itself.
You may also install the dependencies yourself, from the sources, or from
your distribution's package manager.
The development packages needed for grpc are libevent2 under Linux, and zlib.
The only development package needed for grpc is zlib.
The development packages needed for grpc++'s tests are gtests, and gflags.
To the best of our knowledge, no distribution has an OpenSSL package that

5998
Makefile

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

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

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

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

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

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

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

@ -96,7 +96,7 @@ class ClientReader : public ClientStreamingInterface,
virtual bool Read(R* msg) { return context_->Read(msg); }
virtual void Cancel() { context_->FinishStream(Status::Cancelled, true); }
virtual void Cancel() { context_->Cancel(); }
virtual const Status& Wait() { return context_->Wait(); }
@ -122,7 +122,7 @@ class ClientWriter : public ClientStreamingInterface,
virtual void WritesDone() { context_->Write(nullptr, true); }
virtual void Cancel() { context_->FinishStream(Status::Cancelled, true); }
virtual void Cancel() { context_->Cancel(); }
// Read the final response and wait for the final status.
virtual const Status& Wait() {
@ -165,7 +165,7 @@ class ClientReaderWriter : public ClientStreamingInterface,
virtual void WritesDone() { context_->Write(nullptr, true); }
virtual void Cancel() { context_->FinishStream(Status::Cancelled, true); }
virtual void Cancel() { context_->Cancel(); }
virtual const Status& Wait() { return context_->Wait(); }

@ -53,7 +53,7 @@ class StreamContextInterface {
virtual bool Read(google::protobuf::Message* msg) = 0;
virtual bool Write(const google::protobuf::Message* msg, bool is_last) = 0;
virtual const Status& Wait() = 0;
virtual void FinishStream(const Status& status, bool send) = 0;
virtual void Cancel() = 0;
virtual google::protobuf::Message* request() = 0;
virtual google::protobuf::Message* response() = 0;

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

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

@ -194,6 +194,7 @@ typedef enum grpc_completion_type {
GRPC_FINISHED, /* An RPC has finished. The event contains status.
On the server this will be OK or Cancelled. */
GRPC_SERVER_RPC_NEW, /* A new RPC has arrived at the server */
GRPC_SERVER_SHUTDOWN, /* The server has finished shutting down */
GRPC_COMPLETION_DO_NOT_USE /* must be last, forces users to include
a default: case */
} grpc_completion_type;
@ -232,12 +233,12 @@ typedef struct grpc_event {
} grpc_event;
/* Initialize the grpc library */
void grpc_init();
void grpc_init(void);
/* Shutdown the grpc library */
void grpc_shutdown();
void grpc_shutdown(void);
grpc_completion_queue *grpc_completion_queue_create();
grpc_completion_queue *grpc_completion_queue_create(void);
/* Blocks until an event is available, the completion queue is being shutdown,
or deadline is reached. Returns NULL on timeout, otherwise the event that
@ -325,22 +326,6 @@ grpc_call_error grpc_call_start_invoke(grpc_call *call,
void *metadata_read_tag,
void *finished_tag, gpr_uint32 flags);
/* DEPRECATED: users should use grpc_call_server_accept, and
grpc_call_server_end_initial_metadata instead now.
Accept an incoming RPC, binding a completion queue to it.
To be called after adding metadata to the call, but before sending
messages.
flags is a bit-field combination of the write flags defined above.
REQUIRES: Can be called at most once per call.
Can only be called on the server.
Produces a GRPC_FINISHED event with finished_tag when the call has been
completed (there may be other events for the call pending at this
time) */
grpc_call_error grpc_call_accept(grpc_call *call, grpc_completion_queue *cq,
void *finished_tag, gpr_uint32 flags);
/* Accept an incoming RPC, binding a completion queue to it.
To be called before sending or receiving messages.
REQUIRES: Can be called at most once per call.
@ -365,6 +350,16 @@ grpc_call_error grpc_call_server_end_initial_metadata(grpc_call *call,
Can be called multiple times, from any thread. */
grpc_call_error grpc_call_cancel(grpc_call *call);
/* Called by clients to cancel an RPC on the server.
Can be called multiple times, from any thread.
If a status has not been received for the call, set it to the status code
and description passed in.
Importantly, this function does not send status nor description to the
remote endpoint. */
grpc_call_error grpc_call_cancel_with_status(grpc_call *call,
grpc_status_code status,
const char *description);
/* Queue a byte buffer for writing.
flags is a bit-field combination of the write flags defined above.
A write with byte_buffer null is allowed, and will not send any bytes on the
@ -445,6 +440,10 @@ void grpc_server_start(grpc_server *server);
Existing calls will be allowed to complete. */
void grpc_server_shutdown(grpc_server *server);
/* As per grpc_server_shutdown, but send a GRPC_SERVER_SHUTDOWN event when
there are no more calls being serviced. */
void grpc_server_shutdown_and_notify(grpc_server *server, void *tag);
/* Destroy a server.
Forcefully cancels all existing calls. */
void grpc_server_destroy(grpc_server *server);
@ -453,4 +452,4 @@ void grpc_server_destroy(grpc_server *server);
}
#endif
#endif /* __GRPC_GRPC_H__ */
#endif /* __GRPC_GRPC_H__ */

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

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

@ -89,4 +89,4 @@
#error could not determine platform for atm
#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);
}
#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_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) {
/* InterlockedCompareExchangePointerNoFence() not available on vista or
windows7 */
/* InterlockedCompareExchangePointerNoFence() not available on vista or
windows7 */
#ifdef GPR_ARCH_64
return o == (gpr_atm)InterlockedCompareExchangeAcquire64(p, n, o);
#else

@ -53,4 +53,4 @@ typedef struct {
struct gpr_cancellable_list_ waiters;
} 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 /* __GRPC_SUPPORT_CMDLINE_H__ */
#endif /* __GRPC_SUPPORT_CMDLINE_H__ */

@ -63,4 +63,4 @@ double gpr_histogram_sum_of_squares(gpr_histogram *histogram);
}
#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 /* __GRPC_SUPPORT_LOG_H__ */
#endif /* __GRPC_SUPPORT_LOG_H__ */

@ -45,15 +45,16 @@
#if defined(_WIN64) || defined(WIN64)
#define GPR_WIN32 1
#define GPR_ARCH_64 1
#define GPR_GETPID_IN_PROCESS_H 1
#elif defined(_WIN32) || defined(WIN32)
#define GPR_ARCH_32 1
#define GPR_WIN32 1
#define GPR_GETPID_IN_PROCESS_H 1
#elif defined(ANDROID) || defined(__ANDROID__)
#define GPR_ANDROID 1
#define GPR_ARCH_32 1
#define GPR_CPU_LINUX 1
#define GPR_GCC_SYNC 1
#define GPR_LIBEVENT 1
#define GPR_POSIX_MULTIPOLL_WITH_POLL 1
#define GPR_POSIX_SOCKET 1
#define GPR_POSIX_SOCKETADDR 1
@ -61,10 +62,10 @@
#define GPR_POSIX_STRING 1
#define GPR_POSIX_SYNC 1
#define GPR_POSIX_TIME 1
#define GPR_GETPID_IN_UNISTD_H 1
#elif defined(__linux__)
#define GPR_CPU_LINUX 1
#define GPR_GCC_ATOMIC 1
#define GPR_LIBEVENT 1
#define GPR_LINUX 1
#define GPR_POSIX_MULTIPOLL_WITH_POLL 1
#define GPR_POSIX_SOCKET 1
@ -72,6 +73,7 @@
#define GPR_POSIX_STRING 1
#define GPR_POSIX_SYNC 1
#define GPR_POSIX_TIME 1
#define GPR_GETPID_IN_UNISTD_H 1
#ifdef _LP64
#define GPR_ARCH_64 1
#else /* _LP64 */
@ -80,7 +82,6 @@
#elif defined(__APPLE__)
#define GPR_CPU_POSIX 1
#define GPR_GCC_ATOMIC 1
#define GPR_LIBEVENT 1
#define GPR_POSIX_LOG 1
#define GPR_POSIX_MULTIPOLL_WITH_POLL 1
#define GPR_POSIX_SOCKET 1
@ -89,6 +90,7 @@
#define GPR_POSIX_STRING 1
#define GPR_POSIX_SYNC 1
#define GPR_POSIX_TIME 1
#define GPR_GETPID_IN_UNISTD_H 1
#ifdef _LP64
#define GPR_ARCH_64 1
#else /* _LP64 */

@ -163,7 +163,7 @@ gpr_slice gpr_slice_split_tail(gpr_slice *s, size_t split);
Requires s intialized, split <= s.length */
gpr_slice gpr_slice_split_head(gpr_slice *s, size_t split);
gpr_slice gpr_empty_slice();
gpr_slice gpr_empty_slice(void);
/* Returns <0 if a < b, ==0 if a == b, >0 if a > b */
int gpr_slice_cmp(gpr_slice a, gpr_slice b);
@ -173,4 +173,4 @@ int gpr_slice_str_cmp(gpr_slice a, const char *b);
}
#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 /* __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 /* __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 /* __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 \
{ 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
#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;
#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 /* __GRPC_SUPPORT_THD_H__ */
#endif /* __GRPC_SUPPORT_THD_H__ */

@ -39,4 +39,4 @@
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;
#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 /* __GRPC_SUPPORT_TIME_H__ */
#endif /* __GRPC_SUPPORT_TIME_H__ */

@ -40,4 +40,4 @@
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;
} 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)))
#endif /* __GRPC_SUPPORT_USEFUL_H__ */
#endif /* __GRPC_SUPPORT_USEFUL_H__ */

@ -31,6 +31,9 @@
*
*/
#include <string>
#include <map>
#include "src/compiler/cpp_generator.h"
#include "src/compiler/cpp_generator_helpers.h"
@ -42,26 +45,23 @@
namespace grpc_cpp_generator {
namespace {
bool NoStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() &&
!method->server_streaming();
bool NoStreaming(const google::protobuf::MethodDescriptor *method) {
return !method->client_streaming() && !method->server_streaming();
}
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() &&
!method->server_streaming();
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor *method) {
return method->client_streaming() && !method->server_streaming();
}
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor *method) {
return !method->client_streaming() && method->server_streaming();
}
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() &&
method->server_streaming();
bool BidiStreaming(const google::protobuf::MethodDescriptor *method) {
return method->client_streaming() && method->server_streaming();
}
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) {
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor *file) {
for (int i = 0; i < file->service_count(); i++) {
for (int j = 0; j < file->service(i)->method_count(); j++) {
if (ClientOnlyStreaming(file->service(i)->method(j))) {
@ -72,7 +72,7 @@ bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) {
return false;
}
bool HasServerOnlyStreaming(const google::protobuf::FileDescriptor* file) {
bool HasServerOnlyStreaming(const google::protobuf::FileDescriptor *file) {
for (int i = 0; i < file->service_count(); i++) {
for (int j = 0; j < file->service(i)->method_count(); j++) {
if (ServerOnlyStreaming(file->service(i)->method(j))) {
@ -83,7 +83,7 @@ bool HasServerOnlyStreaming(const google::protobuf::FileDescriptor* file) {
return false;
}
bool HasBidiStreaming(const google::protobuf::FileDescriptor* file) {
bool HasBidiStreaming(const google::protobuf::FileDescriptor *file) {
for (int i = 0; i < file->service_count(); i++) {
for (int j = 0; j < file->service(i)->method_count(); j++) {
if (BidiStreaming(file->service(i)->method(j))) {
@ -95,8 +95,8 @@ bool HasBidiStreaming(const google::protobuf::FileDescriptor* file) {
}
} // namespace
string GetHeaderIncludes(const google::protobuf::FileDescriptor* file) {
string temp =
std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file) {
std::string temp =
"#include \"grpc++/impl/internal_stub.h\"\n"
"#include \"grpc++/status.h\"\n"
"\n"
@ -124,16 +124,16 @@ string GetHeaderIncludes(const google::protobuf::FileDescriptor* file) {
return temp;
}
string GetSourceIncludes() {
std::string GetSourceIncludes() {
return "#include \"grpc++/channel_interface.h\"\n"
"#include \"grpc++/impl/rpc_method.h\"\n"
"#include \"grpc++/impl/rpc_service_method.h\"\n"
"#include \"grpc++/stream.h\"\n";
}
void PrintHeaderClientMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
void PrintHeaderClientMethod(google::protobuf::io::Printer *printer,
const google::protobuf::MethodDescriptor *method,
std::map<std::string, std::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@ -146,23 +146,23 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer* printer,
} else if (ClientOnlyStreaming(method)) {
printer->Print(
*vars,
"::grpc::ClientWriter<$Request$>* $Method$("
"::grpc::ClientWriter< $Request$>* $Method$("
"::grpc::ClientContext* context, $Response$* response);\n\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(
*vars,
"::grpc::ClientReader<$Response$>* $Method$("
"::grpc::ClientReader< $Response$>* $Method$("
"::grpc::ClientContext* context, const $Request$* request);\n\n");
} else if (BidiStreaming(method)) {
printer->Print(*vars,
"::grpc::ClientReaderWriter<$Request$, $Response$>* "
"::grpc::ClientReaderWriter< $Request$, $Response$>* "
"$Method$(::grpc::ClientContext* context);\n\n");
}
}
void PrintHeaderServerMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
void PrintHeaderServerMethod(google::protobuf::io::Printer *printer,
const google::protobuf::MethodDescriptor *method,
std::map<std::string, std::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@ -177,25 +177,26 @@ void PrintHeaderServerMethod(google::protobuf::io::Printer* printer,
printer->Print(*vars,
"virtual ::grpc::Status $Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerReader<$Request$>* reader, "
"::grpc::ServerReader< $Request$>* reader, "
"$Response$* response);\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(*vars,
"virtual ::grpc::Status $Method$("
"::grpc::ServerContext* context, const $Request$* request, "
"::grpc::ServerWriter<$Response$>* writer);\n");
"::grpc::ServerWriter< $Response$>* writer);\n");
} else if (BidiStreaming(method)) {
printer->Print(*vars,
"virtual ::grpc::Status $Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerReaderWriter<$Response$, $Request$>* stream);"
"\n");
printer->Print(
*vars,
"virtual ::grpc::Status $Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerReaderWriter< $Response$, $Request$>* stream);"
"\n");
}
}
void PrintHeaderService(google::protobuf::io::Printer* printer,
const google::protobuf::ServiceDescriptor* service,
map<string, string>* vars) {
void PrintHeaderService(google::protobuf::io::Printer *printer,
const google::protobuf::ServiceDescriptor *service,
std::map<std::string, std::string> *vars) {
(*vars)["Service"] = service->name();
printer->Print(*vars,
@ -204,8 +205,9 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
printer->Indent();
// Client side
printer->Print("class Stub : public ::grpc::InternalStub {\n"
" public:\n");
printer->Print(
"class Stub : public ::grpc::InternalStub {\n"
" public:\n");
printer->Indent();
for (int i = 0; i < service->method_count(); ++i) {
PrintHeaderClientMethod(printer, service->method(i), vars);
@ -213,14 +215,15 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
printer->Outdent();
printer->Print("};\n");
printer->Print(
"static Stub* NewStub(const std::shared_ptr<::grpc::ChannelInterface>& "
"static Stub* NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& "
"channel);\n");
printer->Print("\n");
// Server side
printer->Print("class Service {\n"
" public:\n");
printer->Print(
"class Service {\n"
" public:\n");
printer->Indent();
printer->Print("Service() : service_(nullptr) {}\n");
printer->Print("virtual ~Service();\n");
@ -229,19 +232,20 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
}
printer->Print("::grpc::RpcService* service();\n");
printer->Outdent();
printer->Print(" private:\n"
" ::grpc::RpcService* service_;\n");
printer->Print(
" private:\n"
" ::grpc::RpcService* service_;\n");
printer->Print("};\n");
printer->Outdent();
printer->Print("};\n");
}
string GetHeaderServices(const google::protobuf::FileDescriptor* file) {
string output;
std::string GetHeaderServices(const google::protobuf::FileDescriptor *file) {
std::string output;
google::protobuf::io::StringOutputStream output_stream(&output);
google::protobuf::io::Printer printer(&output_stream, '$');
map<string, string> vars;
std::map<std::string, std::string> vars;
for (int i = 0; i < file->service_count(); ++i) {
PrintHeaderService(&printer, file->service(i), &vars);
@ -250,9 +254,9 @@ string GetHeaderServices(const google::protobuf::FileDescriptor* file) {
return output;
}
void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
void PrintSourceClientMethod(google::protobuf::io::Printer *printer,
const google::protobuf::MethodDescriptor *method,
std::map<std::string, std::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@ -269,11 +273,12 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
"context, request, response);\n"
"}\n\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(
*vars,
"::grpc::ClientWriter< $Request$>* $Service$::Stub::$Method$("
"::grpc::ClientContext* context, $Response$* response) {\n");
printer->Print(*vars,
"::grpc::ClientWriter<$Request$>* $Service$::Stub::$Method$("
"::grpc::ClientContext* context, $Response$* response) {\n");
printer->Print(*vars,
" return new ::grpc::ClientWriter<$Request$>("
" return new ::grpc::ClientWriter< $Request$>("
"channel()->CreateStream("
"::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", "
"::grpc::RpcMethod::RpcType::CLIENT_STREAMING), "
@ -282,10 +287,10 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
} else if (ServerOnlyStreaming(method)) {
printer->Print(
*vars,
"::grpc::ClientReader<$Response$>* $Service$::Stub::$Method$("
"::grpc::ClientReader< $Response$>* $Service$::Stub::$Method$("
"::grpc::ClientContext* context, const $Request$* request) {\n");
printer->Print(*vars,
" return new ::grpc::ClientReader<$Response$>("
" return new ::grpc::ClientReader< $Response$>("
"channel()->CreateStream("
"::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", "
"::grpc::RpcMethod::RpcType::SERVER_STREAMING), "
@ -294,11 +299,11 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
} else if (BidiStreaming(method)) {
printer->Print(
*vars,
"::grpc::ClientReaderWriter<$Request$, $Response$>* "
"::grpc::ClientReaderWriter< $Request$, $Response$>* "
"$Service$::Stub::$Method$(::grpc::ClientContext* context) {\n");
printer->Print(
*vars,
" return new ::grpc::ClientReaderWriter<$Request$, $Response$>("
" return new ::grpc::ClientReaderWriter< $Request$, $Response$>("
"channel()->CreateStream("
"::grpc::RpcMethod(\"/$Package$$Service$/$Method$\", "
"::grpc::RpcMethod::RpcType::BIDI_STREAMING), "
@ -307,9 +312,9 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
}
}
void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
void PrintSourceServerMethod(google::protobuf::io::Printer *printer,
const google::protobuf::MethodDescriptor *method,
std::map<std::string, std::string> *vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@ -328,7 +333,7 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
printer->Print(*vars,
"::grpc::Status $Service$::Service::$Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerReader<$Request$>* reader, "
"::grpc::ServerReader< $Request$>* reader, "
"$Response$* response) {\n");
printer->Print(
" return ::grpc::Status("
@ -339,7 +344,7 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
"::grpc::Status $Service$::Service::$Method$("
"::grpc::ServerContext* context, "
"const $Request$* request, "
"::grpc::ServerWriter<$Response$>* writer) {\n");
"::grpc::ServerWriter< $Response$>* writer) {\n");
printer->Print(
" return ::grpc::Status("
"::grpc::StatusCode::UNIMPLEMENTED);\n");
@ -348,7 +353,7 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
printer->Print(*vars,
"::grpc::Status $Service$::Service::$Method$("
"::grpc::ServerContext* context, "
"::grpc::ServerReaderWriter<$Response$, $Request$>* "
"::grpc::ServerReaderWriter< $Response$, $Request$>* "
"stream) {\n");
printer->Print(
" return ::grpc::Status("
@ -357,13 +362,14 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
}
}
void PrintSourceService(google::protobuf::io::Printer* printer,
const google::protobuf::ServiceDescriptor* service,
map<string, string>* vars) {
void PrintSourceService(google::protobuf::io::Printer *printer,
const google::protobuf::ServiceDescriptor *service,
std::map<std::string, std::string> *vars) {
(*vars)["Service"] = service->name();
printer->Print(*vars,
printer->Print(
*vars,
"$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"
" stub->set_channel(channel);\n"
" return stub;\n"
@ -380,14 +386,15 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
PrintSourceServerMethod(printer, service->method(i), vars);
}
printer->Print(*vars,
"::grpc::RpcService* $Service$::Service::service() {\n");
"::grpc::RpcService* $Service$::Service::service() {\n");
printer->Indent();
printer->Print("if (service_ != nullptr) {\n"
" return service_;\n"
"}\n");
printer->Print(
"if (service_ != nullptr) {\n"
" return service_;\n"
"}\n");
printer->Print("service_ = new ::grpc::RpcService();\n");
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);
(*vars)["Method"] = method->name();
(*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true);
@ -399,9 +406,9 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
" \"/$Package$$Service$/$Method$\",\n"
" ::grpc::RpcMethod::NORMAL_RPC,\n"
" new ::grpc::RpcMethodHandler<$Service$::Service, $Request$, "
" new ::grpc::RpcMethodHandler< $Service$::Service, $Request$, "
"$Response$>(\n"
" std::function<::grpc::Status($Service$::Service*, "
" std::function< ::grpc::Status($Service$::Service*, "
"::grpc::ServerContext*, const $Request$*, $Response$*)>("
"&$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n");
@ -411,11 +418,11 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
" \"/$Package$$Service$/$Method$\",\n"
" ::grpc::RpcMethod::CLIENT_STREAMING,\n"
" new ::grpc::ClientStreamingHandler<"
" new ::grpc::ClientStreamingHandler< "
"$Service$::Service, $Request$, $Response$>(\n"
" std::function<::grpc::Status($Service$::Service*, "
" std::function< ::grpc::Status($Service$::Service*, "
"::grpc::ServerContext*, "
"::grpc::ServerReader<$Request$>*, $Response$*)>("
"::grpc::ServerReader< $Request$>*, $Response$*)>("
"&$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n");
} else if (ServerOnlyStreaming(method)) {
@ -424,11 +431,11 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
" \"/$Package$$Service$/$Method$\",\n"
" ::grpc::RpcMethod::SERVER_STREAMING,\n"
" new ::grpc::ServerStreamingHandler<"
" new ::grpc::ServerStreamingHandler< "
"$Service$::Service, $Request$, $Response$>(\n"
" std::function<::grpc::Status($Service$::Service*, "
" std::function< ::grpc::Status($Service$::Service*, "
"::grpc::ServerContext*, "
"const $Request$*, ::grpc::ServerWriter<$Response$>*)>("
"const $Request$*, ::grpc::ServerWriter< $Response$>*)>("
"&$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n");
} else if (BidiStreaming(method)) {
@ -437,11 +444,11 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
"service_->AddMethod(new ::grpc::RpcServiceMethod(\n"
" \"/$Package$$Service$/$Method$\",\n"
" ::grpc::RpcMethod::BIDI_STREAMING,\n"
" new ::grpc::BidiStreamingHandler<"
" new ::grpc::BidiStreamingHandler< "
"$Service$::Service, $Request$, $Response$>(\n"
" std::function<::grpc::Status($Service$::Service*, "
" std::function< ::grpc::Status($Service$::Service*, "
"::grpc::ServerContext*, "
"::grpc::ServerReaderWriter<$Response$, $Request$>*)>("
"::grpc::ServerReaderWriter< $Response$, $Request$>*)>("
"&$Service$::Service::$Method$), this),\n"
" new $Request$, new $Response$));\n");
}
@ -451,11 +458,11 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
printer->Print("}\n\n");
}
string GetSourceServices(const google::protobuf::FileDescriptor* file) {
string output;
std::string GetSourceServices(const google::protobuf::FileDescriptor *file) {
std::string output;
google::protobuf::io::StringOutputStream output_stream(&output);
google::protobuf::io::Printer printer(&output_stream, '$');
map<string, string> vars;
std::map<std::string, std::string> vars;
// Package string is empty or ends with a dot. It is used to fully qualify
// method names.
vars["Package"] = file->package();

@ -42,21 +42,19 @@ class FileDescriptor;
} // namespace protobuf
} // namespace google
using namespace std;
namespace grpc_cpp_generator {
// Return the includes needed for generated header file.
string GetHeaderIncludes(const google::protobuf::FileDescriptor* file);
std::string GetHeaderIncludes(const google::protobuf::FileDescriptor *file);
// Return the includes needed for generated source file.
string GetSourceIncludes();
std::string GetSourceIncludes();
// Return the services for generated header file.
string GetHeaderServices(const google::protobuf::FileDescriptor* file);
std::string GetHeaderServices(const google::protobuf::FileDescriptor *file);
// Return the services for generated source file.
string GetSourceServices(const google::protobuf::FileDescriptor* file);
std::string GetSourceServices(const google::protobuf::FileDescriptor *file);
} // namespace grpc_cpp_generator

@ -39,14 +39,12 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
using namespace std;
namespace grpc_cpp_generator {
inline bool StripSuffix(string* filename, const string& suffix) {
inline bool StripSuffix(std::string *filename, const std::string &suffix) {
if (filename->length() >= suffix.length()) {
size_t suffix_pos = filename->length() - suffix.length();
if (filename->compare(suffix_pos, string::npos, suffix) == 0) {
if (filename->compare(suffix_pos, std::string::npos, suffix) == 0) {
filename->resize(filename->size() - suffix.size());
return true;
}
@ -55,19 +53,20 @@ inline bool StripSuffix(string* filename, const string& suffix) {
return false;
}
inline string StripProto(string filename) {
inline std::string StripProto(std::string filename) {
if (!StripSuffix(&filename, ".protodevel")) {
StripSuffix(&filename, ".proto");
}
return filename;
}
inline string StringReplace(string str, const string& from, const string& to) {
inline std::string StringReplace(std::string str, const std::string &from,
const std::string &to) {
size_t pos = 0;
for (;;) {
pos = str.find(from, pos);
if (pos == string::npos) {
if (pos == std::string::npos) {
break;
}
str.replace(pos, from.length(), to);
@ -77,22 +76,23 @@ inline string StringReplace(string str, const string& from, const string& to) {
return str;
}
inline string DotsToColons(const string& name) {
inline std::string DotsToColons(const std::string &name) {
return StringReplace(name, ".", "::");
}
inline string DotsToUnderscores(const string& name) {
inline std::string DotsToUnderscores(const std::string &name) {
return StringReplace(name, ".", "_");
}
inline string ClassName(const google::protobuf::Descriptor* descriptor, bool qualified) {
inline std::string ClassName(const google::protobuf::Descriptor *descriptor,
bool qualified) {
// Find "outer", the descriptor of the top-level message in which
// "descriptor" is embedded.
const google::protobuf::Descriptor* outer = descriptor;
const google::protobuf::Descriptor *outer = descriptor;
while (outer->containing_type() != NULL) outer = outer->containing_type();
const string& outer_name = outer->full_name();
string inner_name = descriptor->full_name().substr(outer_name.size());
const std::string &outer_name = outer->full_name();
std::string inner_name = descriptor->full_name().substr(outer_name.size());
if (qualified) {
return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name);

@ -35,6 +35,8 @@
//
#include <memory>
#include <string>
#include "src/compiler/cpp_generator.h"
#include "src/compiler/cpp_generator_helpers.h"
#include <google/protobuf/descriptor.h>
@ -49,18 +51,19 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
CppGrpcGenerator() {}
virtual ~CppGrpcGenerator() {}
virtual bool Generate(const google::protobuf::FileDescriptor* file,
const string& parameter,
google::protobuf::compiler::GeneratorContext* context,
string* error) const {
virtual bool Generate(const google::protobuf::FileDescriptor *file,
const std::string &parameter,
google::protobuf::compiler::GeneratorContext *context,
std::string *error) const {
if (file->options().cc_generic_services()) {
*error = "cpp grpc proto compiler plugin does not work with generic "
"services. To generate cpp grpc APIs, please set \""
"cc_generic_service = false\".";
*error =
"cpp grpc proto compiler plugin does not work with generic "
"services. To generate cpp grpc APIs, please set \""
"cc_generic_service = false\".";
return false;
}
string file_name = grpc_cpp_generator::StripProto(file->name());
std::string file_name = grpc_cpp_generator::StripProto(file->name());
// Generate .pb.h
Insert(context, file_name + ".pb.h", "includes",
@ -78,9 +81,9 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
private:
// Insert the given code into the given file at the given insertion point.
void Insert(google::protobuf::compiler::GeneratorContext* context,
const string& filename, const string& insertion_point,
const string& code) const {
void Insert(google::protobuf::compiler::GeneratorContext *context,
const std::string &filename, const std::string &insertion_point,
const std::string &code) const {
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
context->OpenForInsert(filename, insertion_point));
google::protobuf::io::CodedOutputStream coded_out(output.get());
@ -88,7 +91,7 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
}
};
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
CppGrpcGenerator generator;
return google::protobuf::compiler::PluginMain(argc, argv, &generator);
}

@ -1,520 +0,0 @@
/*
*
* Copyright 2014, 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.
*
*/
using namespace std;
#include "src/compiler/go_generator.h"
#include <cctype>
#include <google/protobuf/io/printer.h>
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
namespace grpc_go_generator {
bool NoStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() &&
!method->server_streaming();
}
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() &&
!method->server_streaming();
}
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() &&
method->server_streaming();
}
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() &&
method->server_streaming();
}
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) {
for (int i = 0; i < file->service_count(); i++) {
for (int j = 0; j < file->service(i)->method_count(); j++) {
if (ClientOnlyStreaming(file->service(i)->method(j))) {
return true;
}
}
}
return false;
}
string LowerCaseService(const string& service) {
string ret = service;
if (!ret.empty() && ret[0] >= 'A' && ret[0] <= 'Z') {
ret[0] = ret[0] - 'A' + 'a';
}
return ret;
}
void PrintClientMethodDef(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type()->name();
(*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) {
printer->Print(*vars,
"\t$Method$(ctx context.Context, in *$Request$, opts ...rpc.CallOption) "
"(*$Response$, error)\n");
} else if (BidiStreaming(method)) {
printer->Print(*vars,
"\t$Method$(ctx context.Context, opts ...rpc.CallOption) "
"($Service$_$Method$Client, error)\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(*vars,
"\t$Method$(ctx context.Context, m *$Request$, opts ...rpc.CallOption) "
"($Service$_$Method$Client, error)\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(*vars,
"\t$Method$(ctx context.Context, opts ...rpc.CallOption) "
"($Service$_$Method$Client, error)\n");
}
}
void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type()->name();
(*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) {
printer->Print(*vars,
"func (c *$ServiceStruct$Client) $Method$(ctx context.Context, "
"in *$Request$, opts ...rpc.CallOption) (*$Response$, error) {\n");
printer->Print(*vars,
"\tout := new($Response$)\n");
printer->Print(*vars,
"\terr := rpc.Invoke(ctx, \"/$Package$$Service$/$Method$\", "
"in, out, c.cc, opts...)\n");
printer->Print("\tif err != nil {\n");
printer->Print("\t\treturn nil, err\n");
printer->Print("\t}\n");
printer->Print("\treturn out, nil\n");
printer->Print("}\n\n");
} else if (BidiStreaming(method)) {
printer->Print(
*vars,
"func (c *$ServiceStruct$Client) $Method$(ctx context.Context, opts "
"...rpc.CallOption) ($Service$_$Method$Client, error) {\n"
"\tstream, err := rpc.NewClientStream(ctx, c.cc, "
"\"/$Package$$Service$/$Method$\", opts...)\n"
"\tif err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\treturn &$ServiceStruct$$Method$Client{stream}, nil\n"
"}\n\n");
printer->Print(*vars,
"type $Service$_$Method$Client interface {\n"
"\tSend(*$Request$) error\n"
"\tRecv() (*$Response$, error)\n"
"\trpc.ClientStream\n"
"}\n\n");
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"
"\treturn x.ClientStream.SendProto(m)\n"
"}\n\n");
printer->Print(*vars,
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) "
"{\n"
"\tm := new($Response$)\n"
"\tif err := x.ClientStream.RecvProto(m); err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\treturn m, nil\n"
"}\n\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(
*vars,
"func (c *$ServiceStruct$Client) $Method$(ctx context.Context, m "
"*$Request$, "
"opts ...rpc.CallOption) ($Service$_$Method$Client, error) {\n"
"\tstream, err := rpc.NewClientStream(ctx, c.cc, "
"\"/$Package$$Service$/$Method$\", opts...)\n"
"\tif err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\tx := &$ServiceStruct$$Method$Client{stream}\n"
"\tif err := x.ClientStream.SendProto(m); err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\tif err := x.ClientStream.CloseSend(); err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\treturn x, nil\n"
"}\n\n");
printer->Print(*vars,
"type $Service$_$Method$Client interface {\n"
"\tRecv() (*$Response$, error)\n"
"\trpc.ClientStream\n"
"}\n\n");
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) "
"{\n"
"\tm := new($Response$)\n"
"\tif err := x.ClientStream.RecvProto(m); err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\treturn m, nil\n"
"}\n\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(
*vars,
"func (c *$ServiceStruct$Client) $Method$(ctx context.Context, opts "
"...rpc.CallOption) ($Service$_$Method$Client, error) {\n"
"\tstream, err := rpc.NewClientStream(ctx, c.cc, "
"\"/$Package$$Service$/$Method$\", opts...)\n"
"\tif err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\treturn &$ServiceStruct$$Method$Client{stream}, nil\n"
"}\n\n");
printer->Print(*vars,
"type $Service$_$Method$Client interface {\n"
"\tSend(*$Request$) error\n"
"\tCloseAndRecv() (*$Response$, error)\n"
"\trpc.ClientStream\n"
"}\n\n");
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"
"\treturn x.ClientStream.SendProto(m)\n"
"}\n\n");
printer->Print(*vars,
"func (x *$ServiceStruct$$Method$Client) CloseAndRecv() (*$Response$, "
"error) {\n"
"\tif err := x.ClientStream.CloseSend(); err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\tm := new($Response$)\n"
"\tif err := x.ClientStream.RecvProto(m); err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\t// Read EOF.\n"
"\tif err := x.ClientStream.RecvProto(m); err == io.EOF {\n"
"\t\treturn m, io.EOF\n"
"\t}\n"
"\t// gRPC protocol violation.\n"
"\treturn m, fmt.Errorf(\"Violate gRPC client streaming protocol: no "
"EOF after the response.\")\n"
"}\n\n");
}
}
void PrintClient(google::protobuf::io::Printer* printer,
const google::protobuf::ServiceDescriptor* service,
map<string, string>* vars) {
(*vars)["Service"] = service->name();
(*vars)["ServiceStruct"] = LowerCaseService(service->name());
printer->Print(*vars, "type $Service$Client interface {\n");
for (int i = 0; i < service->method_count(); ++i) {
PrintClientMethodDef(printer, service->method(i), vars);
}
printer->Print("}\n\n");
printer->Print(*vars,
"type $ServiceStruct$Client struct {\n"
"\tcc *rpc.ClientConn\n"
"}\n\n");
printer->Print(*vars,
"func New$Service$Client(cc *rpc.ClientConn) $Service$Client {\n"
"\treturn &$ServiceStruct$Client{cc}\n"
"}\n\n");
for (int i = 0; i < service->method_count(); ++i) {
PrintClientMethodImpl(printer, service->method(i), vars);
}
}
void PrintServerMethodDef(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type()->name();
(*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) {
printer->Print(*vars,
"\t$Method$(context.Context, *$Request$) (*$Response$, error)\n");
} else if (BidiStreaming(method)) {
printer->Print(*vars,
"\t$Method$($Service$_$Method$Server) error\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(*vars,
"\t$Method$(*$Request$, $Service$_$Method$Server) error\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(*vars,
"\t$Method$($Service$_$Method$Server) error\n");
}
}
void PrintServerHandler(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
(*vars)["Method"] = method->name();
(*vars)["Request"] = method->input_type()->name();
(*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) {
printer->Print(*vars,
"func _$Service$_$Method$_Handler(srv interface{}, ctx context.Context,"
" buf []byte) (proto.Message, error) {\n");
printer->Print(*vars,
"\tin := new($Request$)\n");
printer->Print("\tif err := proto.Unmarshal(buf, in); err != nil {\n");
printer->Print("\t\treturn nil, err\n");
printer->Print("\t}\n");
printer->Print(*vars,
"\tout, err := srv.($Service$Server).$Method$(ctx, in)\n");
printer->Print("\tif err != nil {\n");
printer->Print("\t\treturn nil, err\n");
printer->Print("\t}\n");
printer->Print("\treturn out, nil\n");
printer->Print("}\n\n");
} else if (BidiStreaming(method)) {
printer->Print(*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n"
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server"
"{stream})\n"
"}\n\n");
printer->Print(*vars,
"type $Service$_$Method$Server interface {\n"
"\tSend(*$Response$) error\n"
"\tRecv() (*$Request$, error)\n"
"\trpc.Stream\n"
"}\n\n");
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"
"\treturn x.Stream.SendProto(m)\n"
"}\n\n");
printer->Print(*vars,
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) "
"{\n"
"\tm := new($Request$)\n"
"\tif err := x.Stream.RecvProto(m); err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\treturn m, nil\n"
"}\n\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n"
"\tm := new($Request$)\n"
"\tif err := stream.RecvProto(m); err != nil {\n"
"\t\treturn err\n"
"\t}\n"
"\treturn srv.($Service$Server).$Method$(m, "
"&$ServiceStruct$$Method$Server{stream})\n"
"}\n\n");
printer->Print(*vars,
"type $Service$_$Method$Server interface {\n"
"\tSend(*$Response$) error\n"
"\trpc.Stream\n"
"}\n\n");
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"
"\treturn x.Stream.SendProto(m)\n"
"}\n\n");
} else if (ClientOnlyStreaming(method)) {
printer->Print(*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n"
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server"
"{stream})\n"
"}\n\n");
printer->Print(*vars,
"type $Service$_$Method$Server interface {\n"
"\tSendAndClose(*$Response$) error\n"
"\tRecv() (*$Request$, error)\n"
"\trpc.Stream\n"
"}\n\n");
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$) "
"error {\n"
"\tif err := x.Stream.SendProto(m); err != nil {\n"
"\t\treturn err\n"
"\t}\n"
"\treturn nil\n"
"}\n\n");
printer->Print(*vars,
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) {\n"
"\tm := new($Request$)\n"
"\tif err := x.Stream.RecvProto(m); err != nil {\n"
"\t\treturn nil, err\n"
"\t}\n"
"\treturn m, nil\n"
"}\n\n");
}
}
void PrintServerMethodDesc(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
(*vars)["Method"] = method->name();
printer->Print("\t\t{\n");
printer->Print(*vars,
"\t\t\tMethodName:\t\"$Method$\",\n");
printer->Print(*vars,
"\t\t\tHandler:\t_$Service$_$Method$_Handler,\n");
printer->Print("\t\t},\n");
}
void PrintServerStreamingMethodDesc(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) {
(*vars)["Method"] = method->name();
printer->Print("\t\t{\n");
printer->Print(*vars,
"\t\t\tStreamName:\t\"$Method$\",\n");
printer->Print(*vars,
"\t\t\tHandler:\t_$Service$_$Method$_Handler,\n");
printer->Print("\t\t},\n");
}
void PrintServer(google::protobuf::io::Printer* printer,
const google::protobuf::ServiceDescriptor* service,
map<string, string>* vars) {
(*vars)["Service"] = service->name();
printer->Print(*vars, "type $Service$Server interface {\n");
for (int i = 0; i < service->method_count(); ++i) {
PrintServerMethodDef(printer, service->method(i), vars);
}
printer->Print("}\n\n");
printer->Print(*vars,
"func RegisterService(s *rpc.Server, srv $Service$Server) {\n"
"\ts.RegisterService(&_$Service$_serviceDesc, srv)\n"
"}\n\n");
for (int i = 0; i < service->method_count(); ++i) {
PrintServerHandler(printer, service->method(i), vars);
}
printer->Print(*vars,
"var _$Service$_serviceDesc = rpc.ServiceDesc{\n"
"\tServiceName: \"$Package$$Service$\",\n"
"\tHandlerType: (*$Service$Server)(nil),\n"
"\tMethods: []rpc.MethodDesc{\n");
for (int i = 0; i < service->method_count(); ++i) {
if (NoStreaming(service->method(i))) {
PrintServerMethodDesc(printer, service->method(i), vars);
}
}
printer->Print("\t},\n");
printer->Print("\tStreams: []rpc.StreamDesc{\n");
for (int i = 0; i < service->method_count(); ++i) {
if (!NoStreaming(service->method(i))) {
PrintServerStreamingMethodDesc(printer, service->method(i), vars);
}
}
printer->Print("\t},\n"
"}\n\n");
}
std::string BadToUnderscore(std::string str) {
for (unsigned i = 0; i < str.size(); ++i) {
if (!std::isalnum(str[i])) {
str[i] = '_';
}
}
return str;
}
string GetServices(const google::protobuf::FileDescriptor* file) {
string output;
google::protobuf::io::StringOutputStream output_stream(&output);
google::protobuf::io::Printer printer(&output_stream, '$');
map<string, string> vars;
string package_name = !file->options().go_package().empty()
? file->options().go_package()
: file->package();
vars["PackageName"] = BadToUnderscore(package_name);
printer.Print(vars, "package $PackageName$\n\n");
printer.Print("import (\n");
if (HasClientOnlyStreaming(file)) {
printer.Print("\t\"fmt\"\n"
"\t\"io\"\n");
}
printer.Print(
"\t\"google/net/grpc/go/rpc\"\n"
"\tcontext \"google/third_party/golang/go_net/context/context\"\n"
"\tproto \"google/net/proto2/go/proto\"\n"
")\n\n");
// $Package$ is used to fully qualify method names.
vars["Package"] = file->package();
if (!file->package().empty()) {
vars["Package"].append(".");
}
for (int i = 0; i < file->service_count(); ++i) {
PrintClient(&printer, file->service(0), &vars);
printer.Print("\n");
PrintServer(&printer, file->service(0), &vars);
printer.Print("\n");
}
return output;
}
} // namespace grpc_go_generator

@ -1,83 +0,0 @@
/*
*
* Copyright 2014, 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.
*
*/
// Generates go gRPC service interface out of Protobuf IDL.
//
// This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto
// and net/proto2/compiler/public/plugin.h for more information on plugins.
#include <fstream>
#include <memory>
using namespace std;
#include "src/compiler/go_generator.h"
#include <google/protobuf/compiler/code_generator.h>
#include <google/protobuf/compiler/plugin.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream.h>
#include <google/protobuf/descriptor.h>
class GoGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
public:
GoGrpcGenerator() {}
virtual ~GoGrpcGenerator() {}
virtual bool Generate(const google::protobuf::FileDescriptor* file,
const string& parameter,
google::protobuf::compiler::GeneratorContext* context,
string* error) const {
// Get output file name.
string file_name;
if (file->name().size() > 6 &&
file->name().find_last_of(".proto") == file->name().size() - 1) {
file_name = file->name().substr(0, file->name().size() - 6) +
"_grpc.pb.go";
} else {
*error = "Invalid proto file name. Proto file must end with .proto";
return false;
}
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
context->Open(file_name));
google::protobuf::io::CodedOutputStream coded_out(output.get());
string code = grpc_go_generator::GetServices(file);
coded_out.WriteRaw(code.data(), code.size());
return true;
}
};
int main(int argc, char* argv[]) {
GoGrpcGenerator generator;
return google::protobuf::compiler::PluginMain(argc, argv, &generator);
}

@ -32,6 +32,7 @@
*/
#include <cctype>
#include <string>
#include <map>
#include <vector>
@ -56,41 +57,40 @@ namespace grpc_ruby_generator {
namespace {
// Prints out the method using the ruby gRPC DSL.
void PrintMethod(const MethodDescriptor* method, const string& package,
Printer* out) {
string input_type = RubyTypeOf(method->input_type()->name(), package);
void PrintMethod(const MethodDescriptor *method, const std::string &package,
Printer *out) {
std::string input_type = RubyTypeOf(method->input_type()->name(), package);
if (method->client_streaming()) {
input_type = "stream(" + input_type + ")";
}
string output_type = RubyTypeOf(method->output_type()->name(), package);
std::string output_type = RubyTypeOf(method->output_type()->name(), package);
if (method->server_streaming()) {
output_type = "stream(" + output_type + ")";
}
map<string, string> method_vars = ListToDict({
"mth.name", method->name(),
"input.type", input_type,
"output.type", output_type,
std::map<std::string, std::string> method_vars = ListToDict({
"mth.name", method->name(), "input.type", input_type, "output.type",
output_type,
});
out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n");
}
// Prints out the service using the ruby gRPC DSL.
void PrintService(const ServiceDescriptor* service, const string& package,
Printer* out) {
void PrintService(const ServiceDescriptor *service, const std::string &package,
Printer *out) {
if (service->method_count() == 0) {
return;
}
// Begin the service module
map<string, string> module_vars = ListToDict({
std::map<std::string, std::string> module_vars = ListToDict({
"module.name", CapitalizeFirst(service->name()),
});
out->Print(module_vars, "module $module.name$\n");
out->Indent();
// TODO(temiola): add documentation
string doc = "TODO: add proto service documentation here";
map<string, string> template_vars = ListToDict({
std::string doc = "TODO: add proto service documentation here";
std::map<std::string, std::string> template_vars = ListToDict({
"Documentation", doc,
});
out->Print("\n");
@ -104,9 +104,8 @@ void PrintService(const ServiceDescriptor* service, const string& package,
out->Print("\n");
out->Print("self.marshal_class_method = :encode\n");
out->Print("self.unmarshal_class_method = :decode\n");
map<string, string> pkg_vars = ListToDict({
"service.name", service->name(),
"pkg.name", package,
std::map<std::string, std::string> pkg_vars = ListToDict({
"service.name", service->name(), "pkg.name", package,
});
out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n");
out->Print("\n");
@ -126,8 +125,8 @@ void PrintService(const ServiceDescriptor* service, const string& package,
} // namespace
string GetServices(const FileDescriptor* file) {
string output;
std::string GetServices(const FileDescriptor *file) {
std::string output;
StringOutputStream output_stream(&output);
Printer out(&output_stream, '$');
@ -138,10 +137,9 @@ string GetServices(const FileDescriptor* file) {
}
// Write out a file header.
map<string, string> header_comment_vars = ListToDict({
"file.name", file->name(),
"file.package", file->package(),
});
std::map<std::string, std::string> header_comment_vars = ListToDict({
"file.name", file->name(), "file.package", file->package(),
});
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
out.Print(header_comment_vars,
"# Source: $file.name$ for package '$file.package$'\n");
@ -151,16 +149,16 @@ string GetServices(const FileDescriptor* file) {
// Write out require statemment to import the separately generated file
// that defines the messages used by the service. This is generated by the
// main ruby plugin.
map<string, string> dep_vars = ListToDict({
std::map<std::string, std::string> dep_vars = ListToDict({
"dep.name", MessagesRequireName(file),
});
out.Print(dep_vars, "require '$dep.name$'\n");
// Write out services within the modules
out.Print("\n");
vector<string> modules = Split(file->package(), '.');
std::vector<std::string> modules = Split(file->package(), '.');
for (size_t i = 0; i < modules.size(); ++i) {
map<string, string> module_vars = ListToDict({
std::map<std::string, std::string> module_vars = ListToDict({
"module.name", CapitalizeFirst(modules[i]),
});
out.Print(module_vars, "module $module.name$\n");

@ -36,8 +36,6 @@
#include <string>
using namespace std;
namespace google {
namespace protobuf {
class FileDescriptor;
@ -46,7 +44,7 @@ class FileDescriptor;
namespace grpc_ruby_generator {
string GetServices(const google::protobuf::FileDescriptor* file);
std::string GetServices(const google::protobuf::FileDescriptor *file);
} // namespace grpc_ruby_generator

@ -41,14 +41,15 @@
namespace grpc_ruby_generator {
inline bool ServicesFilename(const google::protobuf::FileDescriptor* file,
string* file_name_or_error) {
inline bool ServicesFilename(const google::protobuf::FileDescriptor *file,
std::string *file_name_or_error) {
// Get output file name.
static const unsigned proto_suffix_length = 6; // length of ".proto"
if (file->name().size() > proto_suffix_length &&
file->name().find_last_of(".proto") == file->name().size() - 1) {
*file_name_or_error = file->name().substr(
0, file->name().size() - proto_suffix_length) + "_services.rb";
*file_name_or_error =
file->name().substr(0, file->name().size() - proto_suffix_length) +
"_services.rb";
return true;
} else {
*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 std::string MessagesRequireName(
const google::protobuf::FileDescriptor *file) {
return Replace(file->name(), ".proto", "");
}

@ -40,7 +40,6 @@
#include <string>
#include <vector>
using std::initializer_list;
using std::map;
using std::vector;
@ -49,16 +48,18 @@ namespace grpc_ruby_generator {
// Converts an initializer list of the form { key0, value0, key1, value1, ... }
// 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 std::map<std::string, std::string> ListToDict(
const initializer_list<std::string> &values) {
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;
std::map<std::string, std::string> value_map;
auto value_iter = values.begin();
for (unsigned i = 0; i < values.size()/2; ++i) {
string key = *value_iter;
for (unsigned i = 0; i < values.size() / 2; ++i) {
std::string key = *value_iter;
++value_iter;
string value = *value_iter;
std::string value = *value_iter;
value_map[key] = value;
++value_iter;
}

@ -45,10 +45,10 @@ using std::transform;
namespace grpc_ruby_generator {
// Split splits a string using char into elems.
inline vector<string> &Split(const string &s, char delim,
vector<string>* elems) {
stringstream ss(s);
string item;
inline std::vector<std::string> &Split(const std::string &s, char delim,
std::vector<std::string> *elems) {
std::stringstream ss(s);
std::string item;
while (getline(ss, item, delim)) {
elems->push_back(item);
}
@ -56,16 +56,17 @@ inline vector<string> &Split(const string &s, char delim,
}
// Split splits a string using char, returning the result in a vector.
inline vector<string> Split(const string &s, char delim) {
vector<string> elems;
inline std::vector<std::string> Split(const std::string &s, char delim) {
std::vector<std::string> elems;
Split(s, delim, &elems);
return elems;
}
// Replace replaces from with to in s.
inline string Replace(string s, const string& from, const string& to) {
inline std::string Replace(std::string s, const std::string &from,
const std::string &to) {
size_t start_pos = s.find(from);
if (start_pos == string::npos) {
if (start_pos == std::string::npos) {
return s;
}
s.replace(start_pos, from.length(), to);
@ -73,10 +74,10 @@ inline string Replace(string s, const string& from, const string& to) {
}
// ReplaceAll replaces all instances of search with replace in s.
inline string ReplaceAll(string s, const string& search,
const string& replace) {
inline std::string ReplaceAll(std::string s, const std::string &search,
const std::string &replace) {
size_t pos = 0;
while ((pos = s.find(search, pos)) != string::npos) {
while ((pos = s.find(search, pos)) != std::string::npos) {
s.replace(pos, search.length(), replace);
pos += replace.length();
}
@ -84,9 +85,10 @@ inline string ReplaceAll(string s, const string& search,
}
// ReplacePrefix replaces from with to in s if search is a prefix of s.
inline bool ReplacePrefix(string* s, const string& from, const string& to) {
inline bool ReplacePrefix(std::string *s, const std::string &from,
const std::string &to) {
size_t start_pos = s->find(from);
if (start_pos == string::npos || start_pos != 0) {
if (start_pos == std::string::npos || start_pos != 0) {
return false;
}
s->replace(start_pos, from.length(), to);
@ -94,7 +96,7 @@ inline bool ReplacePrefix(string* s, const string& from, const string& to) {
}
// CapitalizeFirst capitalizes the first char in a string.
inline string CapitalizeFirst(string s) {
inline std::string CapitalizeFirst(std::string s) {
if (s.empty()) {
return s;
}
@ -103,14 +105,15 @@ inline string CapitalizeFirst(string s) {
}
// RubyTypeOf updates a proto type to the required ruby equivalent.
inline string RubyTypeOf(const string& a_type, const string& package) {
string res(a_type);
inline std::string RubyTypeOf(const std::string &a_type,
const std::string &package) {
std::string res(a_type);
ReplacePrefix(&res, package, ""); // remove the leading package if present
ReplacePrefix(&res, ".", ""); // remove the leading . (no package)
if (res.find('.') == string::npos) {
ReplacePrefix(&res, ".", ""); // remove the leading . (no package)
if (res.find('.') == std::string::npos) {
return res;
} else {
vector<string> prefixes_and_type = Split(res, '.');
std::vector<std::string> prefixes_and_type = Split(res, '.');
for (unsigned int i = 0; i < prefixes_and_type.size(); ++i) {
if (i != 0) {
res += "::"; // switch '.' to the ruby module delim

@ -37,6 +37,7 @@
// and net/proto2/compiler/public/plugin.h for more information on plugins.
#include <memory>
#include <string>
#include "src/compiler/ruby_generator.h"
#include "src/compiler/ruby_generator_helpers-inl.h"
@ -51,17 +52,17 @@ class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
RubyGrpcGenerator() {}
~RubyGrpcGenerator() override {}
bool Generate(const google::protobuf::FileDescriptor* file,
const string& parameter,
google::protobuf::compiler::GeneratorContext* context,
string* error) const override {
string code = grpc_ruby_generator::GetServices(file);
bool Generate(const google::protobuf::FileDescriptor *file,
const std::string &parameter,
google::protobuf::compiler::GeneratorContext *context,
std::string *error) const override {
std::string code = grpc_ruby_generator::GetServices(file);
if (code.size() == 0) {
return true; // don't generate a file if there are no services
}
// Get output file name.
string file_name;
std::string file_name;
if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) {
return false;
}
@ -73,7 +74,7 @@ class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
}
};
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
RubyGrpcGenerator generator;
return google::protobuf::compiler::PluginMain(argc, argv, &generator);
}

@ -178,19 +178,19 @@ static void destroy_channel_elem(grpc_channel_element* elem) {
}
const grpc_channel_filter grpc_client_census_filter = {
client_call_op, channel_op,
client_call_op, channel_op,
sizeof(call_data), client_init_call_elem, client_destroy_call_elem,
sizeof(call_data), client_init_call_elem, client_destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"census-client"};
const grpc_channel_filter grpc_server_census_filter = {
server_call_op, channel_op,
server_call_op, channel_op,
sizeof(call_data), server_init_call_elem, server_destroy_call_elem,
sizeof(call_data), server_init_call_elem, server_destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"census-server"};

@ -51,4 +51,4 @@ void grpc_channel_args_destroy(grpc_channel_args *a);
is specified in channel args, otherwise returns 0. */
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__ */

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

@ -165,9 +165,9 @@ static void lb_destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_child_channel_top_filter = {
lb_call_op, lb_channel_op,
lb_call_op, lb_channel_op,
sizeof(lb_call_data), lb_init_call_elem, lb_destroy_call_elem,
sizeof(lb_call_data), lb_init_call_elem, lb_destroy_call_elem,
sizeof(lb_channel_data), lb_init_channel_elem, lb_destroy_channel_elem,

@ -39,7 +39,7 @@
/* helper for filters that need to host child channel stacks... handles
lifetime and upwards propagation cleanly */
const grpc_channel_filter grpc_child_channel_top_filter;
extern const grpc_channel_filter grpc_child_channel_top_filter;
typedef grpc_channel_stack grpc_child_channel;
typedef grpc_call_stack grpc_child_call;

@ -450,9 +450,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_client_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,

@ -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_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);
#endif /* __GRPC_INTERNAL_CHANNEL_CLIENT_SETUP_H__ */
#endif /* __GRPC_INTERNAL_CHANNEL_CLIENT_SETUP_H__ */

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

@ -32,6 +32,7 @@
*/
#include "src/core/channel/http_client_filter.h"
#include <string.h>
#include <grpc/support/log.h>
typedef struct call_data { int sent_headers; } call_data;
@ -130,6 +131,19 @@ static void destroy_call_elem(grpc_call_element *elem) {
ignore_unused(channeld);
}
static const char *scheme_from_args(const grpc_channel_args *args) {
int i;
if (args != NULL) {
for (i = 0; i < args->num_args; ++i) {
if (args->args[i].type == GRPC_ARG_STRING &&
strcmp(args->args[i].key, GRPC_ARG_HTTP2_SCHEME) == 0) {
return args->args[i].value.string;
}
}
}
return "http";
}
/* Constructor for channel_data */
static void init_channel_elem(grpc_channel_element *elem,
const grpc_channel_args *args, grpc_mdctx *mdctx,
@ -146,7 +160,8 @@ static void init_channel_elem(grpc_channel_element *elem,
/* initialize members */
channeld->te_trailers = grpc_mdelem_from_strings(mdctx, "te", "trailers");
channeld->method = grpc_mdelem_from_strings(mdctx, ":method", "POST");
channeld->scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "grpc");
channeld->scheme =
grpc_mdelem_from_strings(mdctx, ":scheme", scheme_from_args(args));
channeld->content_type =
grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc");
}
@ -163,9 +178,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_http_client_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,

@ -39,4 +39,6 @@
/* Processes metadata on the client side for HTTP2 transports */
extern const grpc_channel_filter grpc_http_client_filter;
#define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme"
#endif /* __GRPC_INTERNAL_CHANNEL_HTTP_CLIENT_FILTER_H__ */

@ -132,9 +132,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_http_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,

@ -244,9 +244,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_http_server_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,

@ -67,4 +67,4 @@ grpc_metadata *grpc_metadata_buffer_extract_elements(
grpc_metadata_buffer *buffer);
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__ */

@ -41,4 +41,4 @@
customize for their own filters */
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(
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,
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,
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,
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 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_eof(grpc_httpcli_parser *parser);
#endif /* __GRPC_INTERNAL_HTTPCLI_PARSER_H__ */
#endif /* __GRPC_INTERNAL_HTTPCLI_PARSER_H__ */

@ -100,7 +100,7 @@ void grpc_alarm_list_init(gpr_timespec now) {
}
}
void grpc_alarm_list_shutdown() {
void grpc_alarm_list_shutdown(void) {
int i;
while (run_some_expired_alarms(NULL, gpr_inf_future, NULL, 0))
;
@ -360,7 +360,7 @@ int grpc_alarm_check(gpr_mu *drop_mu, gpr_timespec now, gpr_timespec *next) {
return run_some_expired_alarms(drop_mu, now, next, 1);
}
gpr_timespec grpc_alarm_list_next_timeout() {
gpr_timespec grpc_alarm_list_next_timeout(void) {
gpr_timespec out;
gpr_mu_lock(&g_mu);
out = g_shard_queue[0]->min_deadline;

@ -42,12 +42,12 @@
int grpc_alarm_check(gpr_mu *drop_mu, gpr_timespec now, gpr_timespec *next);
void grpc_alarm_list_init(gpr_timespec now);
void grpc_alarm_list_shutdown();
void grpc_alarm_list_shutdown(void);
gpr_timespec grpc_alarm_list_next_timeout();
gpr_timespec grpc_alarm_list_next_timeout(void);
/* the following must be implemented by each iomgr implementation */
void grpc_kick_poller();
void grpc_kick_poller(void);
#endif /* __GRPC_INTERNAL_IOMGR_ALARM_INTERNAL_H_ */

@ -80,9 +80,9 @@ static void background_callback_executor(void *ignored) {
gpr_event_set(&g_background_callback_executor_done, (void *)1);
}
void grpc_kick_poller() { gpr_cv_broadcast(&g_cv); }
void grpc_kick_poller(void) { gpr_cv_broadcast(&g_cv); }
void grpc_iomgr_init() {
void grpc_iomgr_init(void) {
gpr_thd_id id;
gpr_mu_init(&g_mu);
gpr_cv_init(&g_cv);
@ -93,7 +93,7 @@ void grpc_iomgr_init() {
gpr_thd_new(&id, background_callback_executor, NULL, NULL);
}
void grpc_iomgr_shutdown() {
void grpc_iomgr_shutdown(void) {
delayed_callback *cb;
gpr_timespec shutdown_deadline =
gpr_time_add(gpr_now(), gpr_time_from_seconds(10));
@ -134,13 +134,13 @@ void grpc_iomgr_shutdown() {
gpr_cv_destroy(&g_cv);
}
void grpc_iomgr_ref() {
void grpc_iomgr_ref(void) {
gpr_mu_lock(&g_mu);
++g_refs;
gpr_mu_unlock(&g_mu);
}
void grpc_iomgr_unref() {
void grpc_iomgr_unref(void) {
gpr_mu_lock(&g_mu);
if (0 == --g_refs) {
gpr_cv_signal(&g_cv);

@ -37,8 +37,8 @@
/* gRPC Callback definition */
typedef void (*grpc_iomgr_cb_func)(void *arg, int success);
void grpc_iomgr_init();
void grpc_iomgr_shutdown();
void grpc_iomgr_init(void);
void grpc_iomgr_shutdown(void);
/* This function is called from within a callback or from anywhere else
and causes the invocation of a callback at some point in the future */

@ -42,10 +42,10 @@ int grpc_maybe_call_delayed_callbacks(gpr_mu *drop_mu, int success);
void grpc_iomgr_add_delayed_callback(grpc_iomgr_cb_func cb, void *cb_arg,
int success);
void grpc_iomgr_ref();
void grpc_iomgr_unref();
void grpc_iomgr_ref(void);
void grpc_iomgr_unref(void);
void grpc_iomgr_platform_init();
void grpc_iomgr_platform_shutdown();
void grpc_iomgr_platform_init(void);
void grpc_iomgr_platform_shutdown(void);
#endif /* __GRPC_INTERNAL_IOMGR_IOMGR_INTERNAL_H_ */

@ -33,6 +33,6 @@
#include "src/core/iomgr/iomgr_posix.h"
void grpc_iomgr_platform_init() { grpc_pollset_global_init(); }
void grpc_iomgr_platform_init(void) { grpc_pollset_global_init(); }
void grpc_iomgr_platform_shutdown() { grpc_pollset_global_shutdown(); }
void grpc_iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); }

@ -36,7 +36,7 @@
#include "src/core/iomgr/iomgr_internal.h"
void grpc_pollset_global_init();
void grpc_pollset_global_shutdown();
void grpc_pollset_global_init(void);
void grpc_pollset_global_shutdown(void);
#endif /* __GRPC_INTERNAL_IOMGR_IOMGR_POSIX_H_ */

@ -0,0 +1,68 @@
/*
*
* 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_IOMGR_POLLSET_KICK_H_
#define __GRPC_INTERNAL_IOMGR_POLLSET_KICK_H_
#include <grpc/support/port_platform.h>
/* This is an abstraction around the typical pipe mechanism for waking up a
thread sitting in a poll() style call. */
#ifdef GPR_POSIX_SOCKET
#include "src/core/iomgr/pollset_kick_posix.h"
#else
#error "No pollset kick support on platform"
#endif
void grpc_pollset_kick_global_init(void);
void grpc_pollset_kick_global_destroy(void);
void grpc_pollset_kick_init(grpc_pollset_kick_state *kick_state);
void grpc_pollset_kick_destroy(grpc_pollset_kick_state *kick_state);
/* Must be called before entering poll(). If return value is -1, this consumed
an existing kick. Otherwise the return value is an FD to add to the poll set.
*/
int grpc_pollset_kick_pre_poll(grpc_pollset_kick_state *kick_state);
/* Consume an existing kick. Must be called after poll returns that the fd was
readable, and before calling kick_post_poll. */
void grpc_pollset_kick_consume(grpc_pollset_kick_state *kick_state);
/* Must be called after pre_poll, and after consume if applicable */
void grpc_pollset_kick_post_poll(grpc_pollset_kick_state *kick_state);
void grpc_pollset_kick_kick(grpc_pollset_kick_state *kick_state);
#endif /* __GRPC_INTERNAL_IOMGR_POLLSET_KICK_H_ */

@ -0,0 +1,161 @@
/*
*
* 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.
*
*/
#include "src/core/iomgr/pollset_kick_posix.h"
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "src/core/iomgr/socket_utils_posix.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
/* This implementation is based on a freelist of pipes. */
typedef struct grpc_kick_pipe_info {
int pipe_read_fd;
int pipe_write_fd;
struct grpc_kick_pipe_info *next;
} grpc_kick_pipe_info;
static grpc_kick_pipe_info *pipe_freelist = NULL;
static gpr_mu pipe_freelist_mu;
static grpc_kick_pipe_info *allocate_pipe() {
grpc_kick_pipe_info *info;
gpr_mu_lock(&pipe_freelist_mu);
if (pipe_freelist != NULL) {
info = pipe_freelist;
pipe_freelist = pipe_freelist->next;
} else {
int pipefd[2];
/* TODO(klempner): Make this nonfatal */
GPR_ASSERT(0 == pipe(pipefd));
GPR_ASSERT(grpc_set_socket_nonblocking(pipefd[0], 1));
GPR_ASSERT(grpc_set_socket_nonblocking(pipefd[1], 1));
info = gpr_malloc(sizeof(*info));
info->pipe_read_fd = pipefd[0];
info->pipe_write_fd = pipefd[1];
info->next = NULL;
}
gpr_mu_unlock(&pipe_freelist_mu);
return info;
}
static void free_pipe(grpc_kick_pipe_info *pipe_info) {
/* TODO(klempner): Start closing pipes if the free list gets too large */
gpr_mu_lock(&pipe_freelist_mu);
pipe_info->next = pipe_freelist;
pipe_freelist = pipe_info;
gpr_mu_unlock(&pipe_freelist_mu);
}
void grpc_pollset_kick_global_init() {
pipe_freelist = NULL;
gpr_mu_init(&pipe_freelist_mu);
}
void grpc_pollset_kick_global_destroy() {
while (pipe_freelist != NULL) {
grpc_kick_pipe_info *current = pipe_freelist;
pipe_freelist = pipe_freelist->next;
close(current->pipe_read_fd);
close(current->pipe_write_fd);
gpr_free(current);
}
gpr_mu_destroy(&pipe_freelist_mu);
}
void grpc_pollset_kick_init(grpc_pollset_kick_state *kick_state) {
gpr_mu_init(&kick_state->mu);
kick_state->kicked = 0;
kick_state->pipe_info = NULL;
}
void grpc_pollset_kick_destroy(grpc_pollset_kick_state *kick_state) {
gpr_mu_destroy(&kick_state->mu);
GPR_ASSERT(kick_state->pipe_info == NULL);
}
int grpc_pollset_kick_pre_poll(grpc_pollset_kick_state *kick_state) {
gpr_mu_lock(&kick_state->mu);
if (kick_state->kicked) {
kick_state->kicked = 0;
gpr_mu_unlock(&kick_state->mu);
return -1;
}
kick_state->pipe_info = allocate_pipe();
gpr_mu_unlock(&kick_state->mu);
return kick_state->pipe_info->pipe_read_fd;
}
void grpc_pollset_kick_consume(grpc_pollset_kick_state *kick_state) {
char buf[128];
int r;
for (;;) {
r = read(kick_state->pipe_info->pipe_read_fd, buf, sizeof(buf));
if (r > 0) continue;
if (r == 0) return;
switch (errno) {
case EAGAIN:
return;
case EINTR:
continue;
default:
gpr_log(GPR_ERROR, "error reading pipe: %s", strerror(errno));
return;
}
}
}
void grpc_pollset_kick_post_poll(grpc_pollset_kick_state *kick_state) {
gpr_mu_lock(&kick_state->mu);
free_pipe(kick_state->pipe_info);
kick_state->pipe_info = NULL;
gpr_mu_unlock(&kick_state->mu);
}
void grpc_pollset_kick_kick(grpc_pollset_kick_state *kick_state) {
gpr_mu_lock(&kick_state->mu);
if (kick_state->pipe_info != NULL) {
char c = 0;
while (write(kick_state->pipe_info->pipe_write_fd, &c, 1) != 1 &&
errno == EINTR)
;
} else {
kick_state->kicked = 1;
}
gpr_mu_unlock(&kick_state->mu);
}

@ -0,0 +1,47 @@
/*
*
* 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_IOMGR_POLLSET_KICK_POSIX_H_
#define __GRPC_INTERNAL_IOMGR_POLLSET_KICK_POSIX_H_
#include <grpc/support/sync.h>
struct grpc_kick_pipe_info;
typedef struct grpc_pollset_kick_state {
gpr_mu mu;
int kicked;
struct grpc_kick_pipe_info *pipe_info;
} grpc_pollset_kick_state;
#endif /* __GRPC_INTERNAL_IOMGR_POLLSET_KICK_POSIX_H_ */

@ -131,7 +131,11 @@ static int multipoll_with_poll_pollset_maybe_work(
}
nf = 0;
np = 1;
h->pfds[0].fd = grpc_kick_read_fd(pollset);
h->pfds[0].fd = grpc_pollset_kick_pre_poll(&pollset->kick_state);
if (h->pfds[0].fd < 0) {
/* Already kicked */
return 1;
}
h->pfds[0].events = POLLIN;
h->pfds[0].revents = POLLOUT;
for (i = 0; i < h->fd_count; i++) {
@ -173,7 +177,7 @@ static int multipoll_with_poll_pollset_maybe_work(
/* do nothing */
} else {
if (h->pfds[0].revents & POLLIN) {
grpc_kick_drain(pollset);
grpc_pollset_kick_consume(&pollset->kick_state);
}
for (i = 1; i < np; i++) {
if (h->pfds[i].revents & POLLIN) {
@ -184,6 +188,7 @@ static int multipoll_with_poll_pollset_maybe_work(
}
}
}
grpc_pollset_kick_post_poll(&pollset->kick_state);
end_polling(pollset);
gpr_mu_lock(&pollset->mu);

@ -48,18 +48,6 @@
#include <grpc/support/thd.h>
#include <grpc/support/useful.h>
/* kick pipes: we keep a sharded set of pipes to allow breaking from poll.
Ideally this would be 1:1 with pollsets, but we'd like to avoid associating
full kernel objects with each pollset to keep them lightweight, so instead
keep a sharded set and allow associating a pollset with one of the shards.
TODO(ctiller): move this out from this file, and allow an eventfd
implementation on linux */
#define LOG2_KICK_SHARDS 6
#define KICK_SHARDS (1 << LOG2_KICK_SHARDS)
static int g_kick_pipes[KICK_SHARDS][2];
static grpc_pollset g_backup_pollset;
static int g_shutdown_backup_poller;
static gpr_event g_backup_poller_done;
@ -82,65 +70,22 @@ static void backup_poller(void *p) {
gpr_event_set(&g_backup_poller_done, (void *)1);
}
static size_t kick_shard(const grpc_pollset *info) {
size_t x = (size_t)info;
return ((x >> 4) ^ (x >> 9) ^ (x >> 14)) & (KICK_SHARDS - 1);
}
int grpc_kick_read_fd(grpc_pollset *p) {
return g_kick_pipes[kick_shard(p)][0];
}
static int grpc_kick_write_fd(grpc_pollset *p) {
return g_kick_pipes[kick_shard(p)][1];
}
void grpc_pollset_force_kick(grpc_pollset *p) {
char c = 0;
while (write(grpc_kick_write_fd(p), &c, 1) != 1 && errno == EINTR)
;
}
void grpc_pollset_kick(grpc_pollset *p) {
if (!p->counter) return;
grpc_pollset_force_kick(p);
grpc_pollset_kick_kick(&p->kick_state);
}
void grpc_kick_drain(grpc_pollset *p) {
int fd = grpc_kick_read_fd(p);
char buf[128];
int r;
for (;;) {
r = read(fd, buf, sizeof(buf));
if (r > 0) continue;
if (r == 0) return;
switch (errno) {
case EAGAIN:
return;
case EINTR:
continue;
default:
gpr_log(GPR_ERROR, "error reading pipe: %s", strerror(errno));
return;
}
}
}
void grpc_pollset_force_kick(grpc_pollset *p) { grpc_pollset_kick(p); }
/* global state management */
grpc_pollset *grpc_backup_pollset() { return &g_backup_pollset; }
grpc_pollset *grpc_backup_pollset(void) { return &g_backup_pollset; }
void grpc_pollset_global_init() {
int i;
void grpc_pollset_global_init(void) {
gpr_thd_id id;
/* initialize the kick shards */
for (i = 0; i < KICK_SHARDS; i++) {
GPR_ASSERT(0 == pipe(g_kick_pipes[i]));
GPR_ASSERT(grpc_set_socket_nonblocking(g_kick_pipes[i][0], 1));
GPR_ASSERT(grpc_set_socket_nonblocking(g_kick_pipes[i][1], 1));
}
/* Initialize kick fd state */
grpc_pollset_kick_global_init();
/* initialize the backup pollset */
grpc_pollset_init(&g_backup_pollset);
@ -151,9 +96,7 @@ void grpc_pollset_global_init() {
gpr_thd_new(&id, backup_poller, NULL, NULL);
}
void grpc_pollset_global_shutdown() {
int i;
void grpc_pollset_global_shutdown(void) {
/* terminate the backup poller thread */
gpr_mu_lock(&g_backup_pollset.mu);
g_shutdown_backup_poller = 1;
@ -163,11 +106,8 @@ void grpc_pollset_global_shutdown() {
/* destroy the backup pollset */
grpc_pollset_destroy(&g_backup_pollset);
/* destroy the kick shards */
for (i = 0; i < KICK_SHARDS; i++) {
close(g_kick_pipes[i][0]);
close(g_kick_pipes[i][1]);
}
/* destroy the kick pipes */
grpc_pollset_kick_global_destroy();
}
/* main interface */
@ -178,6 +118,7 @@ static void become_unary_pollset(grpc_pollset *pollset, grpc_fd *fd);
void grpc_pollset_init(grpc_pollset *pollset) {
gpr_mu_init(&pollset->mu);
gpr_cv_init(&pollset->cv);
grpc_pollset_kick_init(&pollset->kick_state);
become_empty_pollset(pollset);
}
@ -213,6 +154,7 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) {
void grpc_pollset_destroy(grpc_pollset *pollset) {
pollset->vtable->destroy(pollset);
grpc_pollset_kick_destroy(&pollset->kick_state);
gpr_mu_destroy(&pollset->mu);
gpr_cv_destroy(&pollset->cv);
}
@ -290,7 +232,11 @@ static int unary_poll_pollset_maybe_work(grpc_pollset *pollset,
return 1;
}
}
pfd[0].fd = grpc_kick_read_fd(pollset);
pfd[0].fd = grpc_pollset_kick_pre_poll(&pollset->kick_state);
if (pfd[0].fd < 0) {
/* Already kicked */
return 1;
}
pfd[0].events = POLLIN;
pfd[0].revents = 0;
pfd[1].fd = fd->fd;
@ -308,7 +254,7 @@ static int unary_poll_pollset_maybe_work(grpc_pollset *pollset,
/* do nothing */
} else {
if (pfd[0].revents & POLLIN) {
grpc_kick_drain(pollset);
grpc_pollset_kick_consume(&pollset->kick_state);
}
if (pfd[1].revents & POLLIN) {
grpc_fd_become_readable(fd, allow_synchronous_callback);
@ -318,6 +264,8 @@ static int unary_poll_pollset_maybe_work(grpc_pollset *pollset,
}
}
grpc_pollset_kick_post_poll(&pollset->kick_state);
gpr_mu_lock(&pollset->mu);
grpc_fd_end_poll(fd, pollset);
pollset->counter = 0;

@ -36,6 +36,8 @@
#include <grpc/support/sync.h>
#include "src/core/iomgr/pollset_kick.h"
typedef struct grpc_pollset_vtable grpc_pollset_vtable;
/* forward declare only in this file to avoid leaking impl details via
@ -51,6 +53,7 @@ typedef struct grpc_pollset {
const grpc_pollset_vtable *vtable;
gpr_mu mu;
gpr_cv cv;
grpc_pollset_kick_state kick_state;
int counter;
union {
int fd;
@ -86,7 +89,7 @@ void grpc_kick_drain(grpc_pollset *p);
regardless of applications listening to events. Relying on this is slow
however (the backup pollset only listens every 100ms or so) - so it's not
to be relied on. */
grpc_pollset *grpc_backup_pollset();
grpc_pollset *grpc_backup_pollset(void);
/* turn a pollset into a multipoller: platform specific */
void grpc_platform_become_multipoller(grpc_pollset *pollset,

@ -115,7 +115,7 @@ int grpc_set_socket_low_latency(int fd, int low_latency) {
static gpr_once g_probe_ipv6_once = GPR_ONCE_INIT;
static int g_ipv6_loopback_available;
static void probe_ipv6_once() {
static void probe_ipv6_once(void) {
int fd = socket(AF_INET6, SOCK_STREAM, 0);
g_ipv6_loopback_available = 0;
if (fd < 0) {
@ -135,7 +135,7 @@ static void probe_ipv6_once() {
}
}
int grpc_ipv6_loopback_available() {
int grpc_ipv6_loopback_available(void) {
gpr_once_init(&g_probe_ipv6_once, probe_ipv6_once);
return g_ipv6_loopback_available;
}

@ -61,7 +61,7 @@ int grpc_set_socket_low_latency(int fd, int low_latency);
and bind IPv6 sockets, but cannot connect to a getsockname() of [::]:port
without a valid loopback interface. Rather than expose this half-broken
state to library users, we turn off IPv6 sockets. */
int grpc_ipv6_loopback_available();
int grpc_ipv6_loopback_available(void);
/* An enum to keep track of IPv4/IPv6 socket modes.

@ -46,7 +46,7 @@ typedef struct grpc_tcp_server grpc_tcp_server;
typedef void (*grpc_tcp_server_cb)(void *arg, grpc_endpoint *ep);
/* Create a server, initially not bound to any ports */
grpc_tcp_server *grpc_tcp_server_create();
grpc_tcp_server *grpc_tcp_server_create(void);
/* Start listening to bound ports */
void grpc_tcp_server_start(grpc_tcp_server *server, grpc_pollset *pollset,

@ -84,7 +84,7 @@ struct grpc_tcp_server {
size_t port_capacity;
};
grpc_tcp_server *grpc_tcp_server_create() {
grpc_tcp_server *grpc_tcp_server_create(void) {
grpc_tcp_server *s = gpr_malloc(sizeof(grpc_tcp_server));
gpr_mu_init(&s->mu);
gpr_cv_init(&s->cv);
@ -120,7 +120,7 @@ void grpc_tcp_server_destroy(grpc_tcp_server *s) {
}
/* get max listen queue size on linux */
static void init_max_accept_queue_size() {
static void init_max_accept_queue_size(void) {
int n = SOMAXCONN;
char buf[64];
FILE *fp = fopen("/proc/sys/net/core/somaxconn", "r");
@ -147,7 +147,7 @@ static void init_max_accept_queue_size() {
}
}
static int get_max_accept_queue_size() {
static int get_max_accept_queue_size(void) {
gpr_once_init(&s_init_max_accept_queue_size, init_max_accept_queue_size);
return s_max_accept_queue_size;
}

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

@ -637,8 +637,8 @@ grpc_credentials *grpc_fake_transport_security_credentials_create(void) {
return c;
}
grpc_server_credentials *
grpc_fake_transport_security_server_credentials_create() {
grpc_server_credentials *grpc_fake_transport_security_server_credentials_create(
void) {
grpc_server_credentials *c = gpr_malloc(sizeof(grpc_server_credentials));
memset(c, 0, sizeof(grpc_server_credentials));
c->type = GRPC_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY;

@ -143,4 +143,4 @@ struct grpc_server_credentials {
const grpc_ssl_config *grpc_ssl_server_credentials_get_config(
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 int grpc_google_root_certs_size;
#endif /* __GRPC_INTERNAL_SECURITY_GOOGLE_ROOT_CERTS_H__ */
#endif /* __GRPC_INTERNAL_SECURITY_GOOGLE_ROOT_CERTS_H__ */

@ -126,8 +126,8 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices,
size_t message_size = GPR_SLICE_LENGTH(encrypted);
while (message_size > 0 || keep_looping) {
gpr_uint32 unprotected_buffer_size_written = end - cur;
gpr_uint32 processed_message_size = message_size;
size_t unprotected_buffer_size_written = end - cur;
size_t processed_message_size = message_size;
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_unprotect(ep->protector, message_bytes,
&processed_message_size, cur,
@ -245,8 +245,8 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
gpr_uint8 *message_bytes = GPR_SLICE_START_PTR(plain);
size_t message_size = GPR_SLICE_LENGTH(plain);
while (message_size > 0) {
gpr_uint32 protected_buffer_size_to_send = end - cur;
gpr_uint32 processed_message_size = message_size;
size_t protected_buffer_size_to_send = end - cur;
size_t processed_message_size = message_size;
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_protect(ep->protector, message_bytes,
&processed_message_size, cur,
@ -268,9 +268,9 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
if (result != TSI_OK) break;
}
if (result == TSI_OK) {
gpr_uint32 still_pending_size;
size_t still_pending_size;
do {
gpr_uint32 protected_buffer_size_to_send = end - cur;
size_t protected_buffer_size_to_send = end - cur;
gpr_mu_lock(&ep->protector_mu);
result = tsi_frame_protector_protect_flush(ep->protector, cur,
&protected_buffer_size_to_send,

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

@ -131,7 +131,7 @@ static void send_handshake_bytes_to_peer(grpc_secure_transport_setup *s) {
grpc_endpoint_write_status write_status;
do {
uint32_t to_send_size = s->handshake_buffer_size - offset;
size_t to_send_size = s->handshake_buffer_size - offset;
result = tsi_handshaker_get_bytes_to_send_to_peer(
s->handshaker, s->handshake_buffer + offset, &to_send_size);
offset += to_send_size;
@ -174,7 +174,7 @@ static void on_handshake_data_received_from_peer(
void *setup, gpr_slice *slices, size_t nslices,
grpc_endpoint_cb_status error) {
grpc_secure_transport_setup *s = setup;
uint32_t consumed_slice_size = 0;
size_t consumed_slice_size = 0;
tsi_result result = TSI_OK;
size_t i;
size_t num_left_overs;

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

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

Loading…
Cancel
Save