Merge github.com:google/grpc into mac

pull/11/head
Craig Tiller 10 years ago
commit c5dcb6af74
  1. 65
      .clang-format
  2. 6
      .gitignore
  3. 638
      Makefile
  4. 15
      build.json
  5. 4
      include/grpc++/channel_interface.h
  6. 1
      include/grpc++/config.h
  7. 1
      include/grpc++/credentials.h
  8. 16
      include/grpc++/impl/rpc_service_method.h
  9. 1
      include/grpc++/status_code_enum.h
  10. 1
      include/grpc/status.h
  11. 21
      src/compiler/cpp_generator.cc
  12. 3
      src/compiler/cpp_generator_helpers.h
  13. 3
      src/compiler/cpp_plugin.cc
  14. 106
      src/compiler/go_generator.cc
  15. 2
      src/compiler/go_generator.h
  16. 4
      src/compiler/go_plugin.cc
  17. 11
      src/compiler/ruby_generator.cc
  18. 8
      src/compiler/ruby_generator_helpers-inl.h
  19. 4
      src/compiler/ruby_generator_map-inl.h
  20. 3
      src/core/channel/channel_stack.c
  21. 1
      src/core/iomgr/pollset.h
  22. 5
      src/core/security/auth.c
  23. 13
      src/core/security/security_context.c
  24. 3
      src/core/security/server_secure_chttp2.c
  25. 4
      src/core/support/alloc.c
  26. 3
      src/core/surface/client.c
  27. 1
      src/core/transport/chttp2/frame_data.c
  28. 18
      src/core/tsi/fake_transport_security.c
  29. 1
      src/core/tsi/fake_transport_security.h
  30. 54
      src/core/tsi/ssl_transport_security.c
  31. 1
      src/core/tsi/ssl_transport_security.h
  32. 23
      src/core/tsi/transport_security.c
  33. 21
      src/core/tsi/transport_security_interface.h
  34. 4
      src/cpp/client/channel.cc
  35. 4
      src/cpp/client/channel.h
  36. 2
      src/cpp/client/credentials.cc
  37. 6
      src/cpp/proto/proto_utils.cc
  38. 3
      src/cpp/proto/proto_utils.h
  39. 3
      src/cpp/server/async_server_context.cc
  40. 4
      src/cpp/server/server_context_impl.cc
  41. 1
      src/cpp/server/server_credentials.cc
  42. 12
      src/cpp/server/server_rpc_handler.cc
  43. 3
      src/cpp/stream/stream_context.cc
  44. 3
      src/cpp/stream/stream_context.h
  45. 1
      src/cpp/util/status.cc
  46. 3
      src/php/ext/grpc/byte_buffer.c
  47. 3
      src/php/ext/grpc/byte_buffer.h
  48. 195
      src/php/ext/grpc/call.c
  49. 1
      src/php/ext/grpc/call.h
  50. 47
      src/php/ext/grpc/channel.c
  51. 32
      src/php/ext/grpc/completion_queue.c
  52. 44
      src/php/ext/grpc/credentials.c
  53. 49
      src/php/ext/grpc/event.c
  54. 128
      src/php/ext/grpc/php_grpc.c
  55. 7
      src/php/ext/grpc/php_grpc.h
  56. 53
      src/php/ext/grpc/server.c
  57. 30
      src/php/ext/grpc/server_credentials.c
  58. 87
      src/php/ext/grpc/timeval.c
  59. 3
      src/ruby/bin/interop/interop_client.rb
  60. 4
      src/ruby/bin/interop/interop_server.rb
  61. 5
      src/ruby/bin/math_client.rb
  62. 4
      src/ruby/bin/math_server.rb
  63. 3
      src/ruby/bin/noproto_client.rb
  64. 3
      src/ruby/bin/noproto_server.rb
  65. 6
      src/ruby/ext/grpc/rb_byte_buffer.c
  66. 18
      src/ruby/ext/grpc/rb_call.c
  67. 3
      src/ruby/ext/grpc/rb_channel_args.c
  68. 1
      src/ruby/ext/grpc/rb_channel_args.h
  69. 37
      src/ruby/ext/grpc/rb_completion_queue.c
  70. 20
      src/ruby/ext/grpc/rb_credentials.c
  71. 57
      src/ruby/ext/grpc/rb_event.c
  72. 39
      src/ruby/ext/grpc/rb_grpc.c
  73. 5
      src/ruby/ext/grpc/rb_metadata.c
  74. 4
      src/ruby/ext/grpc/rb_server.c
  75. 13
      src/ruby/ext/grpc/rb_server_credentials.c
  76. 24
      templates/Makefile.template
  77. 3
      test/core/end2end/data/prod_roots_certs.c
  78. 1
      test/core/end2end/dualstack_socket_test.c
  79. 6
      test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c
  80. 1
      test/core/end2end/tests/cancel_after_accept.c
  81. 5
      test/core/end2end/tests/no_op.c
  82. 1
      test/core/end2end/tests/request_response_with_metadata_and_payload.c
  83. 1
      test/core/httpcli/format_request_test.c
  84. 4
      test/core/surface/completion_queue_benchmark.c
  85. 4
      test/core/surface/completion_queue_test.c
  86. 8
      test/core/util/port.h
  87. 12
      test/cpp/client/channel_arguments_test.cc
  88. 2
      test/cpp/client/credentials_test.cc
  89. 12
      test/cpp/end2end/end2end_test.cc
  90. 9
      test/cpp/end2end/sync_client_async_server_test.cc
  91. 1
      test/cpp/interop/client.cc
  92. 48
      test/cpp/qps/client.cc
  93. 158
      test/cpp/qps/qpstest.proto
  94. 24
      test/cpp/qps/server.cc
  95. 1
      test/cpp/util/status_test.cc
  96. 1
      test/cpp/util/time_test.cc
  97. 8
      tools/clang-format/clang-format-all.sh
  98. 50
      tools/run_tests/jobset.py
  99. 65
      tools/run_tests/run_tests.py

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

6
.gitignore vendored

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

File diff suppressed because one or more lines are too long

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

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

@ -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 {

@ -34,7 +34,6 @@
#ifndef __GRPC_STATUS_H__
#define __GRPC_STATUS_H__
#ifdef __cplusplus
extern "C" {
#endif

@ -43,13 +43,11 @@ namespace grpc_cpp_generator {
namespace {
bool NoStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() &&
!method->server_streaming();
return !method->client_streaming() && !method->server_streaming();
}
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() &&
!method->server_streaming();
return method->client_streaming() && !method->server_streaming();
}
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
@ -57,8 +55,7 @@ bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
}
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() &&
method->server_streaming();
return method->client_streaming() && method->server_streaming();
}
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) {
@ -204,7 +201,8 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
printer->Indent();
// Client side
printer->Print("class Stub : public ::grpc::InternalStub {\n"
printer->Print(
"class Stub : public ::grpc::InternalStub {\n"
" public:\n");
printer->Indent();
for (int i = 0; i < service->method_count(); ++i) {
@ -219,7 +217,8 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
printer->Print("\n");
// Server side
printer->Print("class Service {\n"
printer->Print(
"class Service {\n"
" public:\n");
printer->Indent();
printer->Print("Service() : service_(nullptr) {}\n");
@ -229,7 +228,8 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
}
printer->Print("::grpc::RpcService* service();\n");
printer->Outdent();
printer->Print(" private:\n"
printer->Print(
" private:\n"
" ::grpc::RpcService* service_;\n");
printer->Print("};\n");
@ -382,7 +382,8 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
printer->Print(*vars,
"::grpc::RpcService* $Service$::Service::service() {\n");
printer->Indent();
printer->Print("if (service_ != nullptr) {\n"
printer->Print(
"if (service_ != nullptr) {\n"
" return service_;\n"
"}\n");
printer->Print("service_ = new ::grpc::RpcService();\n");

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

@ -54,7 +54,8 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
google::protobuf::compiler::GeneratorContext* context,
string* error) const {
if (file->options().cc_generic_services()) {
*error = "cpp grpc proto compiler plugin does not work with generic "
*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;

@ -31,8 +31,6 @@
*
*/
using namespace std;
#include "src/compiler/go_generator.h"
#include <cctype>
@ -42,26 +40,24 @@ using namespace std;
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/descriptor.h>
using namespace std;
namespace grpc_go_generator {
bool NoStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() &&
!method->server_streaming();
return !method->client_streaming() && !method->server_streaming();
}
bool ClientOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() &&
!method->server_streaming();
return method->client_streaming() && !method->server_streaming();
}
bool ServerOnlyStreaming(const google::protobuf::MethodDescriptor* method) {
return !method->client_streaming() &&
method->server_streaming();
return !method->client_streaming() && method->server_streaming();
}
bool BidiStreaming(const google::protobuf::MethodDescriptor* method) {
return method->client_streaming() &&
method->server_streaming();
return method->client_streaming() && method->server_streaming();
}
bool HasClientOnlyStreaming(const google::protobuf::FileDescriptor* file) {
@ -91,14 +87,16 @@ void PrintClientMethodDef(google::protobuf::io::Printer* printer,
(*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) {
printer->Print(*vars,
"\t$Method$(ctx context.Context, in *$Request$, opts ...rpc.CallOption) "
"\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,
printer->Print(
*vars,
"\t$Method$(ctx context.Context, m *$Request$, opts ...rpc.CallOption) "
"($Service$_$Method$Client, error)\n");
} else if (ClientOnlyStreaming(method)) {
@ -116,11 +114,11 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
(*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) {
printer->Print(*vars,
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, "\tout := new($Response$)\n");
printer->Print(*vars,
"\terr := rpc.Invoke(ctx, \"/$Package$$Service$/$Method$\", "
"in, out, c.cc, opts...)\n");
@ -151,11 +149,13 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n"
"\treturn x.ClientStream.SendProto(m)\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) "
"{\n"
"\tm := new($Response$)\n"
@ -193,7 +193,8 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) Recv() (*$Response$, error) "
"{\n"
"\tm := new($Response$)\n"
@ -224,11 +225,13 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
"type $ServiceStruct$$Method$Client struct {\n"
"\trpc.ClientStream\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) Send(m *$Request$) error {\n"
"\treturn x.ClientStream.SendProto(m)\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Client) CloseAndRecv() (*$Response$, "
"error) {\n"
"\tif err := x.ClientStream.CloseSend(); err != nil {\n"
@ -264,7 +267,8 @@ void PrintClient(google::protobuf::io::Printer* printer,
"type $ServiceStruct$Client struct {\n"
"\tcc *rpc.ClientConn\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func New$Service$Client(cc *rpc.ClientConn) $Service$Client {\n"
"\treturn &$ServiceStruct$Client{cc}\n"
"}\n\n");
@ -280,17 +284,16 @@ void PrintServerMethodDef(google::protobuf::io::Printer* printer,
(*vars)["Request"] = method->input_type()->name();
(*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) {
printer->Print(*vars,
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");
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");
printer->Print(*vars, "\t$Method$($Service$_$Method$Server) error\n");
}
}
@ -301,11 +304,11 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
(*vars)["Request"] = method->input_type()->name();
(*vars)["Response"] = method->output_type()->name();
if (NoStreaming(method)) {
printer->Print(*vars,
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(*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");
@ -317,7 +320,8 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
printer->Print("\treturn out, nil\n");
printer->Print("}\n\n");
} else if (BidiStreaming(method)) {
printer->Print(*vars,
printer->Print(
*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n"
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server"
@ -333,11 +337,13 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Server) Send(m *$Response$) error {\n"
"\treturn x.Stream.SendProto(m)\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Server) Recv() (*$Request$, error) "
"{\n"
"\tm := new($Request$)\n"
@ -347,7 +353,8 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
"\treturn m, nil\n"
"}\n\n");
} else if (ServerOnlyStreaming(method)) {
printer->Print(*vars,
printer->Print(
*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n"
"\tm := new($Request$)\n"
@ -366,12 +373,14 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(*vars,
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,
printer->Print(
*vars,
"func _$Service$_$Method$_Handler(srv interface{}, stream rpc.Stream) "
"error {\n"
"\treturn srv.($Service$Server).$Method$(&$ServiceStruct$$Method$Server"
@ -387,7 +396,8 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
"type $ServiceStruct$$Method$Server struct {\n"
"\trpc.Stream\n"
"}\n\n");
printer->Print(*vars,
printer->Print(
*vars,
"func (x *$ServiceStruct$$Method$Server) SendAndClose(m *$Response$) "
"error {\n"
"\tif err := x.Stream.SendProto(m); err != nil {\n"
@ -395,7 +405,8 @@ void PrintServerHandler(google::protobuf::io::Printer* printer,
"\t}\n"
"\treturn nil\n"
"}\n\n");
printer->Print(*vars,
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"
@ -411,22 +422,19 @@ void PrintServerMethodDesc(google::protobuf::io::Printer* printer,
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(*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,
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(*vars, "\t\t\tStreamName:\t\"$Method$\",\n");
printer->Print(*vars, "\t\t\tHandler:\t_$Service$_$Method$_Handler,\n");
printer->Print("\t\t},\n");
}
@ -467,7 +475,8 @@ void PrintServer(google::protobuf::io::Printer* printer,
PrintServerStreamingMethodDesc(printer, service->method(i), vars);
}
}
printer->Print("\t},\n"
printer->Print(
"\t},\n"
"}\n\n");
}
@ -493,7 +502,8 @@ string GetServices(const google::protobuf::FileDescriptor* file) {
printer.Print(vars, "package $PackageName$\n\n");
printer.Print("import (\n");
if (HasClientOnlyStreaming(file)) {
printer.Print("\t\"fmt\"\n"
printer.Print(
"\t\"fmt\"\n"
"\t\"io\"\n");
}
printer.Print(

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

@ -61,8 +61,8 @@ class GoGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
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";
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;

@ -67,9 +67,8 @@ void PrintMethod(const MethodDescriptor* method, const string& package,
output_type = "stream(" + output_type + ")";
}
map<string, string> method_vars = ListToDict({
"mth.name", method->name(),
"input.type", input_type,
"output.type", output_type,
"mth.name", method->name(), "input.type", input_type, "output.type",
output_type,
});
out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n");
}
@ -105,8 +104,7 @@ void PrintService(const ServiceDescriptor* service, const string& package,
out->Print("self.marshal_class_method = :encode\n");
out->Print("self.unmarshal_class_method = :decode\n");
map<string, string> pkg_vars = ListToDict({
"service.name", service->name(),
"pkg.name", package,
"service.name", service->name(), "pkg.name", package,
});
out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n");
out->Print("\n");
@ -139,8 +137,7 @@ 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(),
"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,

@ -47,8 +47,9 @@ inline bool ServicesFilename(const google::protobuf::FileDescriptor* file,
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 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;
@ -51,7 +50,8 @@ namespace grpc_ruby_generator {
// 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) {
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;
auto value_iter = values.begin();

@ -190,8 +190,7 @@ void grpc_channel_next_op(grpc_channel_element *elem, grpc_channel_op *op) {
grpc_channel_stack *grpc_channel_stack_from_top_element(
grpc_channel_element *elem) {
return (grpc_channel_stack *)((char *)(elem) -
ROUND_UP_TO_ALIGNMENT_SIZE(
return (grpc_channel_stack *)((char *)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE(
sizeof(grpc_channel_stack)));
}

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

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

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

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

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

@ -106,8 +106,7 @@ static void init_channel_elem(grpc_channel_element *elem,
GPR_ASSERT(!is_last);
}
static void destroy_channel_elem(grpc_channel_element *elem) {
}
static void destroy_channel_elem(grpc_channel_element *elem) {}
const grpc_channel_filter grpc_client_surface_filter = {
call_op, channel_op,

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

@ -83,7 +83,6 @@ typedef struct {
uint32_t max_frame_size;
} tsi_fake_frame_protector;
/* --- Utils. ---*/
static const char* tsi_fake_handshake_message_strings[] = {
@ -246,8 +245,8 @@ static tsi_result fake_protector_protect(
/* Try to drain first. */
if (frame->needs_draining) {
drained_size = saved_output_size - *num_bytes_written;
result = drain_frame_to_bytes(protected_output_frames,
&drained_size, frame);
result =
drain_frame_to_bytes(protected_output_frames, &drained_size, frame);
*num_bytes_written += drained_size;
protected_output_frames += drained_size;
if (result != TSI_OK) {
@ -273,8 +272,8 @@ static tsi_result fake_protector_protect(
return result;
}
}
result = fill_frame_from_bytes(unprotected_bytes, unprotected_bytes_size,
frame);
result =
fill_frame_from_bytes(unprotected_bytes, unprotected_bytes_size, frame);
if (result != TSI_OK) {
if (result == TSI_INCOMPLETE_DATA) result = TSI_OK;
return result;
@ -327,8 +326,7 @@ static tsi_result fake_protector_unprotect(
/* Go past the header if needed. */
if (frame->offset == 0) frame->offset = TSI_FAKE_FRAME_HEADER_SIZE;
drained_size = saved_output_size - *num_bytes_written;
result = drain_frame_to_bytes(unprotected_bytes, &drained_size,
frame);
result = drain_frame_to_bytes(unprotected_bytes, &drained_size, frame);
unprotected_bytes += drained_size;
*num_bytes_written += drained_size;
if (result != TSI_OK) {
@ -481,10 +479,8 @@ static void fake_handshaker_destroy(tsi_handshaker* self) {
static const tsi_handshaker_vtable handshaker_vtable = {
fake_handshaker_get_bytes_to_send_to_peer,
fake_handshaker_process_bytes_from_peer,
fake_handshaker_get_result,
fake_handshaker_extract_peer,
fake_handshaker_create_frame_protector,
fake_handshaker_process_bytes_from_peer, fake_handshaker_get_result,
fake_handshaker_extract_peer, fake_handshaker_create_frame_protector,
fake_handshaker_destroy,
};

@ -50,7 +50,6 @@ extern "C" {
cleartext data for the protector. */
tsi_handshaker* tsi_create_fake_handshaker(int is_client);
/* Creates a protector directly without going through the handshake phase. */
tsi_frame_protector* tsi_create_fake_protector(
uint32_t* max_protected_frame_size);

@ -54,7 +54,6 @@
* SSL structure. This is what we would ultimately want though... */
#define TSI_SSL_MAX_PROTECTION_OVERHEAD 100
/* --- Structure definitions. ---*/
struct tsi_ssl_handshaker_factory {
@ -100,7 +99,6 @@ typedef struct {
uint32_t buffer_offset;
} tsi_ssl_frame_protector;
/* --- Library Initialization. ---*/
static gpr_once init_openssl_once = GPR_ONCE_INIT;
@ -299,12 +297,10 @@ static void log_ssl_error_stack(void) {
}
}
/* Performs an SSL_read and handle errors. */
static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes,
uint32_t* unprotected_bytes_size) {
int read_from_ssl = SSL_read(ssl, unprotected_bytes,
*unprotected_bytes_size);
int read_from_ssl = SSL_read(ssl, unprotected_bytes, *unprotected_bytes_size);
if (read_from_ssl == 0) {
gpr_log(GPR_ERROR, "SSL_read returned 0 unexpectedly.");
return TSI_INTERNAL_ERROR;
@ -423,8 +419,8 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX* context,
/* Loads in-memory PEM verification certs into the SSL context and optionally
returns the verification cert names (root_names can be NULL). */
static tsi_result ssl_ctx_load_verification_certs(
SSL_CTX* context, const unsigned char* pem_roots,
uint32_t pem_roots_size, STACK_OF(X509_NAME)** root_names) {
SSL_CTX* context, const unsigned char* pem_roots, uint32_t pem_roots_size,
STACK_OF(X509_NAME) * *root_names) {
tsi_result result = TSI_OK;
uint32_t num_roots = 0;
X509* root = NULL;
@ -485,13 +481,11 @@ static tsi_result ssl_ctx_load_verification_certs(
return result;
}
/* Populates the SSL context with a private key and a cert chain, and sets the
cipher list and the ephemeral ECDH key. */
static tsi_result populate_ssl_context(
SSL_CTX* context, const unsigned char* pem_private_key,
uint32_t pem_private_key_size,
const unsigned char* pem_certificate_chain,
uint32_t pem_private_key_size, const unsigned char* pem_certificate_chain,
uint32_t pem_certificate_chain_size, const char* cipher_list) {
tsi_result result = TSI_OK;
if (pem_certificate_chain != NULL) {
@ -581,8 +575,7 @@ static tsi_result build_alpn_protocol_name_list(
static tsi_result ssl_protector_protect(
tsi_frame_protector* self, const unsigned char* unprotected_bytes,
uint32_t* unprotected_bytes_size,
unsigned char* protected_output_frames,
uint32_t* unprotected_bytes_size, unsigned char* protected_output_frames,
uint32_t* protected_output_frames_size) {
tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self;
int read_from_ssl;
@ -634,8 +627,7 @@ static tsi_result ssl_protector_protect(
static tsi_result ssl_protector_protect_flush(
tsi_frame_protector* self, unsigned char* protected_output_frames,
uint32_t* protected_output_frames_size,
uint32_t* still_pending_size) {
uint32_t* protected_output_frames_size, uint32_t* still_pending_size) {
tsi_result result = TSI_OK;
tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self;
int read_from_ssl = 0;
@ -662,8 +654,7 @@ static tsi_result ssl_protector_protect_flush(
static tsi_result ssl_protector_unprotect(
tsi_frame_protector* self, const unsigned char* protected_frames_bytes,
uint32_t* protected_frames_bytes_size,
unsigned char* unprotected_bytes,
uint32_t* protected_frames_bytes_size, unsigned char* unprotected_bytes,
uint32_t* unprotected_bytes_size) {
tsi_result result = TSI_OK;
int written_into_ssl = 0;
@ -684,8 +675,8 @@ static tsi_result ssl_protector_unprotect(
*unprotected_bytes_size = output_bytes_size - output_bytes_offset;
/* Then, try to write some data to ssl. */
written_into_ssl = BIO_write(
impl->into_ssl, protected_frames_bytes, *protected_frames_bytes_size);
written_into_ssl = BIO_write(impl->into_ssl, protected_frames_bytes,
*protected_frames_bytes_size);
if (written_into_ssl < 0) {
gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d",
written_into_ssl);
@ -710,13 +701,10 @@ static void ssl_protector_destroy(tsi_frame_protector* self) {
}
static const tsi_frame_protector_vtable frame_protector_vtable = {
ssl_protector_protect,
ssl_protector_protect_flush,
ssl_protector_unprotect,
ssl_protector_protect, ssl_protector_protect_flush, ssl_protector_unprotect,
ssl_protector_destroy,
};
/* --- tsi_handshaker methods implementation. ---*/
static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(
@ -751,8 +739,7 @@ static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) {
}
static tsi_result ssl_handshaker_process_bytes_from_peer(
tsi_handshaker* self, const unsigned char* bytes,
uint32_t* bytes_size) {
tsi_handshaker* self, const unsigned char* bytes, uint32_t* bytes_size) {
tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self;
int bytes_written_into_ssl_size = 0;
if (bytes == NULL || bytes_size == 0 || *bytes_size > INT_MAX) {
@ -884,14 +871,11 @@ static void ssl_handshaker_destroy(tsi_handshaker* self) {
static const tsi_handshaker_vtable handshaker_vtable = {
ssl_handshaker_get_bytes_to_send_to_peer,
ssl_handshaker_process_bytes_from_peer,
ssl_handshaker_get_result,
ssl_handshaker_extract_peer,
ssl_handshaker_create_frame_protector,
ssl_handshaker_process_bytes_from_peer, ssl_handshaker_get_result,
ssl_handshaker_extract_peer, ssl_handshaker_create_frame_protector,
ssl_handshaker_destroy,
};
/* --- tsi_ssl_handshaker_factory common methods. --- */
tsi_result tsi_ssl_handshaker_factory_create_handshaker(
@ -971,7 +955,6 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client,
return TSI_OK;
}
/* --- tsi_ssl__client_handshaker_factory methods implementation. --- */
static tsi_result ssl_client_handshaker_factory_create_handshaker(
@ -991,7 +974,6 @@ static void ssl_client_handshaker_factory_destroy(
free(impl);
}
/* --- tsi_ssl_server_handshaker_factory methods implementation. --- */
static tsi_result ssl_server_handshaker_factory_create_handshaker(
@ -1095,7 +1077,6 @@ static int server_handshaker_factory_alpn_callback(
return SSL_TLSEXT_ERR_NOACK;
}
/* --- tsi_ssl_handshaker_factory constructors. --- */
tsi_result tsi_create_ssl_client_handshaker_factory(
@ -1277,10 +1258,8 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) {
uint32_t i = 0;
const tsi_peer_property* property = tsi_peer_get_property_by_name(
peer, TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY);
if (property == NULL ||
property->type != TSI_PEER_PROPERTY_TYPE_STRING) {
gpr_log(GPR_ERROR,
"Invalid x509 subject common name property.");
if (property == NULL || property->type != TSI_PEER_PROPERTY_TYPE_STRING) {
gpr_log(GPR_ERROR, "Invalid x509 subject common name property.");
return 0;
}
if (does_entry_match_name(property->value.string.data,
@ -1291,8 +1270,7 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) {
property = tsi_peer_get_property_by_name(
peer, TSI_X509_SUBJECT_ALTERNATIVE_NAMES_PEER_PROPERTY);
if (property == NULL || property->type != TSI_PEER_PROPERTY_TYPE_LIST) {
gpr_log(GPR_ERROR,
"Invalid x509 subject alternative names property.");
gpr_log(GPR_ERROR, "Invalid x509 subject alternative names property.");
return 0;
}

@ -162,7 +162,6 @@ void tsi_ssl_handshaker_factory_destroy(tsi_ssl_handshaker_factory* self);
/* Util that checks that an ssl peer matches a specific name. */
int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name);
#ifdef __cplusplus
}
#endif

@ -84,13 +84,11 @@ const char* tsi_result_to_string(tsi_result result) {
}
}
/* --- tsi_frame_protector common implementation. ---
Calls specific implementation after state/input validation. */
tsi_result tsi_frame_protector_protect(
tsi_frame_protector* self,
tsi_result tsi_frame_protector_protect(tsi_frame_protector* self,
const unsigned char* unprotected_bytes,
uint32_t* unprotected_bytes_size,
unsigned char* protected_output_frames,
@ -106,10 +104,8 @@ tsi_result tsi_frame_protector_protect(
}
tsi_result tsi_frame_protector_protect_flush(
tsi_frame_protector* self,
unsigned char* protected_output_frames,
uint32_t* protected_output_frames_size,
uint32_t* still_pending_size) {
tsi_frame_protector* self, unsigned char* protected_output_frames,
uint32_t* protected_output_frames_size, uint32_t* still_pending_size) {
if (self == NULL || protected_output_frames == NULL ||
protected_output_frames == NULL || still_pending_size == NULL) {
return TSI_INVALID_ARGUMENT;
@ -120,10 +116,8 @@ tsi_result tsi_frame_protector_protect_flush(
}
tsi_result tsi_frame_protector_unprotect(
tsi_frame_protector* self,
const unsigned char* protected_frames_bytes,
uint32_t* protected_frames_bytes_size,
unsigned char* unprotected_bytes,
tsi_frame_protector* self, const unsigned char* protected_frames_bytes,
uint32_t* protected_frames_bytes_size, unsigned char* unprotected_bytes,
uint32_t* unprotected_bytes_size) {
if (self == NULL || protected_frames_bytes == NULL ||
protected_frames_bytes_size == NULL || unprotected_bytes == NULL ||
@ -140,7 +134,6 @@ void tsi_frame_protector_destroy(tsi_frame_protector* self) {
self->vtable->destroy(self);
}
/* --- tsi_handshaker common implementation. ---
Calls specific implementation after state/input validation. */
@ -153,7 +146,6 @@ tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self,
return self->vtable->get_bytes_to_send_to_peer(self, bytes, bytes_size);
}
tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker* self,
const unsigned char* bytes,
uint32_t* bytes_size) {
@ -179,8 +171,7 @@ tsi_result tsi_handshaker_extract_peer(tsi_handshaker* self, tsi_peer* peer) {
}
tsi_result tsi_handshaker_create_frame_protector(
tsi_handshaker* self,
uint32_t* max_protected_frame_size,
tsi_handshaker* self, uint32_t* max_protected_frame_size,
tsi_frame_protector** protector) {
tsi_result result;
if (self == NULL || protector == NULL) return TSI_INVALID_ARGUMENT;
@ -201,7 +192,6 @@ void tsi_handshaker_destroy(tsi_handshaker* self) {
self->vtable->destroy(self);
}
/* --- tsi_peer implementation. --- */
const tsi_peer_property* tsi_peer_get_property_by_name(const tsi_peer* self,
@ -227,7 +217,6 @@ tsi_peer_property tsi_init_peer_property(void) {
return property;
}
static void tsi_peer_destroy_list_property(tsi_peer_property* children,
uint32_t child_count) {
uint32_t i;

@ -60,7 +60,6 @@ typedef enum {
const char* tsi_result_to_string(tsi_result result);
/* --- tsi_frame_protector object ---
This object protects and unprotects buffers once the handshake is done.
@ -121,8 +120,7 @@ typedef struct tsi_frame_protector tsi_frame_protector;
if (result != TSI_OK) HandleError(result);
------------------------------------------------------------------------ */
tsi_result tsi_frame_protector_protect(
tsi_frame_protector* self,
tsi_result tsi_frame_protector_protect(tsi_frame_protector* self,
const unsigned char* unprotected_bytes,
uint32_t* unprotected_bytes_size,
unsigned char* protected_output_frames,
@ -137,10 +135,8 @@ tsi_result tsi_frame_protector_protect(
- still_pending_bytes is an output parameter indicating the number of bytes
that still need to be flushed from the protector.*/
tsi_result tsi_frame_protector_protect_flush(
tsi_frame_protector* self,
unsigned char* protected_output_frames,
uint32_t* protected_output_frames_size,
uint32_t* still_pending_size);
tsi_frame_protector* self, unsigned char* protected_output_frames,
uint32_t* protected_output_frames_size, uint32_t* still_pending_size);
/* Outputs unprotected bytes.
- protected_frames_bytes is an input only parameter and points to the
@ -163,16 +159,13 @@ tsi_result tsi_frame_protector_protect_flush(
needs to be read before new protected data can be processed in which case
protected_frames_size will be set to 0. */
tsi_result tsi_frame_protector_unprotect(
tsi_frame_protector* self,
const unsigned char* protected_frames_bytes,
uint32_t* protected_frames_bytes_size,
unsigned char* unprotected_bytes,
tsi_frame_protector* self, const unsigned char* protected_frames_bytes,
uint32_t* protected_frames_bytes_size, unsigned char* unprotected_bytes,
uint32_t* unprotected_bytes_size);
/* Destroys the tsi_frame_protector object. */
void tsi_frame_protector_destroy(tsi_frame_protector* self);
/* --- tsi_peer objects ---
tsi_peer objects are a set of properties. The peer owns the properties. */
@ -333,7 +326,6 @@ tsi_result tsi_handshaker_get_result(tsi_handshaker* self);
#define tsi_handshaker_is_in_progress(h) \
(tsi_handshaker_get_result((h)) == TSI_HANDSHAKE_IN_PROGRESS)
/* This method may return TSI_FAILED_PRECONDITION if
tsi_handshaker_is_in_progress returns 1, it returns TSI_OK otherwise
assuming the handshaker is not in a fatal error state.
@ -357,8 +349,7 @@ tsi_result tsi_handshaker_extract_peer(tsi_handshaker* self, tsi_peer* peer);
the handshaker is not in a fatal error state.
The caller is responsible for destroying the protector. */
tsi_result tsi_handshaker_create_frame_protector(
tsi_handshaker* self,
uint32_t* max_output_protected_frame_size,
tsi_handshaker* self, uint32_t* max_output_protected_frame_size,
tsi_frame_protector** protector);
/* This method releases the tsi_handshaker object. After this method is called,

@ -172,8 +172,8 @@ Status Channel::StartBlockingRpc(const RpcMethod& method,
return status;
}
StreamContextInterface* Channel::CreateStream(const RpcMethod& method,
ClientContext* context,
StreamContextInterface* Channel::CreateStream(
const RpcMethod& method, ClientContext* context,
const google::protobuf::Message* request,
google::protobuf::Message* result) {
grpc_call* call = grpc_channel_create_call(

@ -58,8 +58,8 @@ class Channel : public ChannelInterface {
const google::protobuf::Message& request,
google::protobuf::Message* result) override;
StreamContextInterface* CreateStream(const RpcMethod& method,
ClientContext* context,
StreamContextInterface* CreateStream(
const RpcMethod& method, ClientContext* context,
const google::protobuf::Message* request,
google::protobuf::Message* result) override;

@ -31,7 +31,6 @@
*
*/
#include <string>
#include <grpc/grpc_security.h>
@ -112,7 +111,6 @@ std::unique_ptr<Credentials> CredentialsFactory::IAMCredentials(
return cpp_creds;
}
// Combines two credentials objects into a composite credentials.
std::unique_ptr<Credentials> CredentialsFactory::ComposeCredentials(
const std::unique_ptr<Credentials>& creds1,

@ -40,7 +40,8 @@
namespace grpc {
bool SerializeProto(const google::protobuf::Message& msg, grpc_byte_buffer** bp) {
bool SerializeProto(const google::protobuf::Message& msg,
grpc_byte_buffer** bp) {
grpc::string msg_str;
bool success = msg.SerializeToString(&msg_str);
if (success) {
@ -52,7 +53,8 @@ bool SerializeProto(const google::protobuf::Message& msg, grpc_byte_buffer** bp)
return success;
}
bool DeserializeProto(grpc_byte_buffer* buffer, google::protobuf::Message* msg) {
bool DeserializeProto(grpc_byte_buffer* buffer,
google::protobuf::Message* msg) {
grpc::string msg_string;
grpc_byte_buffer_reader* reader = grpc_byte_buffer_reader_create(buffer);
gpr_slice slice;

@ -46,7 +46,8 @@ namespace grpc {
// Serialize the msg into a buffer created inside the function. The caller
// should destroy the returned buffer when done with it. If serialization fails,
// false is returned and buffer is left unchanged.
bool SerializeProto(const google::protobuf::Message& msg, grpc_byte_buffer** buffer);
bool SerializeProto(const google::protobuf::Message& msg,
grpc_byte_buffer** buffer);
// The caller keeps ownership of buffer and msg.
bool DeserializeProto(grpc_byte_buffer* buffer, google::protobuf::Message* msg);

@ -48,8 +48,7 @@ AsyncServerContext::AsyncServerContext(
host_(host),
absolute_deadline_(absolute_deadline),
request_(nullptr),
call_(call) {
}
call_(call) {}
AsyncServerContext::~AsyncServerContext() { grpc_call_destroy(call_); }

@ -33,6 +33,4 @@
#include "src/cpp/server/server_context_impl.h"
namespace grpc {
} // namespace grpc
namespace grpc {} // namespace grpc

@ -31,7 +31,6 @@
*
*/
#include <grpc/grpc_security.h>
#include <grpc++/server_credentials.h>

@ -60,8 +60,10 @@ void ServerRpcHandler::StartRpc() {
async_server_context_->Accept(cq_.cq());
// Allocate request and response.
std::unique_ptr<google::protobuf::Message> request(method_->AllocateRequestProto());
std::unique_ptr<google::protobuf::Message> response(method_->AllocateResponseProto());
std::unique_ptr<google::protobuf::Message> request(
method_->AllocateRequestProto());
std::unique_ptr<google::protobuf::Message> response(
method_->AllocateResponseProto());
// Read request
async_server_context_->StartRead(request.get());
@ -86,8 +88,10 @@ void ServerRpcHandler::StartRpc() {
} else {
// Allocate request and response.
// TODO(yangg) maybe not allocate both when not needed?
std::unique_ptr<google::protobuf::Message> request(method_->AllocateRequestProto());
std::unique_ptr<google::protobuf::Message> response(method_->AllocateResponseProto());
std::unique_ptr<google::protobuf::Message> request(
method_->AllocateRequestProto());
std::unique_ptr<google::protobuf::Message> response(
method_->AllocateResponseProto());
StreamContext stream_context(*method_, async_server_context_->call(),
cq_.cq(), request.get(), response.get());

@ -61,7 +61,8 @@ StreamContext::StreamContext(const RpcMethod& method, ClientContext* context,
// Server only ctor
StreamContext::StreamContext(const RpcMethod& method, grpc_call* call,
grpc_completion_queue* cq,
google::protobuf::Message* request, google::protobuf::Message* result)
google::protobuf::Message* request,
google::protobuf::Message* result)
: is_client_(false),
method_(&method),
call_(call),

@ -51,7 +51,8 @@ class RpcMethod;
class StreamContext : public StreamContextInterface {
public:
StreamContext(const RpcMethod& method, ClientContext* context,
const google::protobuf::Message* request, google::protobuf::Message* result);
const google::protobuf::Message* request,
google::protobuf::Message* result);
StreamContext(const RpcMethod& method, grpc_call* call,
grpc_completion_queue* cq, google::protobuf::Message* request,
google::protobuf::Message* result);

@ -31,7 +31,6 @@
*
*/
#include <grpc++/status.h>
namespace grpc {

@ -21,8 +21,7 @@ grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length) {
return grpc_byte_buffer_create(&slice, 1);
}
void byte_buffer_to_string(grpc_byte_buffer *buffer,
char **out_string,
void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,
size_t *out_length) {
size_t length = grpc_byte_buffer_length(buffer);
char *string = ecalloc(length + 1, sizeof(char));

@ -5,8 +5,7 @@
grpc_byte_buffer *string_to_byte_buffer(char *string, size_t length);
void byte_buffer_to_string(grpc_byte_buffer *buffer,
char **out_string,
void byte_buffer_to_string(grpc_byte_buffer *buffer, char **out_string,
size_t *out_length);
#endif /* NET_GRPC_PHP_GRPC_BYTE_BUFFER_H_ */

@ -34,8 +34,8 @@ void free_wrapped_grpc_call(void *object TSRMLS_DC){
/* Initializes an instance of wrapped_grpc_call to be associated with an object
* of a class specified by class_type */
zend_object_value create_wrapped_grpc_call(
zend_class_entry *class_type TSRMLS_DC){
zend_object_value create_wrapped_grpc_call(zend_class_entry *class_type
TSRMLS_DC) {
zend_object_value retval;
wrapped_grpc_call *intern;
@ -45,10 +45,8 @@ zend_object_value create_wrapped_grpc_call(
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(
intern,
(zend_objects_store_dtor_t) zend_objects_destroy_object,
free_wrapped_grpc_call,
NULL TSRMLS_CC);
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_call, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
@ -59,8 +57,8 @@ zval *grpc_php_wrap_call(grpc_call *wrapped, bool owned){
zval *call_object;
MAKE_STD_ZVAL(call_object);
object_init_ex(call_object, grpc_ce_call);
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
call_object TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(call_object TSRMLS_CC);
call->wrapped = wrapped;
return call_object;
}
@ -85,10 +83,8 @@ zval *grpc_call_create_metadata_array(int count, grpc_metadata *elements){
memcpy(str_key, elem->key, key_len);
str_val = ecalloc(elem->value_length + 1, sizeof(char));
memcpy(str_val, elem->value, elem->value_length);
if(zend_hash_find(array_hash,
str_key,
key_len,
(void**)data) == SUCCESS){
if (zend_hash_find(array_hash, str_key, key_len, (void **)data) ==
SUCCESS) {
switch (Z_TYPE_P(*data)) {
case IS_STRING:
MAKE_STD_ZVAL(inner_array);
@ -107,23 +103,15 @@ zval *grpc_call_create_metadata_array(int count, grpc_metadata *elements){
efree(str_val);
return NULL;
}
add_next_index_stringl(inner_array,
str_val,
elem->value_length,
false);
add_next_index_stringl(inner_array, str_val, elem->value_length, false);
} else {
add_assoc_stringl(array,
str_key,
str_val,
elem->value_length,
false);
add_assoc_stringl(array, str_key, str_val, elem->value_length, false);
}
}
return array;
}
int php_grpc_call_add_metadata_array_walk(void *elem TSRMLS_DC,
int num_args,
int php_grpc_call_add_metadata_array_walk(void *elem TSRMLS_DC, int num_args,
va_list args,
zend_hash_key *hash_key) {
grpc_call_error error_code;
@ -153,11 +141,8 @@ int php_grpc_call_add_metadata_array_walk(void *elem TSRMLS_DC,
case IS_ARRAY:
inner_hash = Z_ARRVAL_P(*data);
zend_hash_apply_with_arguments(inner_hash TSRMLS_CC,
php_grpc_call_add_metadata_array_walk,
3,
call,
flags,
key);
php_grpc_call_add_metadata_array_walk, 3,
call, flags, key);
break;
default:
zend_throw_exception(zend_exception_get_default(),
@ -175,17 +160,15 @@ int php_grpc_call_add_metadata_array_walk(void *elem TSRMLS_DC,
* @param Timeval $absolute_deadline The deadline for completing the call
*/
PHP_METHOD(Call, __construct) {
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
zval *channel_obj;
char *method;
int method_len;
zval *deadline_obj;
/* "OsO" == 1 Object, 1 string, 1 Object */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"OsO",
&channel_obj, grpc_ce_channel,
&method, &method_len,
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OsO", &channel_obj,
grpc_ce_channel, &method, &method_len,
&deadline_obj, grpc_ce_timeval) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"Call expects a Channel, a String, and a Timeval",
@ -193,7 +176,8 @@ PHP_METHOD(Call, __construct){
return;
}
wrapped_grpc_channel *channel =
(wrapped_grpc_channel*)zend_object_store_get_object(channel_obj TSRMLS_CC);
(wrapped_grpc_channel *)zend_object_store_get_object(
channel_obj TSRMLS_CC);
if (channel->wrapped == NULL) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"Call cannot be constructed from a closed Channel",
@ -202,11 +186,10 @@ PHP_METHOD(Call, __construct){
}
add_property_zval(getThis(), "channel", channel_obj);
wrapped_grpc_timeval *deadline =
(wrapped_grpc_timeval*)zend_object_store_get_object(deadline_obj TSRMLS_CC);
call->wrapped = grpc_channel_create_call(channel->wrapped,
method,
channel->target,
deadline->wrapped);
(wrapped_grpc_timeval *)zend_object_store_get_object(
deadline_obj TSRMLS_CC);
call->wrapped = grpc_channel_create_call(channel->wrapped, method,
channel->target, deadline->wrapped);
}
/**
@ -219,16 +202,14 @@ PHP_METHOD(Call, __construct){
* @return Void
*/
PHP_METHOD(Call, add_metadata) {
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
zval *array;
HashTable *array_hash;
long flags = 0;
/* "a|l" == 1 array, 1 optional long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"a|l",
&array,
&flags) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &flags) ==
FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"add_metadata expects an array and an optional long",
1 TSRMLS_CC);
@ -236,10 +217,8 @@ PHP_METHOD(Call, add_metadata){
}
array_hash = Z_ARRVAL_P(array);
zend_hash_apply_with_arguments(array_hash TSRMLS_CC,
php_grpc_call_add_metadata_array_walk,
2,
call->wrapped,
(gpr_uint32)flags);
php_grpc_call_add_metadata_array_walk, 2,
call->wrapped, (gpr_uint32)flags);
}
/**
@ -260,12 +239,8 @@ PHP_METHOD(Call, start_invoke){
zval *queue_obj;
long flags = 0;
/* "Olll|l" == 1 Object, 3 mandatory longs, 1 optional long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"Olll|l",
&queue_obj, grpc_ce_completion_queue,
&tag1,
&tag2,
&tag3,
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Olll|l", &queue_obj,
grpc_ce_completion_queue, &tag1, &tag2, &tag3,
&flags) == FAILURE) {
zend_throw_exception(
spl_ce_InvalidArgumentException,
@ -274,17 +249,14 @@ PHP_METHOD(Call, start_invoke){
return;
}
add_property_zval(getThis(), "completion_queue", queue_obj);
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
wrapped_grpc_completion_queue *queue =
(wrapped_grpc_completion_queue *)zend_object_store_get_object(
queue_obj TSRMLS_CC);
error_code = grpc_call_start_invoke(call->wrapped,
queue->wrapped,
(void*)tag1,
(void*)tag2,
(void*)tag3,
(gpr_uint32)flags);
error_code =
grpc_call_start_invoke(call->wrapped, queue->wrapped, (void *)tag1,
(void *)tag2, (void *)tag3, (gpr_uint32)flags);
MAYBE_THROW_CALL_ERROR(start_invoke, error_code);
}
@ -303,10 +275,8 @@ PHP_METHOD(Call, server_accept){
zval *queue_obj;
grpc_call_error error_code;
/* "Ol|l" == 1 Object, 1 long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"Ol",
&queue_obj, grpc_ce_completion_queue,
&tag) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &queue_obj,
grpc_ce_completion_queue, &tag) == FAILURE) {
zend_throw_exception(
spl_ce_InvalidArgumentException,
"server_accept expects a CompletionQueue, a long, and an optional long",
@ -314,14 +284,13 @@ PHP_METHOD(Call, server_accept){
return;
}
add_property_zval(getThis(), "completion_queue", queue_obj);
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
wrapped_grpc_completion_queue *queue =
(wrapped_grpc_completion_queue *)zend_object_store_get_object(
queue_obj TSRMLS_CC);
error_code = grpc_call_server_accept(call->wrapped,
queue->wrapped,
(void*)tag);
error_code =
grpc_call_server_accept(call->wrapped, queue->wrapped, (void *)tag);
MAYBE_THROW_CALL_ERROR(server_accept, error_code);
}
@ -329,16 +298,14 @@ PHP_METHOD(Call, server_end_initial_metadata) {
grpc_call_error error_code;
long flags = 0;
/* "|l" == 1 optional long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"|l",
&flags) == FAILURE) {
zend_throw_exception(
spl_ce_InvalidArgumentException,
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags) ==
FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"server_end_initial_metadata expects an optional long",
1 TSRMLS_CC);
}
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
error_code = grpc_call_server_end_initial_metadata(call->wrapped, flags);
MAYBE_THROW_CALL_ERROR(server_end_initial_metadata, error_code);
}
@ -348,8 +315,8 @@ PHP_METHOD(Call, server_end_initial_metadata) {
* @return Void
*/
PHP_METHOD(Call, cancel) {
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
grpc_call_error error_code = grpc_call_cancel(call->wrapped);
MAYBE_THROW_CALL_ERROR(cancel, error_code);
}
@ -364,28 +331,23 @@ PHP_METHOD(Call, cancel){
*/
PHP_METHOD(Call, start_write) {
grpc_call_error error_code;
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
char *buffer;
int buffer_len;
long tag;
long flags = 0;
/* "Ol|l" == 1 Object, 1 mandatory long, 1 optional long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"sl|l",
&buffer, &buffer_len,
&tag,
&flags) == FAILURE){
zend_throw_exception(
spl_ce_InvalidArgumentException,
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &buffer,
&buffer_len, &tag, &flags) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"start_write expects a string and an optional long",
1 TSRMLS_CC);
return;
}
error_code = grpc_call_start_write(call->wrapped,
string_to_byte_buffer(buffer, buffer_len),
(void*)tag,
(gpr_uint32)flags);
(void *)tag, (gpr_uint32)flags);
MAYBE_THROW_CALL_ERROR(start_write, error_code);
}
@ -398,28 +360,24 @@ PHP_METHOD(Call, start_write){
*/
PHP_METHOD(Call, start_write_status) {
grpc_call_error error_code;
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
long status_code;
int status_details_length;
long tag;
char *status_details;
/* "lsl" == 1 long, 1 string, 1 long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lsl",
&status_code,
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lsl", &status_code,
&status_details, &status_details_length,
&tag) == FAILURE) {
zend_throw_exception(
spl_ce_InvalidArgumentException,
"start_write_status expects a long, a string, and a long",
1 TSRMLS_CC);
"start_write_status expects a long, a string, and a long", 1 TSRMLS_CC);
return;
}
error_code = grpc_call_start_write_status(call->wrapped,
(grpc_status_code)status_code,
status_details,
(void*)tag);
error_code =
grpc_call_start_write_status(call->wrapped, (grpc_status_code)status_code,
status_details, (void *)tag);
MAYBE_THROW_CALL_ERROR(start_write_status, error_code);
}
@ -429,14 +387,13 @@ PHP_METHOD(Call, start_write_status){
*/
PHP_METHOD(Call, writes_done) {
grpc_call_error error_code;
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
long tag;
/* "l" == 1 long */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"writes_done expects a long",
1 TSRMLS_CC);
"writes_done expects a long", 1 TSRMLS_CC);
return;
}
error_code = grpc_call_writes_done(call->wrapped, (void *)tag);
@ -451,14 +408,13 @@ PHP_METHOD(Call, writes_done){
*/
PHP_METHOD(Call, start_read) {
grpc_call_error error_code;
wrapped_grpc_call *call = (wrapped_grpc_call*)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_call *call =
(wrapped_grpc_call *)zend_object_store_get_object(getThis() TSRMLS_CC);
long tag;
/* "l" == 1 long */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"start_read expects a long",
1 TSRMLS_CC);
"start_read expects a long", 1 TSRMLS_CC);
return;
}
error_code = grpc_call_start_read(call->wrapped, (void *)tag);
@ -469,15 +425,14 @@ static zend_function_entry call_methods[] = {
PHP_ME(Call, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Call, server_accept, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, server_end_initial_metadata, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, add_metadata, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, cancel, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, start_invoke, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, start_read, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, start_write, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, start_write_status, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, add_metadata, NULL, ZEND_ACC_PUBLIC) PHP_ME(
Call, cancel, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, start_invoke, NULL, ZEND_ACC_PUBLIC) PHP_ME(
Call, start_read, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, start_write, NULL, ZEND_ACC_PUBLIC) PHP_ME(
Call, start_write_status, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Call, writes_done, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHP_FE_END};
void grpc_init_call(TSRMLS_D) {
zend_class_entry ce;

@ -22,7 +22,6 @@
} \
} while (0)
/* Class entry for the Call PHP class */
zend_class_entry *grpc_ce_call;

@ -33,8 +33,8 @@ void free_wrapped_grpc_channel(void *object TSRMLS_DC){
/* Initializes an instance of wrapped_grpc_channel to be associated with an
* object of a class specified by class_type */
zend_object_value create_wrapped_grpc_channel(
zend_class_entry *class_type TSRMLS_DC){
zend_object_value create_wrapped_grpc_channel(zend_class_entry *class_type
TSRMLS_DC) {
zend_object_value retval;
wrapped_grpc_channel *intern;
intern = (wrapped_grpc_channel *)emalloc(sizeof(wrapped_grpc_channel));
@ -42,10 +42,8 @@ zend_object_value create_wrapped_grpc_channel(
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(
intern,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_channel,
NULL TSRMLS_CC);
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_channel, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
@ -63,19 +61,13 @@ void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args){
args->args = ecalloc(args->num_args, sizeof(grpc_arg));
args_index = 0;
for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer);
zend_hash_get_current_data_ex(array_hash,
(void**)&data,
zend_hash_get_current_data_ex(array_hash, (void **)&data,
&array_pointer) == SUCCESS;
zend_hash_move_forward_ex(array_hash, &array_pointer)) {
if(zend_hash_get_current_key_ex(array_hash,
&key,
&key_len,
&index,
0,
if (zend_hash_get_current_key_ex(array_hash, &key, &key_len, &index, 0,
&array_pointer) != HASH_KEY_IS_STRING) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"args keys must be strings",
1 TSRMLS_CC);
"args keys must be strings", 1 TSRMLS_CC);
return;
}
args->args[args_index].key = key;
@ -88,8 +80,7 @@ void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args){
break;
default:
zend_throw_exception(spl_ce_InvalidArgumentException,
"args values must be int or string",
1 TSRMLS_CC);
"args values must be int or string", 1 TSRMLS_CC);
return;
}
args_index++;
@ -114,22 +105,17 @@ PHP_METHOD(Channel, __construct){
zval **creds_obj = NULL;
wrapped_grpc_credentials *creds = NULL;
/* "s|a" == 1 string, 1 optional array */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s|a",
&target, &target_length,
&args_array) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &target,
&target_length, &args_array) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"Channel expects a string and an array",
1 TSRMLS_CC);
"Channel expects a string and an array", 1 TSRMLS_CC);
return;
}
if (args_array == NULL) {
channel->wrapped = grpc_channel_create(target, NULL);
} else {
array_hash = Z_ARRVAL_P(args_array);
if(zend_hash_find(array_hash,
"credentials",
sizeof("credentials"),
if (zend_hash_find(array_hash, "credentials", sizeof("credentials"),
(void **)&creds_obj) == SUCCESS) {
if (zend_get_class_entry(*creds_obj TSRMLS_CC) != grpc_ce_credentials) {
zend_throw_exception(spl_ce_InvalidArgumentException,
@ -146,9 +132,8 @@ PHP_METHOD(Channel, __construct){
channel->wrapped = grpc_channel_create(target, &args);
} else {
gpr_log(GPR_DEBUG, "Initialized secure channel");
channel->wrapped = grpc_secure_channel_create(creds->wrapped,
target,
&args);
channel->wrapped =
grpc_secure_channel_create(creds->wrapped, target, &args);
}
efree(args.args);
}
@ -170,9 +155,7 @@ PHP_METHOD(Channel, close){
static zend_function_entry channel_methods[] = {
PHP_ME(Channel, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(Channel, close, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHP_ME(Channel, close, NULL, ZEND_ACC_PUBLIC) PHP_FE_END};
void grpc_init_channel(TSRMLS_D) {
zend_class_entry ce;

@ -52,10 +52,8 @@ zend_object_value create_wrapped_grpc_completion_queue(
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(
intern,
(zend_objects_store_dtor_t) zend_objects_destroy_object,
free_wrapped_grpc_completion_queue,
NULL TSRMLS_CC);
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_completion_queue, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
@ -81,12 +79,10 @@ PHP_METHOD(CompletionQueue, __construct){
PHP_METHOD(CompletionQueue, next) {
zval *timeout;
/* "O" == 1 Object */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"O",
&timeout, grpc_ce_timeval)==FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &timeout,
grpc_ce_timeval) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"next needs a Timeval",
1 TSRMLS_CC);
"next needs a Timeval", 1 TSRMLS_CC);
return;
}
wrapped_grpc_completion_queue *completion_queue =
@ -107,22 +103,18 @@ PHP_METHOD(CompletionQueue, pluck){
long tag;
zval *timeout;
/* "lO" == 1 long, 1 Object */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lO",
&tag,
&timeout, grpc_ce_timeval)==FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lO", &tag, &timeout,
grpc_ce_timeval) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"pluck needs a long and a Timeval",
1 TSRMLS_CC);
"pluck needs a long and a Timeval", 1 TSRMLS_CC);
}
wrapped_grpc_completion_queue *completion_queue =
(wrapped_grpc_completion_queue *)zend_object_store_get_object(
getThis() TSRMLS_CC);
wrapped_grpc_timeval *wrapped_timeout =
(wrapped_grpc_timeval *)zend_object_store_get_object(timeout TSRMLS_CC);
grpc_event *event = grpc_completion_queue_pluck(completion_queue->wrapped,
(void*)tag,
wrapped_timeout->wrapped);
grpc_event *event = grpc_completion_queue_pluck(
completion_queue->wrapped, (void *)tag, wrapped_timeout->wrapped);
if (event == NULL) {
RETURN_NULL();
}
@ -133,9 +125,7 @@ PHP_METHOD(CompletionQueue, pluck){
static zend_function_entry completion_queue_methods[] = {
PHP_ME(CompletionQueue, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(CompletionQueue, next, NULL, ZEND_ACC_PUBLIC)
PHP_ME(CompletionQueue, pluck, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHP_ME(CompletionQueue, pluck, NULL, ZEND_ACC_PUBLIC) PHP_FE_END};
void grpc_init_completion_queue(TSRMLS_D) {
zend_class_entry ce;

@ -27,21 +27,20 @@ void free_wrapped_grpc_credentials(void *object TSRMLS_DC){
/* Initializes an instance of wrapped_grpc_credentials to be associated with an
* object of a class specified by class_type */
zend_object_value create_wrapped_grpc_credentials(
zend_class_entry *class_type TSRMLS_DC){
zend_object_value create_wrapped_grpc_credentials(zend_class_entry *class_type
TSRMLS_DC) {
zend_object_value retval;
wrapped_grpc_credentials *intern;
intern = (wrapped_grpc_credentials*)emalloc(sizeof(wrapped_grpc_credentials));
intern =
(wrapped_grpc_credentials *)emalloc(sizeof(wrapped_grpc_credentials));
memset(intern, 0, sizeof(wrapped_grpc_credentials));
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(
intern,
(zend_objects_store_dtor_t) zend_objects_destroy_object,
free_wrapped_grpc_credentials,
NULL TSRMLS_CC);
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_credentials, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
@ -84,14 +83,12 @@ PHP_METHOD(Credentials, createSsl){
int root_certs_length, private_key_length = 0, cert_chain_length = 0;
/* "s|s!s! == 1 string, 2 optional nullable strings */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s|s!s!",
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!s!",
&pem_root_certs, &root_certs_length,
&pem_private_key, &private_key_length,
&pem_cert_chain, &cert_chain_length) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"createSsl expects 1 to 3 strings",
1 TSRMLS_CC);
"createSsl expects 1 to 3 strings", 1 TSRMLS_CC);
return;
}
grpc_credentials *creds = grpc_ssl_credentials_create(
@ -113,13 +110,11 @@ PHP_METHOD(Credentials, createComposite){
zval *cred2_obj;
/* "OO" == 3 Objects */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"OO",
&cred1_obj, grpc_ce_credentials,
&cred2_obj, grpc_ce_credentials) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &cred1_obj,
grpc_ce_credentials, &cred2_obj,
grpc_ce_credentials) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"createComposite expects 2 Credentials",
1 TSRMLS_CC);
"createComposite expects 2 Credentials", 1 TSRMLS_CC);
return;
}
wrapped_grpc_credentials *cred1 =
@ -128,8 +123,8 @@ PHP_METHOD(Credentials, createComposite){
wrapped_grpc_credentials *cred2 =
(wrapped_grpc_credentials *)zend_object_store_get_object(
cred2_obj TSRMLS_CC);
grpc_credentials *creds = grpc_composite_credentials_create(cred1->wrapped,
cred2->wrapped);
grpc_credentials *creds =
grpc_composite_credentials_create(cred1->wrapped, cred2->wrapped);
zval *creds_object = grpc_php_wrap_credentials(creds);
RETURN_DESTROY_ZVAL(creds_object);
}
@ -157,11 +152,12 @@ PHP_METHOD(Credentials, createFake) {
static zend_function_entry credentials_methods[] = {
PHP_ME(Credentials, createDefault, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createSsl, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createComposite, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Credentials, createGce, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Credentials, createFake, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
PHP_ME(Credentials, createComposite, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createGce, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Credentials, createFake, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_FE_END};
void grpc_init_credentials(TSRMLS_D) {
zend_class_entry ce;

@ -39,15 +39,16 @@ zval *grpc_php_convert_event(grpc_event *event) {
MAKE_STD_ZVAL(event_object);
object_init(event_object);
add_property_zval(event_object,
"call",
grpc_php_wrap_call(event->call,
event->type==GRPC_SERVER_RPC_NEW));
add_property_zval(
event_object, "call",
grpc_php_wrap_call(event->call, event->type == GRPC_SERVER_RPC_NEW));
add_property_long(event_object, "type", event->type);
add_property_long(event_object, "tag", (long)event->tag);
switch (event->type) {
case GRPC_QUEUE_SHUTDOWN: add_property_null(event_object, "data"); break;
case GRPC_QUEUE_SHUTDOWN:
add_property_null(event_object, "data");
break;
case GRPC_READ:
if (event->data.read == NULL) {
add_property_null(event_object, "data");
@ -57,16 +58,14 @@ zval *grpc_php_convert_event(grpc_event *event) {
}
break;
case GRPC_INVOKE_ACCEPTED:
add_property_long(event_object,
"data",
add_property_long(event_object, "data",
(long)event->data.invoke_accepted);
break;
case GRPC_WRITE_ACCEPTED:
add_property_long(event_object, "data", (long)event->data.write_accepted);
break;
case GRPC_FINISH_ACCEPTED:
add_property_long(event_object,
"data",
add_property_long(event_object, "data",
(long)event->data.finish_accepted);
break;
case GRPC_CLIENT_METADATA_READ:
@ -85,13 +84,9 @@ zval *grpc_php_convert_event(grpc_event *event) {
detail_len = strlen(event->data.finished.details);
detail_string = ecalloc(detail_len + 1, sizeof(char));
memcpy(detail_string, event->data.finished.details, detail_len);
add_property_string(data_object,
"details",
detail_string,
true);
add_property_string(data_object, "details", detail_string, true);
}
add_property_zval(data_object,
"metadata",
add_property_zval(data_object, "metadata",
grpc_call_create_metadata_array(
event->data.finished.metadata_count,
event->data.finished.metadata_elements));
@ -103,29 +98,23 @@ zval *grpc_php_convert_event(grpc_event *event) {
method_len = strlen(event->data.server_rpc_new.method);
method_string = ecalloc(method_len + 1, sizeof(char));
memcpy(method_string, event->data.server_rpc_new.method, method_len);
add_property_string(data_object,
"method",
method_string,
false);
add_property_string(data_object, "method", method_string, false);
host_len = strlen(event->data.server_rpc_new.host);
host_string = ecalloc(host_len + 1, sizeof(char));
memcpy(host_string, event->data.server_rpc_new.host, host_len);
add_property_string(data_object,
"host",
host_string,
false);
add_property_zval(data_object,
"absolute_timeout",
grpc_php_wrap_timeval(
event->data.server_rpc_new.deadline));
add_property_zval(data_object,
"metadata",
add_property_string(data_object, "host", host_string, false);
add_property_zval(
data_object, "absolute_timeout",
grpc_php_wrap_timeval(event->data.server_rpc_new.deadline));
add_property_zval(data_object, "metadata",
grpc_call_create_metadata_array(
event->data.server_rpc_new.metadata_count,
event->data.server_rpc_new.metadata_elements));
add_property_zval(event_object, "data", data_object);
break;
default: add_property_null(event_object, "data"); break;
default:
add_property_null(event_object, "data");
break;
}
grpc_event_finish(event);
return event_object;

@ -33,18 +33,12 @@ zend_module_entry grpc_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"grpc",
grpc_functions,
PHP_MINIT(grpc),
PHP_MSHUTDOWN(grpc),
NULL,
NULL,
"grpc", grpc_functions, PHP_MINIT(grpc), PHP_MSHUTDOWN(grpc), NULL, NULL,
PHP_MINFO(grpc),
#if ZEND_MODULE_API_NO >= 20010901
PHP_GRPC_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
STANDARD_MODULE_PROPERTIES};
/* }}} */
#ifdef COMPILE_DL_GRPC
@ -55,8 +49,10 @@ ZEND_GET_MODULE(grpc)
*/
/* Remove comments and fill if you need to have entries in php.ini
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("grpc.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_grpc_globals, grpc_globals)
STD_PHP_INI_ENTRY("grpc.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_grpc_globals, grpc_globals)
STD_PHP_INI_ENTRY("grpc.global_value", "42", PHP_INI_ALL, OnUpdateLong,
global_value, zend_grpc_globals, grpc_globals)
STD_PHP_INI_ENTRY("grpc.global_string", "foobar", PHP_INI_ALL,
OnUpdateString, global_string, zend_grpc_globals, grpc_globals)
PHP_INI_END()
*/
/* }}} */
@ -74,8 +70,7 @@ static void php_grpc_init_globals(zend_grpc_globals *grpc_globals)
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(grpc)
{
PHP_MINIT_FUNCTION(grpc) {
/* If you have INI entries, uncomment these lines
REGISTER_INI_ENTRIES();
*/
@ -84,112 +79,74 @@ PHP_MINIT_FUNCTION(grpc)
REGISTER_LONG_CONSTANT("Grpc\\CALL_OK", GRPC_CALL_OK, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR", GRPC_CALL_ERROR, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_ON_SERVER",
GRPC_CALL_ERROR_NOT_ON_SERVER,
CONST_CS);
GRPC_CALL_ERROR_NOT_ON_SERVER, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_ON_CLIENT",
GRPC_CALL_ERROR_NOT_ON_CLIENT,
CONST_CS);
GRPC_CALL_ERROR_NOT_ON_CLIENT, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_ALREADY_INVOKED",
GRPC_CALL_ERROR_ALREADY_INVOKED,
CONST_CS);
GRPC_CALL_ERROR_ALREADY_INVOKED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_NOT_INVOKED",
GRPC_CALL_ERROR_NOT_INVOKED,
CONST_CS);
GRPC_CALL_ERROR_NOT_INVOKED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_ALREADY_FINISHED",
GRPC_CALL_ERROR_ALREADY_FINISHED,
CONST_CS);
GRPC_CALL_ERROR_ALREADY_FINISHED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_TOO_MANY_OPERATIONS",
GRPC_CALL_ERROR_TOO_MANY_OPERATIONS,
CONST_CS);
GRPC_CALL_ERROR_TOO_MANY_OPERATIONS, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CALL_ERROR_INVALID_FLAGS",
GRPC_CALL_ERROR_INVALID_FLAGS,
CONST_CS);
GRPC_CALL_ERROR_INVALID_FLAGS, CONST_CS);
/* Register op error constants */
REGISTER_LONG_CONSTANT("Grpc\\OP_OK", GRPC_OP_OK, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\OP_ERROR", GRPC_OP_ERROR, CONST_CS);
/* Register flag constants */
REGISTER_LONG_CONSTANT("Grpc\\WRITE_BUFFER_HINT",
GRPC_WRITE_BUFFER_HINT,
REGISTER_LONG_CONSTANT("Grpc\\WRITE_BUFFER_HINT", GRPC_WRITE_BUFFER_HINT,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\WRITE_NO_COMPRESS",
GRPC_WRITE_NO_COMPRESS,
REGISTER_LONG_CONSTANT("Grpc\\WRITE_NO_COMPRESS", GRPC_WRITE_NO_COMPRESS,
CONST_CS);
/* Register completion type constants */
REGISTER_LONG_CONSTANT("Grpc\\QUEUE_SHUTDOWN",
GRPC_QUEUE_SHUTDOWN,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\QUEUE_SHUTDOWN", GRPC_QUEUE_SHUTDOWN, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\READ", GRPC_READ, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\INVOKE_ACCEPTED",
GRPC_INVOKE_ACCEPTED,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\WRITE_ACCEPTED",
GRPC_WRITE_ACCEPTED,
REGISTER_LONG_CONSTANT("Grpc\\INVOKE_ACCEPTED", GRPC_INVOKE_ACCEPTED,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\FINISH_ACCEPTED",
GRPC_FINISH_ACCEPTED,
REGISTER_LONG_CONSTANT("Grpc\\WRITE_ACCEPTED", GRPC_WRITE_ACCEPTED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\FINISH_ACCEPTED", GRPC_FINISH_ACCEPTED,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\CLIENT_METADATA_READ",
GRPC_CLIENT_METADATA_READ,
CONST_CS);
GRPC_CLIENT_METADATA_READ, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\FINISHED", GRPC_FINISHED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\SERVER_RPC_NEW",
GRPC_SERVER_RPC_NEW,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\SERVER_RPC_NEW", GRPC_SERVER_RPC_NEW, CONST_CS);
/* Register status constants */
REGISTER_LONG_CONSTANT("Grpc\\STATUS_OK",
GRPC_STATUS_OK,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_CANCELLED",
GRPC_STATUS_CANCELLED,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNKNOWN",
GRPC_STATUS_UNKNOWN,
REGISTER_LONG_CONSTANT("Grpc\\STATUS_OK", GRPC_STATUS_OK, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_CANCELLED", GRPC_STATUS_CANCELLED,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNKNOWN", GRPC_STATUS_UNKNOWN, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_INVALID_ARGUMENT",
GRPC_STATUS_INVALID_ARGUMENT,
CONST_CS);
GRPC_STATUS_INVALID_ARGUMENT, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_DEADLINE_EXCEEDED",
GRPC_STATUS_DEADLINE_EXCEEDED,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_NOT_FOUND",
GRPC_STATUS_NOT_FOUND,
GRPC_STATUS_DEADLINE_EXCEEDED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_NOT_FOUND", GRPC_STATUS_NOT_FOUND,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_ALREADY_EXISTS",
GRPC_STATUS_ALREADY_EXISTS,
CONST_CS);
GRPC_STATUS_ALREADY_EXISTS, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_PERMISSION_DENIED",
GRPC_STATUS_PERMISSION_DENIED,
CONST_CS);
GRPC_STATUS_PERMISSION_DENIED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAUTHENTICATED",
GRPC_STATUS_UNAUTHENTICATED,
CONST_CS);
GRPC_STATUS_UNAUTHENTICATED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_RESOURCE_EXHAUSTED",
GRPC_STATUS_RESOURCE_EXHAUSTED,
CONST_CS);
GRPC_STATUS_RESOURCE_EXHAUSTED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_FAILED_PRECONDITION",
GRPC_STATUS_FAILED_PRECONDITION,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_ABORTED",
GRPC_STATUS_ABORTED,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_OUT_OF_RANGE",
GRPC_STATUS_OUT_OF_RANGE,
GRPC_STATUS_FAILED_PRECONDITION, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_ABORTED", GRPC_STATUS_ABORTED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_OUT_OF_RANGE", GRPC_STATUS_OUT_OF_RANGE,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNIMPLEMENTED",
GRPC_STATUS_UNIMPLEMENTED,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_INTERNAL",
GRPC_STATUS_INTERNAL,
GRPC_STATUS_UNIMPLEMENTED, CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_INTERNAL", GRPC_STATUS_INTERNAL,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAVAILABLE",
GRPC_STATUS_UNAVAILABLE,
REGISTER_LONG_CONSTANT("Grpc\\STATUS_UNAVAILABLE", GRPC_STATUS_UNAVAILABLE,
CONST_CS);
REGISTER_LONG_CONSTANT("Grpc\\STATUS_DATA_LOSS",
GRPC_STATUS_DATA_LOSS,
REGISTER_LONG_CONSTANT("Grpc\\STATUS_DATA_LOSS", GRPC_STATUS_DATA_LOSS,
CONST_CS);
grpc_init_call(TSRMLS_C);
@ -205,8 +162,7 @@ PHP_MINIT_FUNCTION(grpc)
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(grpc)
{
PHP_MSHUTDOWN_FUNCTION(grpc) {
/* uncomment this line if you have INI entries
UNREGISTER_INI_ENTRIES();
*/
@ -218,8 +174,7 @@ PHP_MSHUTDOWN_FUNCTION(grpc)
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(grpc)
{
PHP_MINFO_FUNCTION(grpc) {
php_info_print_table_start();
php_info_print_table_header(2, "grpc support", "enabled");
php_info_print_table_end();
@ -235,7 +190,6 @@ PHP_MINFO_FUNCTION(grpc)
follow this convention for the convenience of others editing your code.
*/
/*
* Local variables:
* tab-width: 4

@ -7,7 +7,8 @@
extern zend_module_entry grpc_module_entry;
#define phpext_grpc_ptr &grpc_module_entry
#define PHP_GRPC_VERSION "0.1.0" /* Replace with version number for your extension */
#define PHP_GRPC_VERSION \
"0.1.0" /* Replace with version number for your extension */
#ifdef PHP_WIN32
#define PHP_GRPC_API __declspec(dllexport)
@ -26,9 +27,7 @@ extern zend_module_entry grpc_module_entry;
#include "grpc/grpc.h"
#define RETURN_DESTROY_ZVAL(val) \
RETURN_ZVAL( \
val, \
false /* Don't execute copy constructor */, \
RETURN_ZVAL(val, false /* Don't execute copy constructor */, \
true /* Dealloc original before returning */)
/* These are all function declarations */

@ -35,8 +35,8 @@ void free_wrapped_grpc_server(void *object TSRMLS_DC){
/* Initializes an instance of wrapped_grpc_call to be associated with an object
* of a class specified by class_type */
zend_object_value create_wrapped_grpc_server(
zend_class_entry *class_type TSRMLS_DC){
zend_object_value create_wrapped_grpc_server(zend_class_entry *class_type
TSRMLS_DC) {
zend_object_value retval;
wrapped_grpc_server *intern;
@ -46,10 +46,8 @@ zend_object_value create_wrapped_grpc_server(
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(
intern,
(zend_objects_store_dtor_t) zend_objects_destroy_object,
free_wrapped_grpc_server,
NULL TSRMLS_CC);
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_server, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
@ -69,10 +67,8 @@ PHP_METHOD(Server, __construct){
zval **creds_obj = NULL;
wrapped_grpc_server_credentials *creds = NULL;
/* "O|a" == 1 Object, 1 optional array */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"O|a",
&queue_obj, grpc_ce_completion_queue,
&args_array) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|a", &queue_obj,
grpc_ce_completion_queue, &args_array) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"Server expects a CompletionQueue and an array",
1 TSRMLS_CC);
@ -86,9 +82,7 @@ PHP_METHOD(Server, __construct){
server->wrapped = grpc_server_create(queue->wrapped, NULL);
} else {
array_hash = Z_ARRVAL_P(args_array);
if(zend_hash_find(array_hash,
"credentials",
sizeof("credentials"),
if (zend_hash_find(array_hash, "credentials", sizeof("credentials"),
(void **)&creds_obj) == SUCCESS) {
if (zend_get_class_entry(*creds_obj TSRMLS_CC) !=
grpc_ce_server_credentials) {
@ -106,9 +100,8 @@ PHP_METHOD(Server, __construct){
server->wrapped = grpc_server_create(queue->wrapped, &args);
} else {
gpr_log(GPR_DEBUG, "Initialized secure server");
server->wrapped = grpc_secure_server_create(creds->wrapped,
queue->wrapped,
&args);
server->wrapped =
grpc_secure_server_create(creds->wrapped, queue->wrapped, &args);
}
efree(args.args);
}
@ -126,12 +119,10 @@ PHP_METHOD(Server, request_call){
(wrapped_grpc_server *)zend_object_store_get_object(getThis() TSRMLS_CC);
long tag_new;
/* "l" == 1 long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l",
&tag_new) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &tag_new) ==
FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"request_call expects a long",
1 TSRMLS_CC);
"request_call expects a long", 1 TSRMLS_CC);
return;
}
error_code = grpc_server_request_call(server->wrapped, (void *)tag_new);
@ -149,12 +140,10 @@ PHP_METHOD(Server, add_http2_port){
const char *addr;
int addr_len;
/* "s" == 1 string */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s",
&addr, &addr_len) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) ==
FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"add_http2_port expects a string",
1 TSRMLS_CC);
"add_http2_port expects a string", 1 TSRMLS_CC);
return;
}
RETURN_BOOL(grpc_server_add_http2_port(server->wrapped, addr));
@ -166,12 +155,10 @@ PHP_METHOD(Server, add_secure_http2_port){
const char *addr;
int addr_len;
/* "s" == 1 string */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s",
&addr, &addr_len) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) ==
FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"add_http2_port expects a string",
1 TSRMLS_CC);
"add_http2_port expects a string", 1 TSRMLS_CC);
return;
}
RETURN_BOOL(grpc_server_add_secure_http2_port(server->wrapped, addr));
@ -192,9 +179,7 @@ static zend_function_entry server_methods[] = {
PHP_ME(Server, request_call, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Server, add_http2_port, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Server, add_secure_http2_port, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Server, start, NULL, ZEND_ACC_PUBLIC)
PHP_FE_END
};
PHP_ME(Server, start, NULL, ZEND_ACC_PUBLIC) PHP_FE_END};
void grpc_init_server(TSRMLS_D) {
zend_class_entry ce;

@ -33,17 +33,15 @@ zend_object_value create_wrapped_grpc_server_credentials(
zend_object_value retval;
wrapped_grpc_server_credentials *intern;
intern = (wrapped_grpc_server_credentials*)emalloc(sizeof(
wrapped_grpc_server_credentials));
intern = (wrapped_grpc_server_credentials *)emalloc(
sizeof(wrapped_grpc_server_credentials));
memset(intern, 0, sizeof(wrapped_grpc_server_credentials));
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(
intern,
(zend_objects_store_dtor_t) zend_objects_destroy_object,
free_wrapped_grpc_server_credentials,
NULL TSRMLS_CC);
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_server_credentials, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
@ -74,14 +72,12 @@ PHP_METHOD(ServerCredentials, createSsl){
int root_certs_length = 0, private_key_length, cert_chain_length;
/* "s!ss" == 1 nullable string, 2 strings */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"s!ss",
&pem_root_certs, &root_certs_length,
&pem_private_key, &private_key_length,
&pem_cert_chain, &cert_chain_length) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!ss", &pem_root_certs,
&root_certs_length, &pem_private_key,
&private_key_length, &pem_cert_chain,
&cert_chain_length) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"createSsl expects 3 strings",
1 TSRMLS_CC);
"createSsl expects 3 strings", 1 TSRMLS_CC);
return;
}
grpc_server_credentials *creds = grpc_ssl_server_credentials_create(
@ -104,10 +100,10 @@ PHP_METHOD(ServerCredentials, createFake){
}
static zend_function_entry server_credentials_methods[] = {
PHP_ME(ServerCredentials, createSsl, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(ServerCredentials, createFake, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
PHP_ME(ServerCredentials, createSsl, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(ServerCredentials, createFake, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_FE_END};
void grpc_init_server_credentials(TSRMLS_D) {
zend_class_entry ce;

@ -18,14 +18,12 @@
#include "grpc/support/time.h"
/* Frees and destroys an instance of wrapped_grpc_call */
void free_wrapped_grpc_timeval(void *object TSRMLS_DC){
efree(object);
}
void free_wrapped_grpc_timeval(void *object TSRMLS_DC) { efree(object); }
/* Initializes an instance of wrapped_grpc_timeval to be associated with an
* object of a class specified by class_type */
zend_object_value create_wrapped_grpc_timeval(
zend_class_entry *class_type TSRMLS_DC){
zend_object_value create_wrapped_grpc_timeval(zend_class_entry *class_type
TSRMLS_DC) {
zend_object_value retval;
wrapped_grpc_timeval *intern;
intern = (wrapped_grpc_timeval *)emalloc(sizeof(wrapped_grpc_timeval));
@ -33,10 +31,8 @@ zend_object_value create_wrapped_grpc_timeval(
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);
retval.handle = zend_objects_store_put(
intern,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_timeval,
NULL TSRMLS_CC);
intern, (zend_objects_store_dtor_t)zend_objects_destroy_object,
free_wrapped_grpc_timeval, NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
@ -61,12 +57,10 @@ PHP_METHOD(Timeval, __construct){
(wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC);
long microseconds;
/* "l" == 1 long */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l",
&microseconds) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &microseconds) ==
FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"Timeval expects a long",
1 TSRMLS_CC);
"Timeval expects a long", 1 TSRMLS_CC);
return;
}
gpr_timespec time = gpr_time_from_micros(microseconds);
@ -82,20 +76,18 @@ PHP_METHOD(Timeval, __construct){
PHP_METHOD(Timeval, add) {
zval *other_obj;
/* "O" == 1 Object */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"O",
&other_obj, grpc_ce_timeval) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &other_obj,
grpc_ce_timeval) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"add expects a Timeval",
1 TSRMLS_CC);
"add expects a Timeval", 1 TSRMLS_CC);
return;
}
wrapped_grpc_timeval *self =
(wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC);
wrapped_grpc_timeval *other =
(wrapped_grpc_timeval *)zend_object_store_get_object(other_obj TSRMLS_CC);
zval *sum = grpc_php_wrap_timeval(gpr_time_add(self->wrapped,
other->wrapped));
zval *sum =
grpc_php_wrap_timeval(gpr_time_add(self->wrapped, other->wrapped));
RETURN_DESTROY_ZVAL(sum);
}
@ -108,20 +100,18 @@ PHP_METHOD(Timeval, add){
PHP_METHOD(Timeval, subtract) {
zval *other_obj;
/* "O" == 1 Object */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"O",
&other_obj, grpc_ce_timeval) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &other_obj,
grpc_ce_timeval) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"subtract expects a Timeval",
1 TSRMLS_CC);
"subtract expects a Timeval", 1 TSRMLS_CC);
return;
}
wrapped_grpc_timeval *self =
(wrapped_grpc_timeval *)zend_object_store_get_object(getThis() TSRMLS_CC);
wrapped_grpc_timeval *other =
(wrapped_grpc_timeval *)zend_object_store_get_object(other_obj TSRMLS_CC);
zval *diff = grpc_php_wrap_timeval(gpr_time_sub(self->wrapped,
other->wrapped));
zval *diff =
grpc_php_wrap_timeval(gpr_time_sub(self->wrapped, other->wrapped));
RETURN_DESTROY_ZVAL(diff);
}
@ -135,13 +125,11 @@ PHP_METHOD(Timeval, subtract){
PHP_METHOD(Timeval, compare) {
zval *a_obj, *b_obj;
/* "OO" == 2 Objects */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"OO",
&a_obj, grpc_ce_timeval,
&b_obj, grpc_ce_timeval) == FAILURE){
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OO", &a_obj,
grpc_ce_timeval, &b_obj,
grpc_ce_timeval) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"compare expects two Timevals",
1 TSRMLS_CC);
"compare expects two Timevals", 1 TSRMLS_CC);
return;
}
wrapped_grpc_timeval *a =
@ -162,14 +150,11 @@ PHP_METHOD(Timeval, compare){
PHP_METHOD(Timeval, similar) {
zval *a_obj, *b_obj, *thresh_obj;
/* "OOO" == 3 Objects */
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"OOO",
&a_obj, grpc_ce_timeval,
&b_obj, grpc_ce_timeval,
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "OOO", &a_obj,
grpc_ce_timeval, &b_obj, grpc_ce_timeval,
&thresh_obj, grpc_ce_timeval) == FAILURE) {
zend_throw_exception(spl_ce_InvalidArgumentException,
"compare expects three Timevals",
1 TSRMLS_CC);
"compare expects three Timevals", 1 TSRMLS_CC);
return;
}
wrapped_grpc_timeval *a =
@ -177,7 +162,8 @@ PHP_METHOD(Timeval, similar){
wrapped_grpc_timeval *b =
(wrapped_grpc_timeval *)zend_object_store_get_object(b_obj TSRMLS_CC);
wrapped_grpc_timeval *thresh =
(wrapped_grpc_timeval*)zend_object_store_get_object(thresh_obj TSRMLS_CC);
(wrapped_grpc_timeval *)zend_object_store_get_object(
thresh_obj TSRMLS_CC);
int result = gpr_time_similar(a->wrapped, b->wrapped, thresh->wrapped);
RETURN_BOOL(result);
}
@ -231,18 +217,20 @@ PHP_METHOD(Timeval, sleep_until){
}
static zend_function_entry timeval_methods[] = {
PHP_ME(Timeval, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Timeval, add, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Timeval, compare, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Timeval, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) PHP_ME(
Timeval, add, NULL,
ZEND_ACC_PUBLIC) PHP_ME(Timeval, compare, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Timeval, inf_future, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Timeval, inf_past, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Timeval, now, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Timeval, similar, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_ME(Timeval, similar, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Timeval, sleep_until, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Timeval, subtract, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Timeval, zero, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
PHP_FE_END
};
PHP_ME(Timeval, zero, NULL,
ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_FE_END};
void grpc_init_timeval(TSRMLS_D) {
zend_class_entry ce;
@ -251,5 +239,4 @@ void grpc_init_timeval(TSRMLS_D){
grpc_ce_timeval = zend_register_internal_class(&ce TSRMLS_CC);
}
void grpc_shutdown_timeval(TSRMLS_D){
}
void grpc_shutdown_timeval(TSRMLS_D) {}

@ -1,3 +1,5 @@
#!/usr/bin/env ruby
# Copyright 2014, Google Inc.
# All rights reserved.
#
@ -27,7 +29,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#!/usr/bin/env ruby
# interop_client is a testing tool that accesses a gRPC interop testing
# server and runs a test on it.
#

@ -1,3 +1,5 @@
#!/usr/bin/env ruby
# Copyright 2014, Google Inc.
# All rights reserved.
#
@ -27,8 +29,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#!/usr/bin/env ruby
#
# interop_server is a Testing app that runs a gRPC interop testing server.
#
# It helps validate interoperation b/w gRPC in different environments

@ -1,3 +1,5 @@
#!/usr/bin/env ruby
# Copyright 2014, Google Inc.
# All rights reserved.
#
@ -27,8 +29,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#!/usr/bin/env ruby
#
# Sample app that accesses a Calc service running on a Ruby gRPC server and
# helps validate RpcServer as a gRPC server using proto2 serialization.
#

@ -1,3 +1,5 @@
#!/usr/bin/env ruby
# Copyright 2014, Google Inc.
# All rights reserved.
#
@ -27,8 +29,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#!/usr/bin/env ruby
#
# Sample gRPC Ruby server that implements the Math::Calc service and helps
# validate GRPC::RpcServer as GRPC implementation using proto2 serialization.
#

@ -1,3 +1,5 @@
#!/usr/bin/env ruby
# Copyright 2014, Google Inc.
# All rights reserved.
#
@ -27,7 +29,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#!/usr/bin/env ruby
# Sample app that helps validate RpcServer without protobuf serialization.
#
# Usage: $ ruby -S path/to/noproto_client.rb

@ -1,3 +1,5 @@
#!/usr/bin/env ruby
# Copyright 2014, Google Inc.
# All rights reserved.
#
@ -27,7 +29,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#!/usr/bin/env ruby
# Sample app that helps validate RpcServer without protobuf serialization.
#
# Usage: $ path/to/noproto_server.rb

@ -49,7 +49,6 @@ typedef struct grpc_rb_byte_buffer {
grpc_byte_buffer *wrapped;
} grpc_rb_byte_buffer;
/* Destroys ByteBuffer instances. */
static void grpc_rb_byte_buffer_free(void *p) {
grpc_rb_byte_buffer *bb = NULL;
@ -169,7 +168,6 @@ static VALUE grpc_rb_byte_buffer_to_s(VALUE self) {
return output_obj;
}
/* Initializes ByteBuffer instances. */
static VALUE grpc_rb_byte_buffer_init(VALUE self, VALUE src) {
gpr_slice a_slice;
@ -205,8 +203,8 @@ static VALUE grpc_rb_byte_buffer_init(VALUE self, VALUE src) {
VALUE rb_cByteBuffer = Qnil;
void Init_google_rpc_byte_buffer() {
rb_cByteBuffer = rb_define_class_under(rb_mGoogleRpcCore, "ByteBuffer",
rb_cObject);
rb_cByteBuffer =
rb_define_class_under(rb_mGoogleRpcCore, "ByteBuffer", rb_cObject);
/* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(rb_cByteBuffer, grpc_rb_byte_buffer_alloc);

@ -223,8 +223,7 @@ static VALUE grpc_rb_call_start_invoke(int argc, VALUE *argv, VALUE self) {
Data_Get_Struct(self, grpc_call, call);
err = grpc_call_start_invoke(call, cq, ROBJECT(invoke_accepted_tag),
ROBJECT(metadata_read_tag),
ROBJECT(finished_tag),
NUM2UINT(flags));
ROBJECT(finished_tag), NUM2UINT(flags));
if (err != GRPC_CALL_OK) {
rb_raise(rb_eCallError, "invoke failed: %s (code=%d)",
grpc_call_error_detail_of(err), err);
@ -445,7 +444,6 @@ static VALUE grpc_rb_call_server_accept(VALUE self, VALUE cqueue,
return Qnil;
}
/* rb_cCall is the ruby class that proxies grpc_call. */
VALUE rb_cCall = Qnil;
@ -477,8 +475,8 @@ void Init_google_rpc_error_codes() {
/* Add the detail strings to a Hash */
rb_error_code_details = rb_hash_new();
rb_hash_aset(rb_error_code_details,
UINT2NUM(GRPC_CALL_OK), rb_str_new2("ok"));
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_OK),
rb_str_new2("ok"));
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR),
rb_str_new2("unknown error"));
rb_hash_aset(rb_error_code_details, UINT2NUM(GRPC_CALL_ERROR_NOT_ON_SERVER),
@ -506,8 +504,8 @@ void Init_google_rpc_error_codes() {
void Init_google_rpc_call() {
/* CallError inherits from Exception to signal that it is non-recoverable */
rb_eCallError = rb_define_class_under(rb_mGoogleRpcCore, "CallError",
rb_eException);
rb_eCallError =
rb_define_class_under(rb_mGoogleRpcCore, "CallError", rb_eException);
rb_cCall = rb_define_class_under(rb_mGoogleRpcCore, "Call", rb_cObject);
/* Prevent allocation or inialization of the Call class */
@ -519,8 +517,7 @@ void Init_google_rpc_call() {
rb_define_method(rb_cCall, "server_accept", grpc_rb_call_server_accept, 2);
rb_define_method(rb_cCall, "server_end_initial_metadata",
grpc_rb_call_server_end_initial_metadata, -1);
rb_define_method(rb_cCall, "add_metadata", grpc_rb_call_add_metadata,
-1);
rb_define_method(rb_cCall, "add_metadata", grpc_rb_call_add_metadata, -1);
rb_define_method(rb_cCall, "cancel", grpc_rb_call_cancel, 0);
rb_define_method(rb_cCall, "start_invoke", grpc_rb_call_start_invoke, -1);
rb_define_method(rb_cCall, "start_read", grpc_rb_call_start_read, 1);
@ -570,6 +567,5 @@ VALUE grpc_rb_wrap_call(grpc_call* c) {
rb_hash_aset(hash_all_calls, OFFT2NUM((VALUE)c),
UINT2NUM(NUM2UINT(obj) + 1));
}
return Data_Wrap_Struct(rb_cCall, GC_NOT_MARKED, grpc_rb_call_destroy,
c);
return Data_Wrap_Struct(rb_cCall, GC_NOT_MARKED, grpc_rb_call_destroy, c);
}

@ -46,7 +46,6 @@ static int grpc_rb_channel_create_in_process_add_args_hash_cb(VALUE key,
grpc_channel_args* args;
switch (TYPE(key)) {
case T_STRING:
the_key = StringValuePtr(key);
break;
@ -70,7 +69,6 @@ static int grpc_rb_channel_create_in_process_add_args_hash_cb(VALUE key,
args->args[args->num_args - 1].key = (char*)the_key;
switch (TYPE(val)) {
case T_SYMBOL:
args->args[args->num_args - 1].type = GRPC_ARG_STRING;
args->args[args->num_args - 1].value.string =
@ -109,7 +107,6 @@ typedef struct channel_convert_params {
grpc_channel_args* dst;
} channel_convert_params;
static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) {
ID id_size = rb_intern("size");
VALUE rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);

@ -49,5 +49,4 @@
void grpc_rb_hash_convert_to_channel_args(VALUE src_hash,
grpc_channel_args* dst);
#endif /* GRPC_RB_CHANNEL_ARGS_H_ */

@ -49,29 +49,24 @@ typedef struct next_call_stack {
} next_call_stack;
/* Calls grpc_completion_queue_next without holding the ruby GIL */
static void *grpc_rb_completion_queue_next_no_gil(
next_call_stack *next_call) {
next_call->event = grpc_completion_queue_next(next_call->cq,
next_call->timeout);
static void *grpc_rb_completion_queue_next_no_gil(next_call_stack *next_call) {
next_call->event =
grpc_completion_queue_next(next_call->cq, next_call->timeout);
return NULL;
}
/* Calls grpc_completion_queue_pluck without holding the ruby GIL */
static void *grpc_rb_completion_queue_pluck_no_gil(
next_call_stack *next_call) {
next_call->event = grpc_completion_queue_pluck(next_call->cq,
next_call->tag,
static void *grpc_rb_completion_queue_pluck_no_gil(next_call_stack *next_call) {
next_call->event = grpc_completion_queue_pluck(next_call->cq, next_call->tag,
next_call->timeout);
return NULL;
}
/* Shuts down and drains the completion queue if necessary.
*
* This is done when the ruby completion queue object is about to be GCed.
*/
static void grpc_rb_completion_queue_shutdown_drain(
grpc_completion_queue* cq) {
static void grpc_rb_completion_queue_shutdown_drain(grpc_completion_queue *cq) {
next_call_stack next_call;
grpc_completion_type type;
int drained = 0;
@ -122,11 +117,10 @@ static void grpc_rb_completion_queue_destroy(void *p) {
static VALUE grpc_rb_completion_queue_alloc(VALUE cls) {
grpc_completion_queue *cq = grpc_completion_queue_create();
if (cq == NULL) {
rb_raise(rb_eArgError,
"could not create a completion queue: not sure why");
rb_raise(rb_eArgError, "could not create a completion queue: not sure why");
}
return Data_Wrap_Struct(cls, GC_NOT_MARKED,
grpc_rb_completion_queue_destroy, cq);
return Data_Wrap_Struct(cls, GC_NOT_MARKED, grpc_rb_completion_queue_destroy,
cq);
}
/* Blocks until the next event is available, and returns the event. */
@ -166,9 +160,8 @@ static VALUE grpc_rb_completion_queue_pluck(VALUE self, VALUE tag,
VALUE rb_cCompletionQueue = Qnil;
void Init_google_rpc_completion_queue() {
rb_cCompletionQueue = rb_define_class_under(rb_mGoogleRpcCore,
"CompletionQueue",
rb_cObject);
rb_cCompletionQueue =
rb_define_class_under(rb_mGoogleRpcCore, "CompletionQueue", rb_cObject);
/* constructor: uses an alloc func without an initializer. Using a simple
alloc func works here as the grpc header does not specify any args for
@ -176,12 +169,12 @@ void Init_google_rpc_completion_queue() {
rb_define_alloc_func(rb_cCompletionQueue, grpc_rb_completion_queue_alloc);
/* Add the next method that waits for the next event. */
rb_define_method(rb_cCompletionQueue, "next",
grpc_rb_completion_queue_next, 1);
rb_define_method(rb_cCompletionQueue, "next", grpc_rb_completion_queue_next,
1);
/* Add the pluck method that waits for the next event of given tag */
rb_define_method(rb_cCompletionQueue, "pluck",
grpc_rb_completion_queue_pluck, 2);
rb_define_method(rb_cCompletionQueue, "pluck", grpc_rb_completion_queue_pluck,
2);
}
/* Gets the wrapped completion queue from the ruby wrapper */

@ -40,7 +40,6 @@
#include "rb_grpc.h"
/* grpc_rb_credentials wraps a grpc_credentials. It provides a
* peer ruby object, 'mark' to minimize copying when a credential is
* created from ruby. */
@ -92,8 +91,7 @@ static VALUE grpc_rb_credentials_alloc(VALUE cls) {
wrapper->wrapped = NULL;
wrapper->mark = Qnil;
return Data_Wrap_Struct(cls, grpc_rb_credentials_mark,
grpc_rb_credentials_free,
wrapper);
grpc_rb_credentials_free, wrapper);
}
/* Clones Credentials instances.
@ -111,8 +109,7 @@ static VALUE grpc_rb_credentials_init_copy(VALUE copy, VALUE orig) {
/* Raise an error if orig is not a credentials object or a subclass. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_credentials_free) {
rb_raise(rb_eTypeError, "not a %s",
rb_obj_classname(rb_cCredentials));
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(rb_cCredentials));
}
Data_Get_Struct(orig, grpc_rb_credentials, orig_cred);
@ -238,14 +235,12 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain));
} else if (pem_private_key == Qnil) {
creds = grpc_ssl_credentials_create(
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs),
NULL, 0,
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs), NULL, 0,
RSTRING_PTR(pem_cert_chain), RSTRING_LEN(pem_cert_chain));
} else {
creds = grpc_ssl_credentials_create(
RSTRING_PTR(pem_root_certs), RSTRING_LEN(pem_root_certs),
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key),
NULL, 0);
RSTRING_PTR(pem_private_key), RSTRING_LEN(pem_private_key), NULL, 0);
}
if (creds == NULL) {
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why");
@ -265,15 +260,14 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) {
VALUE rb_cCredentials = Qnil;
void Init_google_rpc_credentials() {
rb_cCredentials = rb_define_class_under(rb_mGoogleRpcCore, "Credentials",
rb_cObject);
rb_cCredentials =
rb_define_class_under(rb_mGoogleRpcCore, "Credentials", rb_cObject);
/* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(rb_cCredentials, grpc_rb_credentials_alloc);
/* Provides a ruby constructor and support for dup/clone. */
rb_define_method(rb_cCredentials, "initialize",
grpc_rb_credentials_init, -1);
rb_define_method(rb_cCredentials, "initialize", grpc_rb_credentials_init, -1);
rb_define_method(rb_cCredentials, "initialize_copy",
grpc_rb_credentials_init_copy, 1);

@ -50,7 +50,6 @@ typedef struct grpc_rb_event {
grpc_event *wrapped;
} grpc_rb_event;
/* rb_mCompletionType is a ruby module that holds the completion type values */
VALUE rb_mCompletionType = Qnil;
@ -129,8 +128,8 @@ static VALUE grpc_rb_event_type(VALUE self) {
return rb_const_get(rb_mCompletionType, rb_intern("SERVER_RPC_NEW"));
default:
rb_raise(rb_eRuntimeError,
"unrecognized event code for an rpc event:%d", event->type);
rb_raise(rb_eRuntimeError, "unrecognized event code for an rpc event:%d",
event->type);
}
return Qnil; /* should not be reached */
}
@ -189,7 +188,6 @@ static VALUE grpc_rb_event_metadata(VALUE self) {
/* Figure out which metadata to read. */
event = wrapper->wrapped;
switch (event->type) {
case GRPC_CLIENT_METADATA_READ:
count = event->data.client_metadata_read.count;
metadata = event->data.client_metadata_read.elements;
@ -218,22 +216,18 @@ static VALUE grpc_rb_event_metadata(VALUE self) {
key = rb_str_new2(metadata[i].key);
value = rb_hash_aref(result, key);
if (value == Qnil) {
value = rb_str_new(
metadata[i].value,
metadata[i].value_length);
value = rb_str_new(metadata[i].value, metadata[i].value_length);
rb_hash_aset(result, key, value);
} else if (TYPE(value) == T_ARRAY) {
/* Add the string to the returned array */
rb_ary_push(value, rb_str_new(
metadata[i].value,
metadata[i].value_length));
rb_ary_push(value,
rb_str_new(metadata[i].value, metadata[i].value_length));
} else {
/* Add the current value with this key and the new one to an array */
new_ary = rb_ary_new();
rb_ary_push(new_ary, value);
rb_ary_push(new_ary, rb_str_new(
metadata[i].value,
metadata[i].value_length));
rb_ary_push(new_ary,
rb_str_new(metadata[i].value, metadata[i].value_length));
rb_hash_aset(result, key, new_ary);
}
}
@ -252,7 +246,6 @@ static VALUE grpc_rb_event_result(VALUE self) {
event = wrapper->wrapped;
switch (event->type) {
case GRPC_QUEUE_SHUTDOWN:
return Qnil;
@ -287,29 +280,24 @@ static VALUE grpc_rb_event_result(VALUE self) {
return grpc_rb_event_metadata(self);
case GRPC_FINISHED:
return rb_struct_new(
rb_sStatus,
UINT2NUM(event->data.finished.status),
(event->data.finished.details == NULL ?
Qnil : rb_str_new2(event->data.finished.details)),
grpc_rb_event_metadata(self),
NULL);
return rb_struct_new(rb_sStatus, UINT2NUM(event->data.finished.status),
(event->data.finished.details == NULL
? Qnil
: rb_str_new2(event->data.finished.details)),
grpc_rb_event_metadata(self), NULL);
break;
case GRPC_SERVER_RPC_NEW:
return rb_struct_new(
rb_sNewServerRpc,
rb_str_new2(event->data.server_rpc_new.method),
rb_sNewServerRpc, rb_str_new2(event->data.server_rpc_new.method),
rb_str_new2(event->data.server_rpc_new.host),
Data_Wrap_Struct(
rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
(void *)&event->data.server_rpc_new.deadline),
grpc_rb_event_metadata(self),
NULL);
grpc_rb_event_metadata(self), NULL);
default:
rb_raise(rb_eRuntimeError,
"unrecognized event code for an rpc event:%d", event->type);
rb_raise(rb_eRuntimeError, "unrecognized event code for an rpc event:%d",
event->type);
}
return Qfalse;
@ -337,8 +325,8 @@ VALUE rb_cEvent = Qnil;
VALUE rb_eEventError = Qnil;
void Init_google_rpc_event() {
rb_eEventError = rb_define_class_under(rb_mGoogleRpcCore, "EventError",
rb_eStandardError);
rb_eEventError =
rb_define_class_under(rb_mGoogleRpcCore, "EventError", rb_eStandardError);
rb_cEvent = rb_define_class_under(rb_mGoogleRpcCore, "Event", rb_cObject);
/* Prevent allocation or inialization from ruby. */
@ -355,8 +343,8 @@ void Init_google_rpc_event() {
rb_define_alias(rb_cEvent, "close", "finish");
/* Constants representing the completion types */
rb_mCompletionType = rb_define_module_under(rb_mGoogleRpcCore,
"CompletionType");
rb_mCompletionType =
rb_define_module_under(rb_mGoogleRpcCore, "CompletionType");
rb_define_const(rb_mCompletionType, "QUEUE_SHUTDOWN",
INT2NUM(GRPC_QUEUE_SHUTDOWN));
rb_define_const(rb_mCompletionType, "READ", INT2NUM(GRPC_READ));
@ -368,8 +356,7 @@ void Init_google_rpc_event() {
INT2NUM(GRPC_FINISH_ACCEPTED));
rb_define_const(rb_mCompletionType, "CLIENT_METADATA_READ",
INT2NUM(GRPC_CLIENT_METADATA_READ));
rb_define_const(rb_mCompletionType, "FINISHED",
INT2NUM(GRPC_FINISHED));
rb_define_const(rb_mCompletionType, "FINISHED", INT2NUM(GRPC_FINISHED));
rb_define_const(rb_mCompletionType, "SERVER_RPC_NEW",
INT2NUM(GRPC_SERVER_RPC_NEW));
rb_define_const(rb_mCompletionType, "RESERVED",

@ -98,7 +98,6 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
const char *want = " want <secs from epoch>|<Time>|<GRPC::TimeConst.*>";
switch (TYPE(time)) {
case T_DATA:
if (CLASS_OF(time) == rb_cTimeVal) {
Data_Get_Struct(time, gpr_timespec, time_const);
@ -107,9 +106,8 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
t.tv_sec = NUM2INT(rb_funcall(time, id_tv_sec, 0));
t.tv_nsec = NUM2INT(rb_funcall(time, id_tv_nsec, 0));
} else {
rb_raise(rb_eTypeError,
"bad input: (%s)->c_timeval, got <%s>,%s",
tstr, rb_obj_classname(time), want);
rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr,
rb_obj_classname(time), want);
}
break;
@ -148,9 +146,8 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
break;
default:
rb_raise(rb_eTypeError,
"bad input: (%s)->c_timeval, got <%s>,%s",
tstr, rb_obj_classname(time), want);
rb_raise(rb_eTypeError, "bad input: (%s)->c_timeval, got <%s>,%s", tstr,
rb_obj_classname(time), want);
break;
}
return t;
@ -158,8 +155,8 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
void Init_google_status_codes() {
/* Constants representing the status codes or grpc_status_code in status.h */
VALUE rb_mStatusCodes = rb_define_module_under(rb_mGoogleRpcCore,
"StatusCodes");
VALUE rb_mStatusCodes =
rb_define_module_under(rb_mGoogleRpcCore, "StatusCodes");
rb_define_const(rb_mStatusCodes, "OK", INT2NUM(GRPC_STATUS_OK));
rb_define_const(rb_mStatusCodes, "CANCELLED", INT2NUM(GRPC_STATUS_CANCELLED));
rb_define_const(rb_mStatusCodes, "UNKNOWN", INT2NUM(GRPC_STATUS_UNKNOWN));
@ -218,19 +215,19 @@ VALUE grpc_rb_time_val_to_s(VALUE self) {
/* Adds a module with constants that map to gpr's static timeval structs. */
void Init_google_time_consts() {
VALUE rb_mTimeConsts = rb_define_module_under(rb_mGoogleRpcCore,
"TimeConsts");
rb_cTimeVal = rb_define_class_under(rb_mGoogleRpcCore, "TimeSpec",
rb_cObject);
VALUE rb_mTimeConsts =
rb_define_module_under(rb_mGoogleRpcCore, "TimeConsts");
rb_cTimeVal =
rb_define_class_under(rb_mGoogleRpcCore, "TimeSpec", rb_cObject);
rb_define_const(rb_mTimeConsts, "ZERO",
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED,
GC_DONT_FREE, (void *)&gpr_time_0));
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_time_0));
rb_define_const(rb_mTimeConsts, "INFINITE_FUTURE",
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED,
GC_DONT_FREE, (void *)&gpr_inf_future));
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_inf_future));
rb_define_const(rb_mTimeConsts, "INFINITE_PAST",
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED,
GC_DONT_FREE, (void *)&gpr_inf_past));
Data_Wrap_Struct(rb_cTimeVal, GC_NOT_MARKED, GC_DONT_FREE,
(void *)&gpr_inf_past));
rb_define_method(rb_cTimeVal, "to_time", grpc_rb_time_val_to_time, 0);
rb_define_method(rb_cTimeVal, "inspect", grpc_rb_time_val_inspect, 0);
rb_define_method(rb_cTimeVal, "to_s", grpc_rb_time_val_to_s, 0);
@ -241,9 +238,7 @@ void Init_google_time_consts() {
id_tv_nsec = rb_intern("tv_nsec");
}
void grpc_rb_shutdown(void *vm) {
grpc_shutdown();
}
void grpc_rb_shutdown(void *vm) { grpc_shutdown(); }
/* Initialize the Google RPC module structs */

@ -48,7 +48,6 @@ typedef struct grpc_rb_metadata {
grpc_metadata *wrapped;
} grpc_rb_metadata;
/* Destroys Metadata instances. */
static void grpc_rb_metadata_free(void *p) {
if (p == NULL) {
@ -189,8 +188,8 @@ static VALUE grpc_rb_metadata_value(VALUE self) {
/* rb_cMetadata is the Metadata class whose instances proxy grpc_metadata. */
VALUE rb_cMetadata = Qnil;
void Init_google_rpc_metadata() {
rb_cMetadata = rb_define_class_under(rb_mGoogleRpcCore, "Metadata",
rb_cObject);
rb_cMetadata =
rb_define_class_under(rb_mGoogleRpcCore, "Metadata", rb_cObject);
/* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(rb_cMetadata, grpc_rb_metadata_alloc);

@ -240,8 +240,8 @@ static VALUE grpc_rb_server_add_http2_port(int argc, VALUE *argv, VALUE self) {
StringValueCStr(port));
}
} else if (TYPE(is_secure) != T_FALSE) {
added_ok = grpc_server_add_secure_http2_port(s->wrapped,
StringValueCStr(port));
added_ok =
grpc_server_add_secure_http2_port(s->wrapped, StringValueCStr(port));
if (added_ok == 0) {
rb_raise(rb_eRuntimeError,
"could not add secure port %s to server, not sure why",

@ -40,7 +40,6 @@
#include "rb_grpc.h"
/* grpc_rb_server_credentials wraps a grpc_server_credentials. It provides a
peer ruby object, 'mark' to minimize copying when a server credential is
created from ruby. */
@ -91,8 +90,7 @@ static VALUE grpc_rb_server_credentials_alloc(VALUE cls) {
wrapper->wrapped = NULL;
wrapper->mark = Qnil;
return Data_Wrap_Struct(cls, grpc_rb_server_credentials_mark,
grpc_rb_server_credentials_free,
wrapper);
grpc_rb_server_credentials_free, wrapper);
}
/* Clones ServerCredentials instances.
@ -123,7 +121,6 @@ static VALUE grpc_rb_server_credentials_init_copy(VALUE copy, VALUE orig) {
return copy;
}
/* The attribute used on the mark object to hold the pem_root_certs. */
static ID id_pem_root_certs;
@ -188,9 +185,8 @@ static VALUE grpc_rb_server_credentials_init(VALUE self, VALUE pem_root_certs,
VALUE rb_cServerCredentials = Qnil;
void Init_google_rpc_server_credentials() {
rb_cServerCredentials = rb_define_class_under(rb_mGoogleRpcCore,
"ServerCredentials",
rb_cObject);
rb_cServerCredentials =
rb_define_class_under(rb_mGoogleRpcCore, "ServerCredentials", rb_cObject);
/* Allocates an object managed by the ruby runtime */
rb_define_alloc_func(rb_cServerCredentials, grpc_rb_server_credentials_alloc);
@ -199,8 +195,7 @@ void Init_google_rpc_server_credentials() {
rb_define_method(rb_cServerCredentials, "initialize",
grpc_rb_server_credentials_init, 3);
rb_define_method(rb_cServerCredentials, "initialize_copy",
grpc_rb_server_credentials_init_copy,
1);
grpc_rb_server_credentials_init_copy, 1);
id_pem_cert_chain = rb_intern("__pem_cert_chain");
id_pem_private_key = rb_intern("__pem_private_key");

@ -2,6 +2,7 @@
# This currently builds C and C++ code.
<%!
import re
import os
proto_re = re.compile('(.*)\\.proto')
@ -355,7 +356,7 @@ buildtests_c: bins_dep_c privatelibs_c\
buildtests_cxx: bins_dep_cxx privatelibs_cxx\
% for tgt in targets:
% if tgt.build == 'test' and tgt.get('c++', False):
bins/${tgt.name}\
bins/$(CONFIG)/${tgt.name}\
% endif
% endfor
@ -687,6 +688,7 @@ libs/$(CONFIG)/lib${lib.name}.a: $(LIB${lib.name.upper()}_OBJS)
$(Q) $(AR) rcs libs/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS)
% if lib.get('baselib', False):
% if lib.get('secure', True):
$(Q) rm -rf tmp-merge
$(Q) mkdir tmp-merge
$(Q) ( cd tmp-merge ; $(AR) x ../libs/$(CONFIG)/lib${lib.name}.a )
$(Q) for l in $(OPENSSL_MERGE_LIBS) ; do ( cd tmp-merge ; <%text>ar x ../$${l}</%text> ) ; done
@ -760,6 +762,18 @@ endif
endif
% endif
% for src in lib.src:
% if not proto_re.match(src):
objs/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
% for src2 in lib.src:
% if proto_re.match(src2):
${proto_to_cc(src2)}\
% endif
% endfor
% endif
% endfor
clean_lib${lib.name}:
$(E) "[CLEAN] Cleaning lib${lib.name} files"
$(Q) $(RM) $(LIB${lib.name.upper()}_OBJS)
@ -836,6 +850,14 @@ bins/$(CONFIG)/${tgt.name}: $(${tgt.name.upper()}_OBJS)\
endif
% endif
% for src in tgt.src:
objs/$(CONFIG)/${os.path.splitext(src)[0]}.o: \
% for dep in tgt.deps:
libs/$(CONFIG)/lib${dep}.a\
% endfor
% endfor
deps_${tgt.name}: $(${tgt.name.upper()}_DEPS)
% if tgt.get('secure', True):

@ -11270,6 +11270,5 @@ unsigned char prod_roots_certs[] = {
0x33, 0x50, 0x59, 0x74, 0x6c, 0x4e, 0x58, 0x4c, 0x66, 0x62, 0x51, 0x34,
0x64, 0x64, 0x49, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44,
0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45,
0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a
};
0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a};
unsigned int prod_roots_certs_size = 134862;

@ -215,7 +215,6 @@ int main(int argc, char **argv) {
test_connect("::1", "127.0.0.1", port, 0);
test_connect("127.0.0.1", "::1", port, 0);
}
}
}

@ -131,9 +131,9 @@ static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {
/* All test configurations */
static grpc_end2end_test_config configs[] = {
{"chttp2/socketpair_one_byte_at_a_time", 0, chttp2_create_fixture_socketpair,
chttp2_init_client_socketpair, chttp2_init_server_socketpair,
chttp2_tear_down_socketpair},
{"chttp2/socketpair_one_byte_at_a_time", 0,
chttp2_create_fixture_socketpair, chttp2_init_client_socketpair,
chttp2_init_server_socketpair, chttp2_tear_down_socketpair},
};
int main(int argc, char **argv) {

@ -156,7 +156,6 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
config.tear_down_data(&f);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
int i;
canceller cancellers[2] = {grpc_call_cancel, wait_for_deadline};

@ -106,7 +106,4 @@ static void test_no_op(grpc_end2end_test_config config) {
config.tear_down_data(&f);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
test_no_op(config);
}
void grpc_end2end_tests(grpc_end2end_test_config config) { test_no_op(config); }

@ -204,7 +204,6 @@ static void test_request_response_with_metadata_and_payload(
cq_verifier_destroy(v_server);
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
test_request_response_with_metadata_and_payload(config);
}

@ -43,7 +43,6 @@ static void test_format_get_request() {
grpc_httpcli_request req;
gpr_slice slice;
memset(&req, 0, sizeof(req));
req.host = "example.com";
req.path = "/index.html";

@ -58,8 +58,8 @@ static void producer_thread(void *arg) {
for (i = 0; i < opt->iterations; i++) {
grpc_cq_begin_op(opt->cc, NULL, GRPC_WRITE_ACCEPTED);
grpc_cq_end_write_accepted(opt->cc, (void *)(gpr_intptr) 1, NULL, NULL,
NULL, GRPC_OP_OK);
grpc_cq_end_write_accepted(opt->cc, (void *)(gpr_intptr)1, NULL, NULL, NULL,
GRPC_OP_OK);
}
gpr_event_set(&opt->on_finished, (void *)(gpr_intptr)1);

@ -296,8 +296,8 @@ static void producer_thread(void *arg) {
gpr_log(GPR_INFO, "producer %d phase 2", opt->id);
for (i = 0; i < TEST_THREAD_EVENTS; i++) {
grpc_cq_end_write_accepted(opt->cc, (void *)(gpr_intptr) 1, NULL, NULL,
NULL, GRPC_OP_OK);
grpc_cq_end_write_accepted(opt->cc, (void *)(gpr_intptr)1, NULL, NULL, NULL,
GRPC_OP_OK);
opt->events_triggered++;
}

@ -34,6 +34,10 @@
#ifndef __GRPC_TEST_UTIL_PORT_H__
#define __GRPC_TEST_UTIL_PORT_H__
#ifdef __cplusplus
extern "C" {
#endif
/* pick a port number that is currently unused by either tcp or udp. return
0 on failure. */
int grpc_pick_unused_port();
@ -41,4 +45,8 @@ int grpc_pick_unused_port();
on failure. */
int grpc_pick_unused_port_or_die();
#ifdef __cplusplus
}
#endif
#endif /* __GRPC_TEST_UTIL_PORT_H__ */

@ -69,15 +69,12 @@ TEST_F(ChannelArgumentsTest, SetInt) {
key = "";
SetChannelArgs(channel_args, &args);
EXPECT_EQ(2, args.num_args);
bool found[2] = {false, false};
// We do not enforce order on the arguments.
for (int i = 0; i < args.num_args; i++) {
for (size_t i = 0; i < args.num_args; i++) {
EXPECT_EQ(GRPC_ARG_INTEGER, args.args[i].type);
if (grpc::string(args.args[i].key) == "key0") {
found[0] = true;
EXPECT_EQ(0, args.args[i].value.integer);
} else if (grpc::string(args.args[i].key) == "key1") {
found[1] = true;
EXPECT_EQ(1, args.args[i].value.integer);
}
}
@ -107,15 +104,12 @@ TEST_F(ChannelArgumentsTest, SetString) {
channel_args.SetString(key, val);
SetChannelArgs(channel_args, &args);
EXPECT_EQ(2, args.num_args);
bool found[2] = {false, false};
// We do not enforce order on the arguments.
for (int i = 0; i < args.num_args; i++) {
for (size_t i = 0; i < args.num_args; i++) {
EXPECT_EQ(GRPC_ARG_STRING, args.args[i].type);
if (grpc::string(args.args[i].key) == "key0") {
found[0] = true;
EXPECT_STREQ("val0", args.args[i].value.string);
} else if (grpc::string(args.args[i].key) == "key1") {
found[1] = true;
EXPECT_STREQ("val1", args.args[i].value.string);
}
}
@ -125,6 +119,6 @@ TEST_F(ChannelArgumentsTest, SetString) {
} // namespace grpc
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -65,7 +65,7 @@ TEST_F(CredentialsTest, InvalidServiceAccountCreds) {
} // namespace grpc
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
grpc_init();
int ret = RUN_ALL_TESTS();
grpc_shutdown();

@ -34,7 +34,7 @@
#include <chrono>
#include <thread>
#include "net/grpc/cpp/echo_duplicate_proto_cc.pb.h"
#include "test/cpp/util/echo_duplicate.pb.h"
#include "test/cpp/util/echo.pb.h"
#include "src/cpp/util/time.h"
#include <grpc++/channel_arguments.h>
@ -47,7 +47,7 @@
#include <grpc++/server_context.h>
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "net/util/netutil.h"
#include "test/core/util/port.h"
#include <gtest/gtest.h>
#include <grpc/grpc.h>
@ -141,7 +141,7 @@ class TestServiceImplDupPkg
class End2endTest : public ::testing::Test {
protected:
void SetUp() override {
int port = PickUnusedPortOrDie();
int port = grpc_pick_unused_port_or_die();
server_address_ << "localhost:" << port;
// Setup server
ServerBuilder builder;
@ -151,9 +151,7 @@ class End2endTest : public ::testing::Test {
server_ = builder.BuildAndStart();
}
void TearDown() override {
server_->Shutdown();
}
void TearDown() override { server_->Shutdown(); }
void ResetStub() {
std::shared_ptr<ChannelInterface> channel =
@ -189,7 +187,7 @@ TEST_F(End2endTest, SimpleRpc) {
TEST_F(End2endTest, MultipleRpcs) {
ResetStub();
vector<std::thread*> threads;
std::vector<std::thread*> threads;
for (int i = 0; i < 10; ++i) {
threads.push_back(new std::thread(SendRpc, stub_.get(), 10));
}

@ -31,7 +31,6 @@
*
*/
#include <chrono>
#include <memory>
#include <sstream>
@ -49,7 +48,7 @@
#include <grpc++/status.h>
#include <grpc++/stream.h>
#include "test/cpp/end2end/async_test_server.h"
#include "net/util/netutil.h"
#include "test/core/util/port.h"
#include <gtest/gtest.h>
using grpc::cpp::test::util::EchoRequest;
@ -73,7 +72,7 @@ void ServerLoop(void* s) {
class End2endTest : public ::testing::Test {
protected:
void SetUp() override {
int port = PickUnusedPortOrDie();
int port = grpc_pick_unused_port_or_die();
// TODO(yangg) protobuf has a StringPrintf, maybe use that
std::ostringstream oss;
oss << "[::]:" << port;
@ -97,9 +96,7 @@ class End2endTest : public ::testing::Test {
EXPECT_TRUE(gpr_thd_new(&id, ServerLoop, server_.get(), NULL));
}
void TearDown() override {
server_->Shutdown();
}
void TearDown() override { server_->Shutdown(); }
std::unique_ptr<AsyncTestServer> server_;
InternalStub stub_;

@ -31,7 +31,6 @@
*
*/
#include <chrono>
#include <memory>
#include <string>

@ -31,7 +31,6 @@
*
*/
#include <cassert>
#include <memory>
#include <string>
@ -46,7 +45,7 @@
#include <grpc++/client_context.h>
#include <grpc++/status.h>
#include "test/cpp/util/create_test_channel.h"
#include "test/cpp/interop/test.pb.h"
#include "test/cpp/qps/qpstest.pb.h"
DEFINE_bool(enable_ssl, false, "Whether to use ssl/tls.");
DEFINE_int32(server_port, 0, "Server port.");
@ -74,8 +73,10 @@ DEFINE_string(workload, "", "Workload parameters");
using grpc::ChannelInterface;
using grpc::CreateTestChannel;
using grpc::testing::ServerStats;
using grpc::testing::SimpleRequest;
using grpc::testing::SimpleResponse;
using grpc::testing::StatsRequest;
using grpc::testing::TestService;
static double now() {
@ -120,6 +121,14 @@ void RunTest(const int client_threads, const int client_channels,
std::vector<std::thread> threads; // Will add threads when ready to execute
std::vector<::gpr_histogram *> thread_stats(client_threads);
TestService::Stub *stub_stats = channels[0].get_stub();
grpc::ClientContext context_stats_begin;
StatsRequest stats_request;
ServerStats server_stats_begin;
stats_request.set_test_num(0);
grpc::Status status_beg = stub_stats->CollectServerStats(
&context_stats_begin, stats_request, &server_stats_begin);
for (int i = 0; i < client_threads; i++) {
gpr_histogram *hist = gpr_histogram_create(0.01, 60e9);
GPR_ASSERT(hist != NULL);
@ -161,11 +170,9 @@ void RunTest(const int client_threads, const int client_channels,
}
for (int i = 0; i < client_threads; i++) {
gpr_histogram *h = thread_stats[i];
gpr_log(GPR_INFO, "latency at thread %d (50/95/99/99.9): %f/%f/%f/%f",
i,
gpr_histogram_percentile(h, 50),
gpr_histogram_percentile(h, 95),
gpr_histogram_percentile(h, 99),
gpr_log(GPR_INFO, "latency at thread %d (50/90/95/99/99.9): %f/%f/%f/%f/%f",
i, gpr_histogram_percentile(h, 50), gpr_histogram_percentile(h, 90),
gpr_histogram_percentile(h, 95), gpr_histogram_percentile(h, 99),
gpr_histogram_percentile(h, 99.9));
gpr_histogram_merge(hist, h);
gpr_histogram_destroy(h);
@ -174,11 +181,32 @@ void RunTest(const int client_threads, const int client_channels,
gpr_log(
GPR_INFO,
"latency across %d threads with %d channels and %d payload "
"(50/95/99/99.9): %f / %f / %f / %f",
"(50/90/95/99/99.9): %f / %f / %f / %f / %f",
client_threads, client_channels, payload_size,
gpr_histogram_percentile(hist, 50), gpr_histogram_percentile(hist, 95),
gpr_histogram_percentile(hist, 99), gpr_histogram_percentile(hist, 99.9));
gpr_histogram_percentile(hist, 50), gpr_histogram_percentile(hist, 90),
gpr_histogram_percentile(hist, 95), gpr_histogram_percentile(hist, 99),
gpr_histogram_percentile(hist, 99.9));
gpr_histogram_destroy(hist);
grpc::ClientContext context_stats_end;
ServerStats server_stats_end;
grpc::Status status_end = stub_stats->CollectServerStats(
&context_stats_end, stats_request, &server_stats_end);
double elapsed = server_stats_end.time_now() - server_stats_begin.time_now();
int total_rpcs = client_threads * num_rpcs;
double utime = server_stats_end.time_user() - server_stats_begin.time_user();
double stime =
server_stats_end.time_system() - server_stats_begin.time_system();
gpr_log(GPR_INFO,
"Elapsed time: %.3f\n"
"RPC Count: %d\n"
"QPS: %.3f\n"
"System time: %.3f\n"
"User time: %.3f\n"
"Resource usage: %.1f%%\n",
elapsed, total_rpcs, total_rpcs / elapsed, stime, utime,
(stime + utime) / elapsed * 100.0);
}
int main(int argc, char **argv) {

@ -0,0 +1,158 @@
// An integration test service that covers all the method signature permutations
// of unary/streaming requests/responses.
syntax = "proto2";
package grpc.testing;
enum PayloadType {
// Compressable text format.
COMPRESSABLE= 1;
// Uncompressable binary format.
UNCOMPRESSABLE = 2;
// Randomly chosen from all other formats defined in this enum.
RANDOM = 3;
}
message StatsRequest {
// run number
optional int32 test_num = 1;
}
message ServerStats {
// wall clock time for timestamp
required double time_now = 1;
// user time used by the server process and threads
required double time_user = 2;
// server time used by the server process and all threads
required double time_system = 3;
// RPC count so far
optional int32 num_rpcs = 4;
}
message Payload {
// The type of data in body.
optional PayloadType type = 1;
// Primary contents of payload.
optional bytes body = 2;
}
message Latencies {
required double l_50 = 1;
required double l_90 = 2;
required double l_99 = 3;
required double l_999 = 4;
}
message StartArgs {
required string server_host = 1;
required int32 server_port = 2;
optional bool enable_ssl = 3 [default = false];
optional int32 client_threads = 4 [default = 1];
optional int32 client_channels = 5 [default = -1];
optional int32 num_rpcs = 6 [default = 1];
optional int32 payload_size = 7 [default = 1];
}
message StartResult {
required Latencies latencies = 1;
required int32 num_rpcs = 2;
required double time_elapsed = 3;
required double time_user = 4;
required double time_system = 5;
}
message SimpleRequest {
// Desired payload type in the response from the server.
// If response_type is RANDOM, server randomly chooses one from other formats.
optional PayloadType response_type = 1 [default=COMPRESSABLE];
// Desired payload size in the response from the server.
// If response_type is COMPRESSABLE, this denotes the size before compression.
optional int32 response_size = 2;
// Optional input payload sent along with the request.
optional Payload payload = 3;
}
message SimpleResponse {
optional Payload payload = 1;
}
message StreamingInputCallRequest {
// Optional input payload sent along with the request.
optional Payload payload = 1;
// Not expecting any payload from the response.
}
message StreamingInputCallResponse {
// Aggregated size of payloads received from the client.
optional int32 aggregated_payload_size = 1;
}
message ResponseParameters {
// Desired payload sizes in responses from the server.
// If response_type is COMPRESSABLE, this denotes the size before compression.
required int32 size = 1;
// Desired interval between consecutive responses in the response stream in
// microseconds.
required int32 interval_us = 2;
}
message StreamingOutputCallRequest {
// Desired payload type in the response from the server.
// If response_type is RANDOM, the payload from each response in the stream
// might be of different types. This is to simulate a mixed type of payload
// stream.
optional PayloadType response_type = 1 [default=COMPRESSABLE];
repeated ResponseParameters response_parameters = 2;
// Optional input payload sent along with the request.
optional Payload payload = 3;
}
message StreamingOutputCallResponse {
optional Payload payload = 1;
}
service TestService {
// Start test with specified workload
rpc StartTest(StartArgs) returns (Latencies);
// Collect stats from server, ignore request content
rpc CollectServerStats(StatsRequest) returns (ServerStats);
// One request followed by one response.
// The server returns the client payload as-is.
rpc UnaryCall(SimpleRequest) returns (SimpleResponse);
// One request followed by a sequence of responses (streamed download).
// The server returns the payload with client desired type and sizes.
rpc StreamingOutputCall(StreamingOutputCallRequest)
returns (stream StreamingOutputCallResponse);
// A sequence of requests followed by one response (streamed upload).
// The server returns the aggregated size of client payload as the result.
rpc StreamingInputCall(stream StreamingInputCallRequest)
returns (StreamingInputCallResponse);
// A sequence of requests with each request served by the server immediately.
// As one request could lead to multiple responses, this interface
// demonstrates the idea of full duplexing.
rpc FullDuplexCall(stream StreamingOutputCallRequest)
returns (stream StreamingOutputCallResponse);
// A sequence of requests followed by a sequence of responses.
// The server buffers all the client requests and then serves them in order. A
// stream of responses are returned to the client when the server starts with
// first request.
rpc HalfDuplexCall(stream StreamingOutputCallRequest)
returns (stream StreamingOutputCallResponse);
}

@ -31,6 +31,8 @@
*
*/
#include <sys/time.h>
#include <sys/resource.h>
#include <thread>
#include <google/gflags.h>
@ -41,7 +43,7 @@
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
#include <grpc++/status.h>
#include "test/cpp/interop/test.pb.h"
#include "test/cpp/qps/qpstest.pb.h"
#include <grpc/grpc.h>
#include <grpc/support/log.h>
@ -54,11 +56,17 @@ using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::testing::Payload;
using grpc::testing::PayloadType;
using grpc::testing::ServerStats;
using grpc::testing::SimpleRequest;
using grpc::testing::SimpleResponse;
using grpc::testing::StatsRequest;
using grpc::testing::TestService;
using grpc::Status;
static double time_double(struct timeval* tv) {
return tv->tv_sec + 1e-6 * tv->tv_usec;
}
bool SetPayload(PayloadType type, int size, Payload* payload) {
PayloadType response_type = type;
// TODO(yangg): Support UNCOMPRESSABLE payload.
@ -72,7 +80,21 @@ bool SetPayload(PayloadType type, int size, Payload* payload) {
}
class TestServiceImpl : public TestService::Service {
private:
int num_rpcs;
public:
Status CollectServerStats(ServerContext* context, const StatsRequest*,
ServerStats* response) {
struct rusage usage;
struct timeval tv;
gettimeofday(&tv, NULL);
getrusage(RUSAGE_SELF, &usage);
response->set_time_now(time_double(&tv));
response->set_time_user(time_double(&usage.ru_utime));
response->set_time_system(time_double(&usage.ru_stime));
return Status::OK;
}
Status UnaryCall(ServerContext* context, const SimpleRequest* request,
SimpleResponse* response) {
if (request->has_response_size() && request->response_size() > 0) {

@ -31,7 +31,6 @@
*
*/
#include <grpc++/status.h>
#include <grpc/status.h>
#include <grpc/support/log.h>

@ -31,7 +31,6 @@
*
*/
#include "src/cpp/util/time.h"
#include <chrono>

@ -0,0 +1,8 @@
#!/bin/bash
set -ex
cd $(dirname $0)/../..
for dir in src test include
do
find $dir -name '*.c' -or -name '*.cc' -or -name '*.h' | xargs clang-format -i
done

@ -39,6 +39,36 @@ _RUNNING = object()
_KILLED = object()
_COLORS = {
'red': 31,
'green': 32,
'yellow': 33,
}
_BEGINNING_OF_LINE = '\x1b[0G'
_CLEAR_LINE = '\x1b[2K'
_TAG_COLOR = {
'FAILED': 'red',
'PASSED': 'green',
'START': 'yellow',
'WAITING': 'yellow',
}
def message(tag, message, explanatory_text=None):
sys.stdout.write('%s%s\x1b[%dm%s\x1b[0m: %s%s' % (
_BEGINNING_OF_LINE,
_CLEAR_LINE,
_COLORS[_TAG_COLOR[tag]],
tag,
message,
'\n%s\n' % explanatory_text if explanatory_text is not None else ''))
sys.stdout.flush()
class Job(object):
"""Manages one job."""
@ -49,9 +79,7 @@ class Job(object):
stderr=subprocess.STDOUT,
stdout=self._tempfile)
self._state = _RUNNING
sys.stdout.write('\x1b[0G\x1b[2K\x1b[33mSTART\x1b[0m: %s' %
self._cmdline)
sys.stdout.flush()
message('START', self._cmdline)
def state(self):
"""Poll current state of the job. Prints messages at completion."""
@ -60,16 +88,10 @@ class Job(object):
self._state = _FAILURE
self._tempfile.seek(0)
stdout = self._tempfile.read()
sys.stdout.write('\x1b[0G\x1b[2K\x1b[31mFAILED\x1b[0m: %s'
' [ret=%d]\n'
'%s\n' % (
self._cmdline, self._process.returncode, stdout))
sys.stdout.flush()
message('FAILED', '%s [ret=%d]' % (self._cmdline, self._process.returncode), stdout)
else:
self._state = _SUCCESS
sys.stdout.write('\x1b[0G\x1b[2K\x1b[32mPASSED\x1b[0m: %s' %
self._cmdline)
sys.stdout.flush()
message('PASSED', '%s' % self._cmdline)
return self._state
def kill(self):
@ -86,6 +108,7 @@ class Jobset(object):
self._check_cancelled = check_cancelled
self._cancelled = False
self._failures = 0
self._completed = 0
self._maxjobs = maxjobs
def start(self, cmdline):
@ -107,8 +130,11 @@ class Jobset(object):
if st == _FAILURE: self._failures += 1
dead.add(job)
for job in dead:
self._completed += 1
self._running.remove(job)
if not dead: return
if dead: return
message('WAITING', '%d jobs running, %d complete' % (
len(self._running), self._completed))
time.sleep(0.1)
def cancelled(self):

@ -11,15 +11,44 @@ import time
import jobset
import watch_dirs
# flags required for make for each configuration
_CONFIGS = ['dbg', 'opt', 'tsan', 'msan', 'asan']
# SimpleConfig: just compile with CONFIG=config, and run the binary to test
class SimpleConfig(object):
def __init__(self, config):
self.build_config = config
def run_command(self, binary):
return [binary]
# ValgrindConfig: compile with some CONFIG=config, but use valgrind to run
class ValgrindConfig(object):
def __init__(self, config):
self.build_config = config
def run_command(self, binary):
return ['valgrind', binary]
# different configurations we can run under
_CONFIGS = {
'dbg': SimpleConfig('dbg'),
'opt': SimpleConfig('opt'),
'tsan': SimpleConfig('tsan'),
'msan': SimpleConfig('msan'),
'asan': SimpleConfig('asan'),
'valgrind': ValgrindConfig('dbg'),
}
_DEFAULT = ['dbg', 'opt']
_MAKE_TEST_TARGETS = ['buildtests_c', 'buildtests_cxx']
# parse command line
argp = argparse.ArgumentParser(description='Run grpc tests.')
argp.add_argument('-c', '--config',
choices=['all'] + _CONFIGS,
choices=['all'] + sorted(_CONFIGS.keys()),
nargs='+',
default=['all'])
default=_DEFAULT)
argp.add_argument('-t', '--test-filter', nargs='*', default=['*'])
argp.add_argument('-n', '--runs_per_test', default=1, type=int)
argp.add_argument('-f', '--forever',
@ -29,10 +58,11 @@ argp.add_argument('-f', '--forever',
args = argp.parse_args()
# grab config
configs = [cfg
run_configs = set(_CONFIGS[cfg]
for cfg in itertools.chain.from_iterable(
_CONFIGS if x == 'all' else [x]
for x in args.config)]
_CONFIGS.iterkeys() if x == 'all' else [x]
for x in args.config))
build_configs = set(cfg.build_config for cfg in run_configs)
filters = args.test_filter
runs_per_test = args.runs_per_test
forever = args.forever
@ -44,19 +74,22 @@ def _build_and_run(check_cancelled):
if not jobset.run(
(['make',
'-j', '%d' % (multiprocessing.cpu_count() + 1),
'buildtests_c',
target,
'CONFIG=%s' % cfg]
for cfg in configs), check_cancelled, maxjobs=1):
for cfg in build_configs
for target in _MAKE_TEST_TARGETS),
check_cancelled, maxjobs=1):
sys.exit(1)
# run all the tests
jobset.run(([x]
for x in itertools.chain.from_iterable(
itertools.chain.from_iterable(itertools.repeat(
glob.glob('bins/%s/%s_test' % (config, filt)),
runs_per_test))
for config in configs
for filt in filters)), check_cancelled)
jobset.run((
config.run_command(x)
for config in run_configs
for filt in filters
for x in itertools.chain.from_iterable(itertools.repeat(
glob.glob('bins/%s/%s_test' % (
config.build_config, filt)),
runs_per_test))), check_cancelled)
if forever:

Loading…
Cancel
Save