Merge github.com:google/grpc

changes/47/217547/1
Craig Tiller 10 years ago
commit a311bb6e47
  1. 4
      INSTALL
  2. 19
      Makefile
  3. 73
      README.md
  4. 6
      build.json
  5. 5
      examples/tips/client.h
  6. 17
      examples/tips/client_main.cc
  7. 2
      include/grpc++/server_credentials.h
  8. 27
      include/grpc/grpc.h
  9. 67
      include/grpc/grpc_http.h
  10. 12
      include/grpc/support/sync_generic.h
  11. 37
      src/compiler/ruby_generator.cc
  12. 101
      src/core/channel/call_op_string.c
  13. 20
      src/core/channel/census_filter.c
  14. 10
      src/core/channel/channel_args.c
  15. 30
      src/core/channel/channel_stack.c
  16. 9
      src/core/channel/channel_stack.h
  17. 11
      src/core/channel/child_channel.c
  18. 17
      src/core/channel/client_channel.c
  19. 59
      src/core/channel/connected_channel.c
  20. 26
      src/core/channel/http_client_filter.c
  21. 10
      src/core/channel/http_filter.c
  22. 158
      src/core/channel/http_server_filter.c
  23. 6
      src/core/channel/metadata_buffer.c
  24. 10
      src/core/channel/noop_filter.c
  25. 82
      src/core/httpcli/format_request.c
  26. 3
      src/core/httpcli/httpcli.c
  27. 2
      src/core/httpcli/httpcli_security_context.c
  28. 10
      src/core/iomgr/alarm_heap.c
  29. 4
      src/core/iomgr/pollset_windows.h
  30. 7
      src/core/iomgr/resolve_address.c
  31. 4
      src/core/iomgr/sockaddr_posix.h
  32. 3
      src/core/iomgr/sockaddr_utils.c
  33. 2
      src/core/iomgr/sockaddr_win32.h
  34. 2
      src/core/iomgr/socket_utils_common_posix.c
  35. 2
      src/core/iomgr/tcp_posix.c
  36. 3
      src/core/iomgr/tcp_server_posix.c
  37. 2
      src/core/security/auth.c
  38. 17
      src/core/security/credentials.c
  39. 6
      src/core/security/credentials.h
  40. 2
      src/core/security/json_token.c
  41. 2
      src/core/security/secure_endpoint.c
  42. 2
      src/core/security/security_context.c
  43. 2
      src/core/statistics/census_rpc_stats.c
  44. 2
      src/core/statistics/census_tracing.c
  45. 2
      src/core/support/cmdline.c
  46. 7
      src/core/support/histogram.c
  47. 2
      src/core/support/host_port.c
  48. 6
      src/core/support/murmur_hash.c
  49. 80
      src/core/support/string.c
  50. 32
      src/core/support/string.h
  51. 11
      src/core/surface/byte_buffer.c
  52. 199
      src/core/surface/call.c
  53. 2
      src/core/surface/call.h
  54. 2
      src/core/surface/channel.c
  55. 4
      src/core/surface/channel_create.c
  56. 21
      src/core/surface/client.c
  57. 7
      src/core/surface/completion_queue.c
  58. 82
      src/core/surface/event_string.c
  59. 21
      src/core/surface/lame_client.c
  60. 4
      src/core/surface/secure_channel_create.c
  61. 13
      src/core/surface/server.c
  62. 10
      src/core/transport/chttp2/frame_data.c
  63. 16
      src/core/transport/chttp2/frame_goaway.c
  64. 11
      src/core/transport/chttp2/frame_settings.c
  65. 2
      src/core/transport/chttp2/frame_window_update.c
  66. 36
      src/core/transport/chttp2/gen_hpack_tables.c
  67. 28
      src/core/transport/chttp2/hpack_parser.c
  68. 3
      src/core/transport/chttp2/hpack_table.c
  69. 3
      src/core/transport/chttp2/huffsyms.c
  70. 2
      src/core/transport/chttp2/stream_encoder.c
  71. 38
      src/core/transport/chttp2/timeout_encoding.c
  72. 3
      src/core/transport/chttp2/timeout_encoding.h
  73. 5
      src/core/transport/chttp2/varint.h
  74. 26
      src/core/transport/chttp2_transport.c
  75. 1
      src/core/transport/metadata.c
  76. 6
      src/core/tsi/fake_transport_security.c
  77. 6
      src/core/tsi/ssl_transport_security.c
  78. 15
      src/cpp/client/channel.cc
  79. 12
      src/cpp/stream/stream_context.cc
  80. 1
      src/cpp/stream/stream_context.h
  81. 57
      src/node/binding.gyp
  82. 7
      src/node/examples/math_server.js
  83. 0
      src/node/ext/byte_buffer.cc
  84. 0
      src/node/ext/byte_buffer.h
  85. 31
      src/node/ext/call.cc
  86. 2
      src/node/ext/call.h
  87. 0
      src/node/ext/channel.cc
  88. 0
      src/node/ext/channel.h
  89. 0
      src/node/ext/completion_queue_async_worker.cc
  90. 0
      src/node/ext/completion_queue_async_worker.h
  91. 3
      src/node/ext/credentials.cc
  92. 0
      src/node/ext/credentials.h
  93. 0
      src/node/ext/event.cc
  94. 0
      src/node/ext/event.h
  95. 2
      src/node/ext/node_grpc.cc
  96. 0
      src/node/ext/server.cc
  97. 0
      src/node/ext/server.h
  98. 0
      src/node/ext/server_credentials.cc
  99. 0
      src/node/ext/server_credentials.h
  100. 0
      src/node/ext/tag.cc
  101. Some files were not shown because too many files have changed in this diff Show More

@ -58,7 +58,7 @@ for that particular dependency if you want to reduce the libraries' size.
The recommended version of OpenSSL that provides ALPN support is available
at this URL:
https://www.openssl.org/source/openssl-1.0.2-beta3.tar.gz
https://www.openssl.org/source/openssl-1.0.2.tar.gz
Dependencies to compile and run the tests
@ -101,7 +101,7 @@ A word on OpenSSL
Secure HTTP2 requires to have the TLS extension ALPN (see rfc 7301 and
http://http2.github.io/http2-spec/ section 3.3). Our HTTP2 implementation
relies on OpenSSL's implementation. OpenSSL 1.0.2beta3 is the first version
relies on OpenSSL's implementation. OpenSSL 1.0.2 is the first released version
of OpenSSL that has ALPN support, and this explains our dependency on it.
Note that the Makefile supports compiling only the unsecure elements of grpc,

@ -1233,7 +1233,6 @@ PUBLIC_HEADERS_C += \
include/grpc/support/port_platform.h \
include/grpc/support/slice.h \
include/grpc/support/slice_buffer.h \
include/grpc/support/string.h \
include/grpc/support/sync.h \
include/grpc/support/sync_generic.h \
include/grpc/support/sync_posix.h \
@ -1396,7 +1395,7 @@ LIBGRPC_SRC = \
src/core/iomgr/pollset_multipoller_with_poll_posix.c \
src/core/iomgr/pollset_posix.c \
src/core/iomgr/pollset_windows.c \
src/core/iomgr/resolve_address_posix.c \
src/core/iomgr/resolve_address.c \
src/core/iomgr/sockaddr_utils.c \
src/core/iomgr/socket_utils_common_posix.c \
src/core/iomgr/socket_utils_linux.c \
@ -1515,7 +1514,7 @@ src/core/iomgr/pollset_kick_posix.c: $(OPENSSL_DEP)
src/core/iomgr/pollset_multipoller_with_poll_posix.c: $(OPENSSL_DEP)
src/core/iomgr/pollset_posix.c: $(OPENSSL_DEP)
src/core/iomgr/pollset_windows.c: $(OPENSSL_DEP)
src/core/iomgr/resolve_address_posix.c: $(OPENSSL_DEP)
src/core/iomgr/resolve_address.c: $(OPENSSL_DEP)
src/core/iomgr/sockaddr_utils.c: $(OPENSSL_DEP)
src/core/iomgr/socket_utils_common_posix.c: $(OPENSSL_DEP)
src/core/iomgr/socket_utils_linux.c: $(OPENSSL_DEP)
@ -1655,7 +1654,7 @@ objs/$(CONFIG)/src/core/iomgr/pollset_kick_posix.o:
objs/$(CONFIG)/src/core/iomgr/pollset_multipoller_with_poll_posix.o:
objs/$(CONFIG)/src/core/iomgr/pollset_posix.o:
objs/$(CONFIG)/src/core/iomgr/pollset_windows.o:
objs/$(CONFIG)/src/core/iomgr/resolve_address_posix.o:
objs/$(CONFIG)/src/core/iomgr/resolve_address.o:
objs/$(CONFIG)/src/core/iomgr/sockaddr_utils.o:
objs/$(CONFIG)/src/core/iomgr/socket_utils_common_posix.o:
objs/$(CONFIG)/src/core/iomgr/socket_utils_linux.o:
@ -1815,7 +1814,7 @@ LIBGRPC_UNSECURE_SRC = \
src/core/iomgr/pollset_multipoller_with_poll_posix.c \
src/core/iomgr/pollset_posix.c \
src/core/iomgr/pollset_windows.c \
src/core/iomgr/resolve_address_posix.c \
src/core/iomgr/resolve_address.c \
src/core/iomgr/sockaddr_utils.c \
src/core/iomgr/socket_utils_common_posix.c \
src/core/iomgr/socket_utils_linux.c \
@ -1938,7 +1937,7 @@ objs/$(CONFIG)/src/core/iomgr/pollset_kick_posix.o:
objs/$(CONFIG)/src/core/iomgr/pollset_multipoller_with_poll_posix.o:
objs/$(CONFIG)/src/core/iomgr/pollset_posix.o:
objs/$(CONFIG)/src/core/iomgr/pollset_windows.o:
objs/$(CONFIG)/src/core/iomgr/resolve_address_posix.o:
objs/$(CONFIG)/src/core/iomgr/resolve_address.o:
objs/$(CONFIG)/src/core/iomgr/sockaddr_utils.o:
objs/$(CONFIG)/src/core/iomgr/socket_utils_common_posix.o:
objs/$(CONFIG)/src/core/iomgr/socket_utils_linux.o:
@ -2133,9 +2132,9 @@ objs/$(CONFIG)/src/cpp/util/time.o:
LIBGRPC++_TEST_UTIL_SRC = \
gens/test/cpp/util/messages.pb.cc \
gens/test/cpp/util/echo.pb.cc \
gens/test/cpp/util/echo_duplicate.pb.cc \
gens/test/cpp/util/messages.pb.cc \
test/cpp/end2end/async_test_server.cc \
test/cpp/util/create_test_channel.cc \
@ -2152,9 +2151,9 @@ libs/$(CONFIG)/libgrpc++_test_util.a: openssl_dep_error
else
ifneq ($(OPENSSL_DEP),)
test/cpp/util/messages.proto: $(OPENSSL_DEP)
test/cpp/util/echo.proto: $(OPENSSL_DEP)
test/cpp/util/echo_duplicate.proto: $(OPENSSL_DEP)
test/cpp/util/messages.proto: $(OPENSSL_DEP)
test/cpp/end2end/async_test_server.cc: $(OPENSSL_DEP)
test/cpp/util/create_test_channel.cc: $(OPENSSL_DEP)
endif
@ -2183,8 +2182,8 @@ endif
objs/$(CONFIG)/test/cpp/end2end/async_test_server.o: gens/test/cpp/util/echo.pb.cc gens/test/cpp/util/echo_duplicate.pb.cc gens/test/cpp/util/messages.pb.cc
objs/$(CONFIG)/test/cpp/util/create_test_channel.o: gens/test/cpp/util/echo.pb.cc gens/test/cpp/util/echo_duplicate.pb.cc gens/test/cpp/util/messages.pb.cc
objs/$(CONFIG)/test/cpp/end2end/async_test_server.o: gens/test/cpp/util/messages.pb.cc gens/test/cpp/util/echo.pb.cc gens/test/cpp/util/echo_duplicate.pb.cc
objs/$(CONFIG)/test/cpp/util/create_test_channel.o: gens/test/cpp/util/messages.pb.cc gens/test/cpp/util/echo.pb.cc gens/test/cpp/util/echo_duplicate.pb.cc
LIBTIPS_CLIENT_LIB_SRC = \

@ -0,0 +1,73 @@
[gRPC - An RPC library and framework](http://github.com/google/grpc)
===================================
Copyright 2015 Google Inc.
#Installation
See grpc/INSTALL for installation instructions for various platforms.
#Overview
Remote Procedure Calls (RPCs) provide a useful abstraction for building
distributed applications and services. The libraries in this repository
provide a concrete implementation of the gRPC protocol, layered over HTTP/2.
These libraries enable communication between clients and servers using any
combination of the supported languages.
##Interface
Developers using gRPC typically start with the description of an RPC service
(a collection of methods), and generate client and server side interfaces
which they use on the client-side and implement on the server side.
By default, gRPC uses [Protocol Buffers](github.com/google/protobuf) as the
Interface Definition Language (IDL) for describing both the service interface
and the structure of the payload messages. It is possible to use other
alternatives if desired.
###Surface API
Starting from an interface definition in a .proto file, gRPC provides
Protocol Compiler plugins that generate Client- and Server-side APIs.
gRPC users typically call into these APIs on the Client side and implement
the corresponding API on the server side.
#### Synchronous vs. asynchronous
Synchronous RPC calls, that block until a response arrives from the server, are
the closest approximation to the abstraction of a procedure call that RPC
aspires to.
On the other hand, networks are inherently asynchronous and in many scenarios,
it is desirable to have the ability to start RPCs without blocking the current
thread.
The gRPC programming surface in most languages comes in both synchronous and
asynchronous flavors.
## Streaming
gRPC supports streaming semantics, where either the client or the server (or both)
send a stream of messages on a single RPC call. The most general case is
Bidirectional Streaming where a single gRPC call establishes a stream where both
the client and the server can send a stream of messages to each other. The streamed
messages are delivered in the order they were sent.
#Protocol
The gRPC protocol specifies the abstract requirements for communication between
clients and servers. A concrete embedding over HTTP/2 completes the picture by
fleshing out the details of each of the required operations.
## Abstract gRPC protocol
A gRPC RPC comprises of a bidirectional stream of messages, initiated by the client. In the client-to-server direction, this stream begins with a mandatory `Call Header`, followed by optional `Initial-Metadata`, followed by zero or more `Payload Messages`. The server-to-client direction contains an optional `Initial-Metadata`, followed by zero or more `Payload Messages` terminated with a mandatory `Status` and optional `Status-Metadata` (a.k.a.,`Trailing-Metadata`).
## Implementation over HTTP/2
The abstract protocol defined above is implemented over [HTTP/2](https://http2.github.io/). gRPC bidirectional streams are mapped to HTTP/2 streams. The contents of `Call Header` and `Initial Metadata` are sent as HTTP/2 headers and subject to HPAC compression. `Payload Messages` are serialized into a byte stream of length prefixed gRPC frames which are then fragmented into HTTP/2 frames at the sender and reassembled at the receiver. `Status` and `Trailing-Metadata` are sent as HTTP/2 trailing headers (a.k.a., trailers).
## Flow Control
gRPC inherits the flow control mchanims in HTTP/2 and uses them to enable fine-grained control of the amount of memory used for buffering in-flight messages.

@ -129,7 +129,7 @@
"src/core/iomgr/pollset_multipoller_with_poll_posix.c",
"src/core/iomgr/pollset_posix.c",
"src/core/iomgr/pollset_windows.c",
"src/core/iomgr/resolve_address_posix.c",
"src/core/iomgr/resolve_address.c",
"src/core/iomgr/sockaddr_utils.c",
"src/core/iomgr/socket_utils_common_posix.c",
"src/core/iomgr/socket_utils_linux.c",
@ -202,7 +202,6 @@
"include/grpc/support/port_platform.h",
"include/grpc/support/slice.h",
"include/grpc/support/slice_buffer.h",
"include/grpc/support/string.h",
"include/grpc/support/sync.h",
"include/grpc/support/sync_generic.h",
"include/grpc/support/sync_posix.h",
@ -218,6 +217,7 @@
"headers": [
"src/core/support/cpu.h",
"src/core/support/murmur_hash.h",
"src/core/support/string.h",
"src/core/support/thd_internal.h"
],
"src": [
@ -405,9 +405,9 @@
"build": "private",
"language": "c++",
"src": [
"test/cpp/util/messages.proto",
"test/cpp/util/echo.proto",
"test/cpp/util/echo_duplicate.proto",
"test/cpp/util/messages.proto",
"test/cpp/end2end/async_test_server.cc",
"test/cpp/util/create_test_channel.cc"
]

@ -31,6 +31,9 @@
*
*/
#ifndef __GRPCPP_EXAMPLES_TIPS_CLIENT_H_
#define __GRPCPP_EXAMPLES_TIPS_CLIENT_H_
#include <grpc++/channel_interface.h>
#include <grpc++/status.h>
@ -52,3 +55,5 @@ class Client {
} // namespace tips
} // namespace examples
} // namespace grpc
#endif // __GRPCPP_EXAMPLES_TIPS_CLIENT_H_

@ -41,30 +41,29 @@
#include "examples/tips/client.h"
#include "test/cpp/util/create_test_channel.h"
DEFINE_bool(enable_ssl, true, "Whether to use ssl/tls.");
DEFINE_bool(use_prod_roots, true, "True to use SSL roots for production GFE");
DEFINE_int32(server_port, 0, "Server port.");
DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
DEFINE_string(server_host_override, "foo.test.google.com",
"Override the server host which is sent in HTTP header");
DEFINE_int32(server_port, 443, "Server port.");
DEFINE_string(server_host,
"pubsub-staging.googleapis.com", "Server host to connect to");
int main(int argc, char** argv) {
grpc_init();
google::ParseCommandLineFlags(&argc, &argv, true);
gpr_log(GPR_INFO, "Start TIPS client");
GPR_ASSERT(FLAGS_server_port);
const int host_port_buf_size = 1024;
char host_port[host_port_buf_size];
snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(),
FLAGS_server_port);
std::shared_ptr<grpc::ChannelInterface> channel(
grpc::CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots));
grpc::CreateTestChannel(host_port,
FLAGS_server_host,
true, // enable SSL
true)); // use prod roots
grpc::examples::tips::Client client(channel);
grpc::Status s = client.CreateTopic("test");
gpr_log(GPR_INFO, "return code %d", s.code());
GPR_ASSERT(s.IsOk());
channel.reset();

@ -61,7 +61,7 @@ class ServerCredentials final {
// Options to create ServerCredentials with SSL
struct SslServerCredentialsOptions {
struct PemKeyCertPair{
struct PemKeyCertPair {
grpc::string private_key;
grpc::string cert_chain;
};

@ -158,6 +158,7 @@ typedef struct grpc_byte_buffer grpc_byte_buffer;
/* Sample helpers to obtain byte buffers (these will certainly move place */
grpc_byte_buffer *grpc_byte_buffer_create(gpr_slice *slices, size_t nslices);
grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb);
size_t grpc_byte_buffer_length(grpc_byte_buffer *bb);
void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer);
@ -182,17 +183,17 @@ typedef struct grpc_metadata {
} grpc_metadata;
typedef enum grpc_completion_type {
GRPC_QUEUE_SHUTDOWN, /* Shutting down */
GRPC_READ, /* A read has completed */
GRPC_INVOKE_ACCEPTED, /* An invoke call has been accepted by flow
control */
GRPC_WRITE_ACCEPTED, /* A write has been accepted by
flow control */
GRPC_QUEUE_SHUTDOWN, /* Shutting down */
GRPC_READ, /* A read has completed */
GRPC_INVOKE_ACCEPTED, /* An invoke call has been accepted by flow
control */
GRPC_WRITE_ACCEPTED, /* A write has been accepted by
flow control */
GRPC_FINISH_ACCEPTED, /* writes_done or write_status has been accepted */
GRPC_CLIENT_METADATA_READ, /* The metadata array sent by server received at
client */
GRPC_FINISHED, /* An RPC has finished. The event contains status.
On the server this will be OK or Cancelled. */
GRPC_FINISHED, /* An RPC has finished. The event contains status.
On the server this will be OK or Cancelled. */
GRPC_SERVER_RPC_NEW, /* A new RPC has arrived at the server */
GRPC_SERVER_SHUTDOWN, /* The server has finished shutting down */
GRPC_COMPLETION_DO_NOT_USE /* must be last, forces users to include
@ -313,18 +314,14 @@ grpc_call_error grpc_call_add_metadata(grpc_call *call, grpc_metadata *metadata,
flags is a bit-field combination of the write flags defined above.
REQUIRES: Can be called at most once per call.
Can only be called on the client.
Produces a GRPC_INVOKE_ACCEPTED event with invoke_accepted_tag when the
call has been invoked (meaning bytes can start flowing to the wire).
Produces a GRPC_CLIENT_METADATA_READ event with metadata_read_tag when
the servers initial metadata has been read.
Produces a GRPC_FINISHED event with finished_tag when the call has been
completed (there may be other events for the call pending at this
time) */
grpc_call_error grpc_call_start_invoke(grpc_call *call,
grpc_completion_queue *cq,
void *invoke_accepted_tag,
void *metadata_read_tag,
void *finished_tag, gpr_uint32 flags);
grpc_call_error grpc_call_invoke(grpc_call *call, grpc_completion_queue *cq,
void *metadata_read_tag, void *finished_tag,
gpr_uint32 flags);
/* Accept an incoming RPC, binding a completion queue to it.
To be called before sending or receiving messages.

@ -0,0 +1,67 @@
/*
*
* Copyright 2014, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef __GRPC_GRPC_HTTP_H__
#define __GRPC_GRPC_HTTP_H__
#ifdef __cplusplus
extern "C" {
#endif
/* HTTP GET support.
HTTP2 servers can publish statically generated text content served
via HTTP2 GET queries by publishing one or more grpc_http_server_page
elements via repeated GRPC_ARG_SERVE_OVER_HTTP elements in the servers
channel_args.
This is not:
- a general purpose web server
- particularly fast
It's useful for being able to serve up some static content (maybe some
javascript to be able to interact with your GRPC server?) */
typedef struct {
const char *path;
const char *content_type;
const char *content;
} grpc_http_server_page;
#define GRPC_ARG_SERVE_OVER_HTTP "grpc.serve_over_http"
#ifdef __cplusplus
}
#endif
#endif /* __GRPC_GRPC_HTTP_H__ */

@ -38,16 +38,22 @@
#include <grpc/support/atm.h>
/* gpr_event */
typedef struct { gpr_atm state; } gpr_event;
typedef struct {
gpr_atm state;
} gpr_event;
#define GPR_EVENT_INIT \
{ 0 }
/* gpr_refcount */
typedef struct { gpr_atm count; } gpr_refcount;
typedef struct {
gpr_atm count;
} gpr_refcount;
/* gpr_stats_counter */
typedef struct { gpr_atm value; } gpr_stats_counter;
typedef struct {
gpr_atm value;
} gpr_stats_counter;
#define GPR_STATS_INIT \
{ 0 }

@ -67,10 +67,9 @@ void PrintMethod(const MethodDescriptor *method, const std::string &package,
if (method->server_streaming()) {
output_type = "stream(" + output_type + ")";
}
std::map<std::string, std::string> method_vars = ListToDict({
"mth.name", method->name(), "input.type", input_type, "output.type",
output_type,
});
std::map<std::string, std::string> method_vars =
ListToDict({"mth.name", method->name(), "input.type", input_type,
"output.type", output_type, });
out->Print(method_vars, "rpc :$mth.name$, $input.type$, $output.type$\n");
}
@ -82,17 +81,15 @@ void PrintService(const ServiceDescriptor *service, const std::string &package,
}
// Begin the service module
std::map<std::string, std::string> module_vars = ListToDict({
"module.name", CapitalizeFirst(service->name()),
});
std::map<std::string, std::string> module_vars =
ListToDict({"module.name", CapitalizeFirst(service->name()), });
out->Print(module_vars, "module $module.name$\n");
out->Indent();
// TODO(temiola): add documentation
std::string doc = "TODO: add proto service documentation here";
std::map<std::string, std::string> template_vars = ListToDict({
"Documentation", doc,
});
std::map<std::string, std::string> template_vars =
ListToDict({"Documentation", doc, });
out->Print("\n");
out->Print(template_vars, "# $Documentation$\n");
out->Print("class Service\n");
@ -104,9 +101,8 @@ void PrintService(const ServiceDescriptor *service, const std::string &package,
out->Print("\n");
out->Print("self.marshal_class_method = :encode\n");
out->Print("self.unmarshal_class_method = :decode\n");
std::map<std::string, std::string> pkg_vars = ListToDict({
"service.name", service->name(), "pkg.name", package,
});
std::map<std::string, std::string> pkg_vars =
ListToDict({"service.name", service->name(), "pkg.name", package, });
out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n");
out->Print("\n");
for (int i = 0; i < service->method_count(); ++i) {
@ -137,9 +133,8 @@ std::string GetServices(const FileDescriptor *file) {
}
// Write out a file header.
std::map<std::string, std::string> header_comment_vars = ListToDict({
"file.name", file->name(), "file.package", file->package(),
});
std::map<std::string, std::string> header_comment_vars = ListToDict(
{"file.name", file->name(), "file.package", file->package(), });
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
out.Print(header_comment_vars,
"# Source: $file.name$ for package '$file.package$'\n");
@ -149,18 +144,16 @@ std::string GetServices(const FileDescriptor *file) {
// Write out require statemment to import the separately generated file
// that defines the messages used by the service. This is generated by the
// main ruby plugin.
std::map<std::string, std::string> dep_vars = ListToDict({
"dep.name", MessagesRequireName(file),
});
std::map<std::string, std::string> dep_vars =
ListToDict({"dep.name", MessagesRequireName(file), });
out.Print(dep_vars, "require '$dep.name$'\n");
// Write out services within the modules
out.Print("\n");
std::vector<std::string> modules = Split(file->package(), '.');
for (size_t i = 0; i < modules.size(); ++i) {
std::map<std::string, std::string> module_vars = ListToDict({
"module.name", CapitalizeFirst(modules[i]),
});
std::map<std::string, std::string> module_vars =
ListToDict({"module.name", CapitalizeFirst(modules[i]), });
out.Print(module_vars, "module $module.name$\n");
out.Indent();
}

@ -37,114 +37,93 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
#define MAX_APPEND 1024
static void put_metadata(gpr_strvec *b, grpc_mdelem *md) {
gpr_strvec_add(b, gpr_strdup(" key="));
gpr_strvec_add(b, gpr_hexdump((char *)GPR_SLICE_START_PTR(md->key->slice),
GPR_SLICE_LENGTH(md->key->slice), GPR_HEXDUMP_PLAINTEXT));
typedef struct {
size_t cap;
size_t len;
char *buffer;
} buf;
static void bprintf(buf *b, const char *fmt, ...) {
va_list arg;
if (b->len + MAX_APPEND > b->cap) {
b->cap = GPR_MAX(b->len + MAX_APPEND, b->cap * 3 / 2);
b->buffer = gpr_realloc(b->buffer, b->cap);
}
va_start(arg, fmt);
b->len += vsprintf(b->buffer + b->len, fmt, arg);
va_end(arg);
}
static void bputs(buf *b, const char *s) {
size_t slen = strlen(s);
if (b->len + slen + 1 > b->cap) {
b->cap = GPR_MAX(b->len + slen + 1, b->cap * 3 / 2);
b->buffer = gpr_realloc(b->buffer, b->cap);
}
strcat(b->buffer, s);
b->len += slen;
}
static void put_metadata(buf *b, grpc_mdelem *md) {
char *txt;
txt = gpr_hexdump((char *)GPR_SLICE_START_PTR(md->key->slice),
GPR_SLICE_LENGTH(md->key->slice), GPR_HEXDUMP_PLAINTEXT);
bputs(b, " key=");
bputs(b, txt);
gpr_free(txt);
txt = gpr_hexdump((char *)GPR_SLICE_START_PTR(md->value->slice),
GPR_SLICE_LENGTH(md->value->slice), GPR_HEXDUMP_PLAINTEXT);
bputs(b, " value=");
bputs(b, txt);
gpr_free(txt);
gpr_strvec_add(b, gpr_strdup(" value="));
gpr_strvec_add(b, gpr_hexdump((char *)GPR_SLICE_START_PTR(md->value->slice),
GPR_SLICE_LENGTH(md->value->slice), GPR_HEXDUMP_PLAINTEXT));
}
char *grpc_call_op_string(grpc_call_op *op) {
buf b = {0, 0, 0};
char *tmp;
char *out;
gpr_strvec b;
gpr_strvec_init(&b);
switch (op->dir) {
case GRPC_CALL_DOWN:
bprintf(&b, ">");
gpr_strvec_add(&b, gpr_strdup(">"));
break;
case GRPC_CALL_UP:
bprintf(&b, "<");
gpr_strvec_add(&b, gpr_strdup("<"));
break;
}
switch (op->type) {
case GRPC_SEND_METADATA:
bprintf(&b, "SEND_METADATA");
gpr_strvec_add(&b, gpr_strdup("SEND_METADATA"));
put_metadata(&b, op->data.metadata);
break;
case GRPC_SEND_DEADLINE:
bprintf(&b, "SEND_DEADLINE %d.%09d", op->data.deadline.tv_sec,
gpr_asprintf(&tmp, "SEND_DEADLINE %d.%09d", op->data.deadline.tv_sec,
op->data.deadline.tv_nsec);
gpr_strvec_add(&b, tmp);
break;
case GRPC_SEND_START:
bprintf(&b, "SEND_START pollset=%p", op->data.start.pollset);
gpr_asprintf(&tmp, "SEND_START pollset=%p", op->data.start.pollset);
gpr_strvec_add(&b, tmp);
break;
case GRPC_SEND_MESSAGE:
bprintf(&b, "SEND_MESSAGE");
gpr_strvec_add(&b, gpr_strdup("SEND_MESSAGE"));
break;
case GRPC_SEND_PREFORMATTED_MESSAGE:
gpr_strvec_add(&b, gpr_strdup("SEND_PREFORMATTED_MESSAGE"));
break;
case GRPC_SEND_FINISH:
bprintf(&b, "SEND_FINISH");
gpr_strvec_add(&b, gpr_strdup("SEND_FINISH"));
break;
case GRPC_REQUEST_DATA:
bprintf(&b, "REQUEST_DATA");
gpr_strvec_add(&b, gpr_strdup("REQUEST_DATA"));
break;
case GRPC_RECV_METADATA:
bprintf(&b, "RECV_METADATA");
gpr_strvec_add(&b, gpr_strdup("RECV_METADATA"));
put_metadata(&b, op->data.metadata);
break;
case GRPC_RECV_DEADLINE:
bprintf(&b, "RECV_DEADLINE %d.%09d", op->data.deadline.tv_sec,
gpr_asprintf(&tmp, "RECV_DEADLINE %d.%09d", op->data.deadline.tv_sec,
op->data.deadline.tv_nsec);
gpr_strvec_add(&b, tmp);
break;
case GRPC_RECV_END_OF_INITIAL_METADATA:
bprintf(&b, "RECV_END_OF_INITIAL_METADATA");
gpr_strvec_add(&b, gpr_strdup("RECV_END_OF_INITIAL_METADATA"));
break;
case GRPC_RECV_MESSAGE:
bprintf(&b, "RECV_MESSAGE");
gpr_strvec_add(&b, gpr_strdup("RECV_MESSAGE"));
break;
case GRPC_RECV_HALF_CLOSE:
bprintf(&b, "RECV_HALF_CLOSE");
gpr_strvec_add(&b, gpr_strdup("RECV_HALF_CLOSE"));
break;
case GRPC_RECV_FINISH:
bprintf(&b, "RECV_FINISH");
gpr_strvec_add(&b, gpr_strdup("RECV_FINISH"));
break;
case GRPC_CANCEL_OP:
bprintf(&b, "CANCEL_OP");
gpr_strvec_add(&b, gpr_strdup("CANCEL_OP"));
break;
}
bprintf(&b, " flags=0x%08x", op->flags);
gpr_asprintf(&tmp, " flags=0x%08x", op->flags);
gpr_strvec_add(&b, tmp);
out = gpr_strvec_flatten(&b, NULL);
gpr_strvec_destroy(&b);
return b.buffer;
return out;
}
void grpc_call_log_op(char *file, int line, gpr_log_severity severity,

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

@ -33,9 +33,9 @@
#include <grpc/grpc.h>
#include "src/core/channel/channel_args.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/string.h>
#include <string.h>
@ -52,7 +52,9 @@ static grpc_arg copy_arg(const grpc_arg *src) {
break;
case GRPC_ARG_POINTER:
dst.value.pointer = src->value.pointer;
dst.value.pointer.p = src->value.pointer.copy(src->value.pointer.p);
dst.value.pointer.p = src->value.pointer.copy
? src->value.pointer.copy(src->value.pointer.p)
: src->value.pointer.p;
break;
}
return dst;
@ -91,7 +93,9 @@ void grpc_channel_args_destroy(grpc_channel_args *a) {
case GRPC_ARG_INTEGER:
break;
case GRPC_ARG_POINTER:
a->args[i].value.pointer.destroy(a->args[i].value.pointer.p);
if (a->args[i].value.pointer.destroy) {
a->args[i].value.pointer.destroy(a->args[i].value.pointer.p);
}
break;
}
gpr_free(a->args[i].key);

@ -54,7 +54,7 @@
/* Given a size, round up to the next multiple of sizeof(void*) */
#define ROUND_UP_TO_ALIGNMENT_SIZE(x) \
(((x)+GPR_MAX_ALIGNMENT - 1) & ~(GPR_MAX_ALIGNMENT - 1))
(((x) + GPR_MAX_ALIGNMENT - 1) & ~(GPR_MAX_ALIGNMENT - 1))
size_t grpc_channel_stack_size(const grpc_channel_filter **filters,
size_t filter_count) {
@ -75,9 +75,9 @@ size_t grpc_channel_stack_size(const grpc_channel_filter **filters,
return size;
}
#define CHANNEL_ELEMS_FROM_STACK(stk) \
((grpc_channel_element *)((char *)(stk) + ROUND_UP_TO_ALIGNMENT_SIZE( \
sizeof(grpc_channel_stack))))
#define CHANNEL_ELEMS_FROM_STACK(stk) \
((grpc_channel_element *)( \
(char *)(stk) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_channel_stack))))
#define CALL_ELEMS_FROM_STACK(stk) \
((grpc_call_element *)((char *)(stk) + \
@ -202,6 +202,17 @@ grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem) {
static void do_nothing(void *user_data, grpc_op_error error) {}
void grpc_call_element_recv_metadata(grpc_call_element *cur_elem,
grpc_mdelem *mdelem) {
grpc_call_op metadata_op;
metadata_op.type = GRPC_RECV_METADATA;
metadata_op.dir = GRPC_CALL_UP;
metadata_op.done_cb = do_nothing;
metadata_op.user_data = NULL;
metadata_op.data.metadata = mdelem;
grpc_call_next_op(cur_elem, &metadata_op);
}
void grpc_call_element_send_metadata(grpc_call_element *cur_elem,
grpc_mdelem *mdelem) {
grpc_call_op metadata_op;
@ -209,7 +220,7 @@ void grpc_call_element_send_metadata(grpc_call_element *cur_elem,
metadata_op.dir = GRPC_CALL_DOWN;
metadata_op.done_cb = do_nothing;
metadata_op.user_data = NULL;
metadata_op.data.metadata = grpc_mdelem_ref(mdelem);
metadata_op.data.metadata = mdelem;
grpc_call_next_op(cur_elem, &metadata_op);
}
@ -221,3 +232,12 @@ void grpc_call_element_send_cancel(grpc_call_element *cur_elem) {
cancel_op.user_data = NULL;
grpc_call_next_op(cur_elem, &cancel_op);
}
void grpc_call_element_send_finish(grpc_call_element *cur_elem) {
grpc_call_op cancel_op;
cancel_op.type = GRPC_SEND_FINISH;
cancel_op.dir = GRPC_CALL_DOWN;
cancel_op.done_cb = do_nothing;
cancel_op.user_data = NULL;
grpc_call_next_op(cur_elem, &cancel_op);
}

@ -69,6 +69,8 @@ typedef enum {
GRPC_SEND_START,
/* send a message to the channels peer */
GRPC_SEND_MESSAGE,
/* send a pre-formatted message to the channels peer */
GRPC_SEND_PREFORMATTED_MESSAGE,
/* send half-close to the channels peer */
GRPC_SEND_FINISH,
/* request that more data be allowed through flow control */
@ -244,7 +246,9 @@ typedef struct {
/* A call stack tracks a set of related filters for one call, and guarantees
they live within a single malloc() allocation */
typedef struct { size_t count; } grpc_call_stack;
typedef struct {
size_t count;
} grpc_call_stack;
/* Get a channel element given a channel stack and its index */
grpc_channel_element *grpc_channel_stack_element(grpc_channel_stack *stack,
@ -292,7 +296,10 @@ void grpc_call_log_op(char *file, int line, gpr_log_severity severity,
void grpc_call_element_send_metadata(grpc_call_element *cur_elem,
grpc_mdelem *elem);
void grpc_call_element_recv_metadata(grpc_call_element *cur_elem,
grpc_mdelem *elem);
void grpc_call_element_send_cancel(grpc_call_element *cur_elem);
void grpc_call_element_send_finish(grpc_call_element *cur_elem);
#ifdef GRPC_CHANNEL_STACK_TRACE
#define GRPC_CALL_LOG_OP(sev, elem, op) grpc_call_log_op(sev, elem, op)

@ -165,14 +165,9 @@ static void lb_destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_child_channel_top_filter = {
lb_call_op, lb_channel_op,
sizeof(lb_call_data), lb_init_call_elem, lb_destroy_call_elem,
sizeof(lb_channel_data), lb_init_channel_elem, lb_destroy_channel_elem,
"child-channel",
};
lb_call_op, lb_channel_op, sizeof(lb_call_data),
lb_init_call_elem, lb_destroy_call_elem, sizeof(lb_channel_data),
lb_init_channel_elem, lb_destroy_channel_elem, "child-channel", };
/* grpc_child_channel proper */

@ -40,9 +40,9 @@
#include "src/core/channel/connected_channel.h"
#include "src/core/channel/metadata_buffer.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>
@ -410,7 +410,7 @@ static void init_channel_elem(grpc_channel_element *elem,
grpc_mdctx *metadata_context, int is_first,
int is_last) {
channel_data *chand = elem->channel_data;
char temp[16];
char temp[GPR_LTOA_MIN_BUFSIZE];
GPR_ASSERT(!is_first);
GPR_ASSERT(is_last);
@ -425,7 +425,7 @@ static void init_channel_elem(grpc_channel_element *elem,
chand->transport_setup_initiated = 0;
chand->args = grpc_channel_args_copy(args);
sprintf(temp, "%d", GRPC_STATUS_CANCELLED);
gpr_ltoa(GRPC_STATUS_CANCELLED, temp);
chand->cancel_status =
grpc_mdelem_from_strings(metadata_context, "grpc-status", temp);
}
@ -450,14 +450,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_client_channel_filter = {
call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"client-channel",
};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "client-channel", };
grpc_transport_setup_result grpc_client_channel_transport_setup_complete(
grpc_channel_stack *channel_stack, grpc_transport *transport,

@ -37,12 +37,12 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include "src/core/transport/transport.h"
#include <grpc/byte_buffer.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/string.h>
#define MAX_BUFFER_LENGTH 8192
/* the protobuf library will (by default) start warning at 100megs */
@ -69,7 +69,7 @@ typedef struct {
/* We perform a small hack to locate transport data alongside the connected
channel data in call allocations, to allow everything to be pulled in minimal
cache line requests */
#define TRANSPORT_STREAM_FROM_CALL_DATA(calld) ((grpc_stream *)((calld)+1))
#define TRANSPORT_STREAM_FROM_CALL_DATA(calld) ((grpc_stream *)((calld) + 1))
#define CALL_DATA_FROM_TRANSPORT_STREAM(transport_stream) \
(((call_data *)(transport_stream)) - 1)
@ -140,6 +140,8 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
grpc_sopb_add_begin_message(&calld->outgoing_sopb,
grpc_byte_buffer_length(op->data.message),
op->flags);
/* fall-through */
case GRPC_SEND_PREFORMATTED_MESSAGE:
copy_byte_buffer_to_stream_ops(op->data.message, &calld->outgoing_sopb);
calld->outgoing_buffer_length_estimate +=
(5 + grpc_byte_buffer_length(op->data.message));
@ -257,14 +259,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_connected_channel_filter = {
call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"connected",
};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "connected", };
static gpr_slice alloc_recv_buffer(void *user_data, grpc_transport *transport,
grpc_stream *stream, size_t size_hint) {
@ -384,23 +381,25 @@ static void recv_batch(void *user_data, grpc_transport *transport,
case GRPC_OP_BEGIN_MESSAGE:
/* can't begin a message when we're still reading a message */
if (calld->reading_message) {
char message[128];
sprintf(message,
"Message terminated early; read %d bytes, expected %d",
(int)calld->incoming_message.length,
(int)calld->incoming_message_length);
char *message = NULL;
gpr_asprintf(&message,
"Message terminated early; read %d bytes, expected %d",
(int)calld->incoming_message.length,
(int)calld->incoming_message_length);
recv_error(chand, calld, __LINE__, message);
gpr_free(message);
return;
}
/* stash away parameters, and prepare for incoming slices */
length = stream_op->data.begin_message.length;
if (length > calld->max_message_length) {
char message[128];
sprintf(
message,
char *message = NULL;
gpr_asprintf(
&message,
"Maximum message length of %d exceeded by a message of length %d",
calld->max_message_length, length);
recv_error(chand, calld, __LINE__, message);
gpr_free(message);
} else if (length > 0) {
calld->reading_message = 1;
calld->incoming_message_length = length;
@ -423,12 +422,13 @@ static void recv_batch(void *user_data, grpc_transport *transport,
gpr_slice_buffer_add(&calld->incoming_message, stream_op->data.slice);
if (calld->incoming_message.length > calld->incoming_message_length) {
/* if we got too many bytes, complain */
char message[128];
sprintf(message,
"Receiving message overflow; read %d bytes, expected %d",
(int)calld->incoming_message.length,
(int)calld->incoming_message_length);
char *message = NULL;
gpr_asprintf(&message,
"Receiving message overflow; read %d bytes, expected %d",
(int)calld->incoming_message.length,
(int)calld->incoming_message_length);
recv_error(chand, calld, __LINE__, message);
gpr_free(message);
return;
} else if (calld->incoming_message.length ==
calld->incoming_message_length) {
@ -441,11 +441,13 @@ static void recv_batch(void *user_data, grpc_transport *transport,
final_state == GRPC_STREAM_CLOSED)) {
calld->got_read_close = 1;
if (calld->reading_message) {
char message[128];
sprintf(message, "Last message truncated; read %d bytes, expected %d",
(int)calld->incoming_message.length,
(int)calld->incoming_message_length);
char *message = NULL;
gpr_asprintf(&message,
"Last message truncated; read %d bytes, expected %d",
(int)calld->incoming_message.length,
(int)calld->incoming_message_length);
recv_error(chand, calld, __LINE__, message);
gpr_free(message);
}
call_op.type = GRPC_RECV_HALF_CLOSE;
call_op.dir = GRPC_CALL_UP;
@ -503,8 +505,7 @@ static void transport_closed(void *user_data, grpc_transport *transport) {
const grpc_transport_callbacks connected_channel_transport_callbacks = {
alloc_recv_buffer, accept_stream, recv_batch,
transport_goaway, transport_closed,
};
transport_goaway, transport_closed, };
grpc_transport_setup_result grpc_connected_channel_bind_transport(
grpc_channel_stack *channel_stack, grpc_transport *transport) {

@ -35,7 +35,9 @@
#include <string.h>
#include <grpc/support/log.h>
typedef struct call_data { int sent_headers; } call_data;
typedef struct call_data {
int sent_headers;
} call_data;
typedef struct channel_data {
grpc_mdelem *te_trailers;
@ -67,8 +69,8 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
/* Send : prefixed headers, which have to be before any application
* layer headers. */
calld->sent_headers = 1;
grpc_call_element_send_metadata(elem, channeld->method);
grpc_call_element_send_metadata(elem, channeld->scheme);
grpc_call_element_send_metadata(elem, grpc_mdelem_ref(channeld->method));
grpc_call_element_send_metadata(elem, grpc_mdelem_ref(channeld->scheme));
}
grpc_call_next_op(elem, op);
break;
@ -76,12 +78,12 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
if (!calld->sent_headers) {
/* Send : prefixed headers, if we haven't already */
calld->sent_headers = 1;
grpc_call_element_send_metadata(elem, channeld->method);
grpc_call_element_send_metadata(elem, channeld->scheme);
grpc_call_element_send_metadata(elem, grpc_mdelem_ref(channeld->method));
grpc_call_element_send_metadata(elem, grpc_mdelem_ref(channeld->scheme));
}
/* Send non : prefixed headers */
grpc_call_element_send_metadata(elem, channeld->te_trailers);
grpc_call_element_send_metadata(elem, channeld->content_type);
grpc_call_element_send_metadata(elem, grpc_mdelem_ref(channeld->te_trailers));
grpc_call_element_send_metadata(elem, grpc_mdelem_ref(channeld->content_type));
grpc_call_next_op(elem, op);
break;
default:
@ -178,10 +180,6 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_http_client_filter = {
call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"http-client"};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "http-client"};

@ -132,10 +132,6 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_http_filter = {
call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"http"};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "http"};

@ -34,29 +34,80 @@
#include "src/core/channel/http_server_filter.h"
#include <string.h>
#include <grpc/grpc_http.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
typedef enum { NOT_RECEIVED, POST, GET } known_method_type;
typedef struct {
grpc_mdelem *path;
grpc_mdelem *content_type;
grpc_byte_buffer *content;
} gettable;
typedef struct call_data {
int sent_status;
int seen_scheme;
int seen_method;
int seen_te_trailers;
known_method_type seen_method;
gpr_uint8 sent_status;
gpr_uint8 seen_scheme;
gpr_uint8 seen_te_trailers;
grpc_mdelem *path;
} call_data;
typedef struct channel_data {
grpc_mdelem *te_trailers;
grpc_mdelem *method;
grpc_mdelem *method_get;
grpc_mdelem *method_post;
grpc_mdelem *http_scheme;
grpc_mdelem *https_scheme;
/* TODO(klempner): Remove this once we stop using it */
grpc_mdelem *grpc_scheme;
grpc_mdelem *content_type;
grpc_mdelem *status;
grpc_mdelem *status_ok;
grpc_mdelem *status_not_found;
grpc_mdstr *path_key;
size_t gettable_count;
gettable *gettables;
} channel_data;
/* used to silence 'variable not used' warnings */
static void ignore_unused(void *ignored) {}
/* Handle 'GET': not technically grpc, so probably a web browser hitting
us */
static void payload_done(void *elem, grpc_op_error error) {
if (error == GRPC_OP_OK) {
grpc_call_element_send_finish(elem);
}
}
static void handle_get(grpc_call_element *elem) {
channel_data *channeld = elem->channel_data;
call_data *calld = elem->call_data;
grpc_call_op op;
size_t i;
for (i = 0; i < channeld->gettable_count; i++) {
if (channeld->gettables[i].path == calld->path) {
grpc_call_element_send_metadata(elem,
grpc_mdelem_ref(channeld->status_ok));
grpc_call_element_send_metadata(
elem, grpc_mdelem_ref(channeld->gettables[i].content_type));
op.type = GRPC_SEND_PREFORMATTED_MESSAGE;
op.dir = GRPC_CALL_DOWN;
op.flags = 0;
op.data.message = channeld->gettables[i].content;
op.done_cb = payload_done;
op.user_data = elem;
grpc_call_next_op(elem, &op);
}
}
grpc_call_element_send_metadata(elem,
grpc_mdelem_ref(channeld->status_not_found));
grpc_call_element_send_finish(elem);
}
/* Called either:
- in response to an API call (or similar) from above, to send something
- a network event (or similar) from below, to receive something
@ -73,14 +124,17 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
case GRPC_RECV_METADATA:
/* Check if it is one of the headers we care about. */
if (op->data.metadata == channeld->te_trailers ||
op->data.metadata == channeld->method ||
op->data.metadata == channeld->method_get ||
op->data.metadata == channeld->method_post ||
op->data.metadata == channeld->http_scheme ||
op->data.metadata == channeld->https_scheme ||
op->data.metadata == channeld->grpc_scheme ||
op->data.metadata == channeld->content_type) {
/* swallow it */
if (op->data.metadata == channeld->method) {
calld->seen_method = 1;
if (op->data.metadata == channeld->method_get) {
calld->seen_method = GET;
} else if (op->data.metadata == channeld->method_post) {
calld->seen_method = POST;
} else if (op->data.metadata->key == channeld->http_scheme->key) {
calld->seen_scheme = 1;
} else if (op->data.metadata == channeld->te_trailers) {
@ -108,7 +162,7 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
grpc_mdelem_unref(op->data.metadata);
op->done_cb(op->user_data, GRPC_OP_OK);
} else if (op->data.metadata->key == channeld->te_trailers->key ||
op->data.metadata->key == channeld->method->key ||
op->data.metadata->key == channeld->method_post->key ||
op->data.metadata->key == channeld->http_scheme->key ||
op->data.metadata->key == channeld->content_type->key) {
gpr_log(GPR_ERROR, "Invalid %s: header: '%s'",
@ -120,6 +174,13 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
grpc_mdelem_unref(op->data.metadata);
op->done_cb(op->user_data, GRPC_OP_OK);
grpc_call_element_send_cancel(elem);
} else if (op->data.metadata->key == channeld->path_key) {
if (calld->path != NULL) {
gpr_log(GPR_ERROR, "Received :path twice");
grpc_mdelem_unref(calld->path);
}
calld->path = op->data.metadata;
op->done_cb(op->user_data, GRPC_OP_OK);
} else {
/* pass the event up */
grpc_call_next_op(elem, op);
@ -129,14 +190,21 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
/* Have we seen the required http2 transport headers?
(:method, :scheme, content-type, with :path and :authority covered
at the channel level right now) */
if (calld->seen_method && calld->seen_scheme && calld->seen_te_trailers) {
if (calld->seen_method == POST && calld->seen_scheme &&
calld->seen_te_trailers && calld->path) {
grpc_call_element_recv_metadata(elem, calld->path);
calld->path = NULL;
grpc_call_next_op(elem, op);
} else if (calld->seen_method == GET) {
handle_get(elem);
} else {
if (!calld->seen_method) {
if (calld->seen_method == NOT_RECEIVED) {
gpr_log(GPR_ERROR, "Missing :method header");
} else if (!calld->seen_scheme) {
}
if (!calld->seen_scheme) {
gpr_log(GPR_ERROR, "Missing :scheme header");
} else if (!calld->seen_te_trailers) {
}
if (!calld->seen_te_trailers) {
gpr_log(GPR_ERROR, "Missing te trailers header");
}
/* Error this call out */
@ -151,7 +219,8 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
if (!calld->sent_status) {
calld->sent_status = 1;
/* status is reffed by grpc_call_element_send_metadata */
grpc_call_element_send_metadata(elem, channeld->status);
grpc_call_element_send_metadata(elem,
grpc_mdelem_ref(channeld->status_ok));
}
grpc_call_next_op(elem, op);
break;
@ -189,9 +258,10 @@ static void init_call_elem(grpc_call_element *elem,
ignore_unused(channeld);
/* initialize members */
calld->path = NULL;
calld->sent_status = 0;
calld->seen_scheme = 0;
calld->seen_method = 0;
calld->seen_method = NOT_RECEIVED;
calld->seen_te_trailers = 0;
}
@ -201,14 +271,20 @@ static void destroy_call_elem(grpc_call_element *elem) {
call_data *calld = elem->call_data;
channel_data *channeld = elem->channel_data;
ignore_unused(calld);
ignore_unused(channeld);
if (calld->path) {
grpc_mdelem_unref(calld->path);
}
}
/* Constructor for channel_data */
static void init_channel_elem(grpc_channel_element *elem,
const grpc_channel_args *args, grpc_mdctx *mdctx,
int is_first, int is_last) {
size_t i;
size_t gettable_capacity = 0;
/* grab pointers to our data from the channel element */
channel_data *channeld = elem->channel_data;
@ -220,13 +296,40 @@ static void init_channel_elem(grpc_channel_element *elem,
/* initialize members */
channeld->te_trailers = grpc_mdelem_from_strings(mdctx, "te", "trailers");
channeld->status = grpc_mdelem_from_strings(mdctx, ":status", "200");
channeld->method = grpc_mdelem_from_strings(mdctx, ":method", "POST");
channeld->status_ok = grpc_mdelem_from_strings(mdctx, ":status", "200");
channeld->status_not_found =
grpc_mdelem_from_strings(mdctx, ":status", "404");
channeld->method_post = grpc_mdelem_from_strings(mdctx, ":method", "POST");
channeld->method_get = grpc_mdelem_from_strings(mdctx, ":method", "GET");
channeld->http_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "http");
channeld->https_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "https");
channeld->grpc_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "grpc");
channeld->path_key = grpc_mdstr_from_string(mdctx, ":path");
channeld->content_type =
grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc");
/* initialize http download support */
channeld->gettable_count = 0;
channeld->gettables = NULL;
for (i = 0; i < args->num_args; i++) {
if (0 == strcmp(args->args[i].key, GRPC_ARG_SERVE_OVER_HTTP)) {
gettable *g;
gpr_slice slice;
grpc_http_server_page *p = args->args[i].value.pointer.p;
if (channeld->gettable_count == gettable_capacity) {
gettable_capacity =
GPR_MAX(gettable_capacity * 3 / 2, gettable_capacity + 1);
channeld->gettables =
gpr_realloc(channeld->gettables, gettable_capacity * sizeof(gettable));
}
g = &channeld->gettables[channeld->gettable_count++];
g->path = grpc_mdelem_from_strings(mdctx, ":path", p->path);
g->content_type =
grpc_mdelem_from_strings(mdctx, "content-type", p->content_type);
slice = gpr_slice_from_copied_string(p->content);
g->content = grpc_byte_buffer_create(&slice, 1);
}
}
}
/* Destructor for channel data */
@ -235,19 +338,18 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
channel_data *channeld = elem->channel_data;
grpc_mdelem_unref(channeld->te_trailers);
grpc_mdelem_unref(channeld->status);
grpc_mdelem_unref(channeld->method);
grpc_mdelem_unref(channeld->status_ok);
grpc_mdelem_unref(channeld->status_not_found);
grpc_mdelem_unref(channeld->method_post);
grpc_mdelem_unref(channeld->method_get);
grpc_mdelem_unref(channeld->http_scheme);
grpc_mdelem_unref(channeld->https_scheme);
grpc_mdelem_unref(channeld->grpc_scheme);
grpc_mdelem_unref(channeld->content_type);
grpc_mdstr_unref(channeld->path_key);
}
const grpc_channel_filter grpc_http_server_filter = {
call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"http-server"};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "http-server"};

@ -61,7 +61,7 @@ struct grpc_metadata_buffer_impl {
size_t elem_cap;
};
#define ELEMS(buffer) ((qelem *)((buffer)+1))
#define ELEMS(buffer) ((qelem *)((buffer) + 1))
void grpc_metadata_buffer_init(grpc_metadata_buffer *buffer) {
/* start buffer as NULL, indicating no elements */
@ -152,7 +152,9 @@ size_t grpc_metadata_buffer_count(const grpc_metadata_buffer *buffer) {
return *buffer ? (*buffer)->elems : 0;
}
typedef struct { grpc_metadata_buffer_impl *impl; } elems_hdr;
typedef struct {
grpc_metadata_buffer_impl *impl;
} elems_hdr;
grpc_metadata *grpc_metadata_buffer_extract_elements(
grpc_metadata_buffer *buffer) {

@ -131,10 +131,6 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
const grpc_channel_filter grpc_no_op_filter = {
call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"no-op"};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "no-op"};

@ -37,67 +37,57 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/slice.h>
#include <grpc/support/useful.h>
typedef struct {
size_t length;
size_t capacity;
char *data;
} sbuf;
static void sbuf_append(sbuf *buf, const char *bytes, size_t len) {
if (buf->length + len > buf->capacity) {
buf->capacity = GPR_MAX(buf->length + len, buf->capacity * 3 / 2);
buf->data = gpr_realloc(buf->data, buf->capacity);
}
memcpy(buf->data + buf->length, bytes, len);
buf->length += len;
}
static void sbprintf(sbuf *buf, const char *fmt, ...) {
char temp[GRPC_HTTPCLI_MAX_HEADER_LENGTH];
size_t len;
va_list args;
va_start(args, fmt);
len = vsprintf(temp, fmt, args);
va_end(args);
sbuf_append(buf, temp, len);
}
static void fill_common_header(const grpc_httpcli_request *request, sbuf *buf) {
static void fill_common_header(const grpc_httpcli_request *request, gpr_strvec *buf) {
size_t i;
sbprintf(buf, "%s HTTP/1.0\r\n", request->path);
gpr_strvec_add(buf, gpr_strdup(request->path));
gpr_strvec_add(buf, gpr_strdup(" HTTP/1.0\r\n"));
/* just in case some crazy server really expects HTTP/1.1 */
sbprintf(buf, "Host: %s\r\n", request->host);
sbprintf(buf, "Connection: close\r\n");
sbprintf(buf, "User-Agent: %s\r\n", GRPC_HTTPCLI_USER_AGENT);
gpr_strvec_add(buf, gpr_strdup("Host: "));
gpr_strvec_add(buf, gpr_strdup(request->host));
gpr_strvec_add(buf, gpr_strdup("\r\n"));
gpr_strvec_add(buf, gpr_strdup("Connection: close\r\n"));
gpr_strvec_add(buf, gpr_strdup("User-Agent: "GRPC_HTTPCLI_USER_AGENT"\r\n"));
/* user supplied headers */
for (i = 0; i < request->hdr_count; i++) {
sbprintf(buf, "%s: %s\r\n", request->hdrs[i].key, request->hdrs[i].value);
gpr_strvec_add(buf, gpr_strdup(request->hdrs[i].key));
gpr_strvec_add(buf, gpr_strdup(": "));
gpr_strvec_add(buf, gpr_strdup(request->hdrs[i].value));
gpr_strvec_add(buf, gpr_strdup("\r\n"));
}
}
gpr_slice grpc_httpcli_format_get_request(const grpc_httpcli_request *request) {
sbuf out = {0, 0, NULL};
gpr_strvec out;
char *flat;
size_t flat_len;
sbprintf(&out, "GET ");
gpr_strvec_init(&out);
gpr_strvec_add(&out, gpr_strdup("GET "));
fill_common_header(request, &out);
sbprintf(&out, "\r\n");
gpr_strvec_add(&out, gpr_strdup("\r\n"));
return gpr_slice_new(out.data, out.length, gpr_free);
flat = gpr_strvec_flatten(&out, &flat_len);
gpr_strvec_destroy(&out);
return gpr_slice_new(flat, flat_len, gpr_free);
}
gpr_slice grpc_httpcli_format_post_request(const grpc_httpcli_request *request,
const char *body_bytes,
size_t body_size) {
sbuf out = {0, 0, NULL};
gpr_strvec out;
char *tmp;
size_t out_len;
size_t i;
sbprintf(&out, "POST ");
gpr_strvec_init(&out);
gpr_strvec_add(&out, gpr_strdup("POST "));
fill_common_header(request, &out);
if (body_bytes) {
gpr_uint8 has_content_type = 0;
@ -108,14 +98,18 @@ gpr_slice grpc_httpcli_format_post_request(const grpc_httpcli_request *request,
}
}
if (!has_content_type) {
sbprintf(&out, "Content-Type: text/plain\r\n");
gpr_strvec_add(&out, gpr_strdup("Content-Type: text/plain\r\n"));
}
sbprintf(&out, "Content-Length: %lu\r\n", (unsigned long)body_size);
gpr_asprintf(&tmp, "Content-Length: %lu\r\n", (unsigned long)body_size);
gpr_strvec_add(&out, tmp);
}
sbprintf(&out, "\r\n");
gpr_strvec_add(&out, gpr_strdup("\r\n"));
tmp = gpr_strvec_flatten(&out, &out_len);
if (body_bytes) {
sbuf_append(&out, body_bytes, body_size);
tmp = gpr_realloc(tmp, out_len + body_size);
memcpy(tmp + out_len, body_bytes, body_size);
out_len += body_size;
}
return gpr_slice_new(out.data, out.length, gpr_free);
return gpr_slice_new(tmp, out_len, gpr_free);
}

@ -31,6 +31,7 @@
*
*/
#include "src/core/iomgr/sockaddr.h"
#include "src/core/httpcli/httpcli.h"
#include <string.h>
@ -44,9 +45,9 @@
#include "src/core/security/security_context.h"
#include "src/core/security/google_root_certs.h"
#include "src/core/security/secure_transport_setup.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
typedef struct {
gpr_slice request_text;

@ -36,9 +36,9 @@
#include <string.h>
#include "src/core/security/secure_transport_setup.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include "src/core/tsi/ssl_transport_security.h"
typedef struct {

@ -66,11 +66,11 @@ static void adjust_downwards(grpc_alarm **first, int i, int length,
int next_i;
if (left_child >= length) break;
right_child = left_child + 1;
next_i = right_child < length &&
gpr_time_cmp(first[left_child]->deadline,
first[right_child]->deadline) < 0
? right_child
: left_child;
next_i =
right_child < length && gpr_time_cmp(first[left_child]->deadline,
first[right_child]->deadline) < 0
? right_child
: left_child;
if (gpr_time_cmp(t->deadline, first[next_i]->deadline) >= 0) break;
first[i] = first[next_i];
first[i]->heap_index = i;

@ -44,8 +44,8 @@
struct grpc_fd;
typedef struct grpc_pollset {
gpr_mu mu;
gpr_cv cv;
gpr_mu mu;
gpr_cv cv;
} grpc_pollset;
#define GRPC_POLLSET_MU(pollset) (&(pollset)->mu)

@ -33,20 +33,17 @@
#define _POSIX_SOURCE
#include "src/core/iomgr/sockaddr.h"
#include "src/core/iomgr/resolve_address.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#include <string.h>
#include "src/core/iomgr/iomgr_internal.h"
#include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/iomgr/socket_utils_posix.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/thd.h>
#include <grpc/support/time.h>

@ -34,7 +34,11 @@
#ifndef __GRPC_INTERNAL_IOMGR_SOCKADDR_POSIX_H_
#define __GRPC_INTERNAL_IOMGR_SOCKADDR_POSIX_H_
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#endif /* __GRPC_INTERNAL_IOMGR_SOCKADDR_POSIX_H_ */

@ -33,12 +33,11 @@
#include "src/core/iomgr/sockaddr_utils.h"
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/host_port.h>
#include <grpc/support/string.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>

@ -34,4 +34,6 @@
#ifndef __GRPC_INTERNAL_IOMGR_SOCKADDR_WIN32_H_
#define __GRPC_INTERNAL_IOMGR_SOCKADDR_WIN32_H_
#include <ws2tcpip.h>
#endif // __GRPC_INTERNAL_IOMGR_SOCKADDR_WIN32_H_

@ -50,8 +50,8 @@
#include <errno.h>
#include "src/core/iomgr/sockaddr_utils.h"
#include "src/core/support/string.h"
#include <grpc/support/host_port.h>
#include <grpc/support/string.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/sync.h>

@ -44,10 +44,10 @@
#include <sys/socket.h>
#include <unistd.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

@ -255,8 +255,7 @@ static int add_socket_to_server(grpc_tcp_server *s, int fd,
/* append it to the list under a lock */
if (s->nports == s->port_capacity) {
s->port_capacity *= 2;
s->ports =
gpr_realloc(s->ports, sizeof(server_port) * s->port_capacity);
s->ports = gpr_realloc(s->ports, sizeof(server_port) * s->port_capacity);
}
sp = &s->ports[s->nports++];
sp->server = s;

@ -57,7 +57,7 @@ static void on_credentials_metadata(void *user_data, grpc_mdelem **md_elems,
grpc_call_element *elem = (grpc_call_element *)user_data;
size_t i;
for (i = 0; i < num_md; i++) {
grpc_call_element_send_metadata(elem, md_elems[i]);
grpc_call_element_send_metadata(elem, grpc_mdelem_ref(md_elems[i]));
}
grpc_call_next_op(elem, &((call_data *)elem->call_data)->op);
}

@ -36,9 +36,9 @@
#include "src/core/httpcli/httpcli.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/security/json_token.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
@ -157,7 +157,7 @@ static void ssl_server_destroy(grpc_server_credentials *creds) {
if (c->config.pem_private_keys[i] != NULL) {
gpr_free(c->config.pem_private_keys[i]);
}
if (c->config.pem_cert_chains[i]!= NULL) {
if (c->config.pem_cert_chains[i] != NULL) {
gpr_free(c->config.pem_cert_chains[i]);
}
}
@ -354,7 +354,6 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
cJSON *access_token = NULL;
cJSON *token_type = NULL;
cJSON *expires_in = NULL;
size_t new_access_token_size = 0;
json = cJSON_Parse(null_terminated_body);
if (json == NULL) {
gpr_log(GPR_ERROR, "Could not parse JSON from %s", null_terminated_body);
@ -384,12 +383,8 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
new_access_token_size = strlen(token_type->valuestring) + 1 +
strlen(access_token->valuestring) + 1;
new_access_token = gpr_malloc(new_access_token_size);
/* C89 does not have snprintf :(. */
sprintf(new_access_token, "%s %s", token_type->valuestring,
access_token->valuestring);
gpr_asprintf(&new_access_token, "%s %s", token_type->valuestring,
access_token->valuestring);
token_lifetime->tv_sec = expires_in->valueint;
token_lifetime->tv_nsec = 0;
if (*token_elem != NULL) grpc_mdelem_unref(*token_elem);
@ -539,9 +534,7 @@ static void service_account_fetch_oauth2(
response_cb(metadata_req, &response);
return;
}
body = gpr_malloc(strlen(GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX) +
strlen(jwt) + 1);
sprintf(body, "%s%s", GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX, jwt);
gpr_asprintf(&body, "%s%s", GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX, jwt);
memset(&request, 0, sizeof(grpc_httpcli_request));
request.host = GRPC_SERVICE_ACCOUNT_HOST;
request.path = GRPC_SERVICE_ACCOUNT_TOKEN_PATH;

@ -118,9 +118,9 @@ grpc_credentials *grpc_credentials_contains_type(
/* Exposed for testing only. */
grpc_credentials_status
grpc_oauth2_token_fetcher_credentials_parse_server_response(
const struct grpc_httpcli_response *response, grpc_mdctx *ctx,
grpc_mdelem **token_elem, gpr_timespec *token_lifetime);
grpc_oauth2_token_fetcher_credentials_parse_server_response(
const struct grpc_httpcli_response *response, grpc_mdctx *ctx,
grpc_mdelem **token_elem, gpr_timespec *token_lifetime);
/* Simulates an oauth2 token fetch with the specified value for testing. */
grpc_credentials *grpc_fake_oauth2_credentials_create(

@ -37,9 +37,9 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include "src/core/security/base64.h"
#include "src/core/support/string.h"
#include <openssl/bio.h>
#include <openssl/evp.h>

@ -32,11 +32,11 @@
*/
#include "src/core/security/secure_endpoint.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/slice.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include "src/core/tsi/transport_security_interface.h"

@ -39,12 +39,12 @@
#include "src/core/channel/http_client_filter.h"
#include "src/core/security/credentials.h"
#include "src/core/security/secure_endpoint.h"
#include "src/core/support/string.h"
#include "src/core/surface/lame_client.h"
#include "src/core/transport/chttp2/alpn.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/string.h>
#include "src/core/tsi/fake_transport_security.h"
#include "src/core/tsi/ssl_transport_security.h"

@ -39,9 +39,9 @@
#include "src/core/statistics/census_tracing.h"
#include "src/core/statistics/window_stats.h"
#include "src/core/support/murmur_hash.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#define NUM_INTERVALS 3

@ -38,10 +38,10 @@
#include "src/core/statistics/census_rpc_stats.h"
#include "src/core/statistics/hash_table.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>

@ -37,9 +37,9 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
typedef enum { ARGTYPE_INT, ARGTYPE_BOOL, ARGTYPE_STRING } argtype;

@ -186,10 +186,9 @@ static double threshold_for_count_below(gpr_histogram *h, double count_below) {
should lie */
lower_bound = bucket_start(h, lower_idx);
upper_bound = bucket_start(h, lower_idx + 1);
return GPR_CLAMP(upper_bound -
(upper_bound - lower_bound) *
(count_so_far - count_below) /
h->buckets[lower_idx],
return GPR_CLAMP(upper_bound - (upper_bound - lower_bound) *
(count_so_far - count_below) /
h->buckets[lower_idx],
h->min_seen, h->max_seen);
}
}

@ -35,8 +35,8 @@
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/log.h>
#include <grpc/support/string.h>
int gpr_join_host_port(char **out, const char *host, int port) {
if (host[0] != '[' && strchr(host, ':') != NULL) {

@ -52,7 +52,7 @@ gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed) {
int i;
gpr_uint32 h1 = seed;
gpr_uint32 k1 = 0;
gpr_uint32 k1;
const gpr_uint32 c1 = 0xcc9e2d51;
const gpr_uint32 c2 = 0x1b873593;
@ -62,7 +62,7 @@ gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed) {
/* body */
for (i = -nblocks; i; i++) {
gpr_uint32 k1 = GETBLOCK32(blocks, i);
k1 = GETBLOCK32(blocks, i);
k1 *= c1;
k1 = ROTL32(k1, 15);
@ -73,6 +73,8 @@ gpr_uint32 gpr_murmur_hash3(const void *key, size_t len, gpr_uint32 seed) {
h1 = h1 * 5 + 0xe6546b64;
}
k1 = 0;
/* tail */
switch (len & 3) {
case 3:

@ -14,7 +14,7 @@
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
@ -31,7 +31,7 @@
*
*/
#include <grpc/support/string.h>
#include "src/core/support/string.h"
#include <ctype.h>
#include <stddef.h>
@ -122,3 +122,79 @@ int gpr_parse_bytes_to_uint32(const char *buf, size_t len, gpr_uint32 *result) {
*result = out;
return 1;
}
void gpr_reverse_bytes(char *str, int len) {
char *p1, *p2;
for (p1 = str, p2 = str + len - 1; p2 > p1; ++p1, --p2) {
char temp = *p1;
*p1 = *p2;
*p2 = temp;
}
}
int gpr_ltoa(long value, char *string) {
int i = 0;
int neg = value < 0;
if (value == 0) {
string[0] = '0';
string[1] = 0;
return 1;
}
if (neg) value = -value;
while (value) {
string[i++] = '0' + value % 10;
value /= 10;
}
if (neg) string[i++] = '-';
gpr_reverse_bytes(string, i);
string[i] = 0;
return i;
}
char *gpr_strjoin(const char **strs, size_t nstrs, size_t *final_length) {
size_t out_length = 0;
size_t i;
char *out;
for (i = 0; i < nstrs; i++) {
out_length += strlen(strs[i]);
}
out_length += 1; /* null terminator */
out = gpr_malloc(out_length);
out_length = 0;
for (i = 0; i < nstrs; i++) {
size_t slen = strlen(strs[i]);
memcpy(out + out_length, strs[i], slen);
out_length += slen;
}
out[out_length] = 0;
if (final_length != NULL) {
*final_length = out_length;
}
return out;
}
void gpr_strvec_init(gpr_strvec *sv) {
memset(sv, 0, sizeof(*sv));
}
void gpr_strvec_destroy(gpr_strvec *sv) {
size_t i;
for (i = 0; i < sv->count; i++) {
gpr_free(sv->strs[i]);
}
gpr_free(sv->strs);
}
void gpr_strvec_add(gpr_strvec *sv, char *str) {
if (sv->count == sv->capacity) {
sv->capacity = GPR_MAX(sv->capacity + 8, sv->capacity * 2);
sv->strs = gpr_realloc(sv->strs, sizeof(char*) * sv->capacity);
}
sv->strs[sv->count++] = str;
}
char *gpr_strvec_flatten(gpr_strvec *sv, size_t *final_length) {
return gpr_strjoin((const char**)sv->strs, sv->count, final_length);
}

@ -60,6 +60,17 @@ char *gpr_hexdump(const char *buf, size_t len, gpr_uint32 flags);
int gpr_parse_bytes_to_uint32(const char *data, size_t length,
gpr_uint32 *result);
/* Minimum buffer size for calling ltoa */
#define GPR_LTOA_MIN_BUFSIZE (3 * sizeof(long))
/* Convert a long to a string in base 10; returns the length of the
output string (or 0 on failure).
output must be at least GPR_LTOA_MIN_BUFSIZE bytes long. */
int gpr_ltoa(long value, char *output);
/* Reverse a run of bytes */
void gpr_reverse_bytes(char *str, int len);
/* printf to a newly-allocated string. The set of supported formats may vary
between platforms.
@ -70,6 +81,27 @@ int gpr_parse_bytes_to_uint32(const char *data, size_t length,
the result is undefined. */
int gpr_asprintf(char **strp, const char *format, ...);
/* Join a set of strings, returning the resulting string.
Total combined length (excluding null terminator) is returned in total_length
if it is non-null. */
char *gpr_strjoin(const char **strs, size_t nstrs, size_t *total_length);
/* A vector of strings... for building up a final string one piece at a time */
typedef struct {
char **strs;
size_t count;
size_t capacity;
} gpr_strvec;
/* Initialize/destroy */
void gpr_strvec_init(gpr_strvec *strs);
void gpr_strvec_destroy(gpr_strvec *strs);
/* Add a string to a strvec, takes ownership of the string */
void gpr_strvec_add(gpr_strvec *strs, char *add);
/* Return a joined string with all added substrings, optionally setting
total_length as per gpr_strjoin */
char *gpr_strvec_flatten(gpr_strvec *strs, size_t *total_length);
#ifdef __cplusplus
}
#endif

@ -49,6 +49,17 @@ grpc_byte_buffer *grpc_byte_buffer_create(gpr_slice *slices, size_t nslices) {
return bb;
}
grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb) {
switch (bb->type) {
case GRPC_BB_SLICE_BUFFER:
return grpc_byte_buffer_create(bb->data.slice_buffer.slices,
bb->data.slice_buffer.count);
}
gpr_log(GPR_INFO, "should never get here");
abort();
return NULL;
}
void grpc_byte_buffer_destroy(grpc_byte_buffer *bb) {
switch (bb->type) {
case GRPC_BB_SLICE_BUFFER:

@ -35,11 +35,11 @@
#include "src/core/channel/channel_stack.h"
#include "src/core/channel/metadata_buffer.h"
#include "src/core/iomgr/alarm.h"
#include "src/core/support/string.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/completion_queue.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <stdio.h>
#include <stdlib.h>
@ -173,11 +173,14 @@ struct grpc_call {
/* protects variables in this section */
gpr_mu read_mu;
gpr_uint8 received_start;
gpr_uint8 start_ok;
gpr_uint8 reads_done;
gpr_uint8 received_finish;
gpr_uint8 received_metadata;
gpr_uint8 have_read;
gpr_uint8 have_alarm;
gpr_uint8 pending_writes_done;
gpr_uint8 got_status_code;
/* The current outstanding read message tag (only valid if have_read == 1) */
void *read_tag;
@ -190,6 +193,8 @@ struct grpc_call {
/* The current outstanding send message/context/invoke/end tag (only valid if
have_write == 1) */
void *write_tag;
grpc_byte_buffer *pending_write;
gpr_uint32 pending_write_flags;
/* The final status of the call */
grpc_status_code status_code;
@ -198,7 +203,7 @@ struct grpc_call {
gpr_refcount internal_refcount;
};
#define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call)+1))
#define CALL_STACK_FROM_CALL(call) ((grpc_call_stack *)((call) + 1))
#define CALL_FROM_CALL_STACK(call_stack) (((grpc_call *)(call_stack)) - 1)
#define CALL_ELEM_FROM_CALL(call, idx) \
grpc_call_stack_element(CALL_STACK_FROM_CALL(call), idx)
@ -227,11 +232,15 @@ grpc_call *grpc_call_create(grpc_channel *channel,
call->have_alarm = 0;
call->received_metadata = 0;
call->got_status_code = 0;
call->start_ok = 0;
call->status_code =
server_transport_data != NULL ? GRPC_STATUS_OK : GRPC_STATUS_UNKNOWN;
call->status_details = NULL;
call->received_finish = 0;
call->reads_done = 0;
call->received_start = 0;
call->pending_write = NULL;
call->pending_writes_done = 0;
grpc_metadata_buffer_init(&call->incoming_metadata);
gpr_ref_init(&call->internal_refcount, 1);
grpc_call_stack_init(channel_stack, server_transport_data,
@ -360,16 +369,6 @@ grpc_call_error grpc_call_add_metadata(grpc_call *call, grpc_metadata *metadata,
return GRPC_CALL_OK;
}
static void done_invoke(void *user_data, grpc_op_error error) {
grpc_call *call = user_data;
void *tag = call->write_tag;
GPR_ASSERT(call->have_write);
call->have_write = 0;
call->write_tag = INVALID_TAG;
grpc_cq_end_invoke_accepted(call->cq, tag, call, NULL, NULL, error);
}
static void finish_call(grpc_call *call) {
size_t count;
grpc_metadata *elements;
@ -384,11 +383,81 @@ static void finish_call(grpc_call *call) {
elements, count);
}
grpc_call_error grpc_call_start_invoke(grpc_call *call,
grpc_completion_queue *cq,
void *invoke_accepted_tag,
void *metadata_read_tag,
void *finished_tag, gpr_uint32 flags) {
static void done_write(void *user_data, grpc_op_error error) {
grpc_call *call = user_data;
void *tag = call->write_tag;
GPR_ASSERT(call->have_write);
call->have_write = 0;
call->write_tag = INVALID_TAG;
grpc_cq_end_write_accepted(call->cq, tag, call, NULL, NULL, error);
}
static void done_writes_done(void *user_data, grpc_op_error error) {
grpc_call *call = user_data;
void *tag = call->write_tag;
GPR_ASSERT(call->have_write);
call->have_write = 0;
call->write_tag = INVALID_TAG;
grpc_cq_end_finish_accepted(call->cq, tag, call, NULL, NULL, error);
}
static void call_started(void *user_data, grpc_op_error error) {
grpc_call *call = user_data;
grpc_call_element *elem;
grpc_byte_buffer *pending_write = NULL;
gpr_uint32 pending_write_flags = 0;
gpr_uint8 pending_writes_done = 0;
int ok;
grpc_call_op op;
gpr_mu_lock(&call->read_mu);
GPR_ASSERT(!call->received_start);
call->received_start = 1;
ok = call->start_ok = (error == GRPC_OP_OK);
pending_write = call->pending_write;
pending_write_flags = call->pending_write_flags;
pending_writes_done = call->pending_writes_done;
gpr_mu_unlock(&call->read_mu);
if (pending_write) {
if (ok) {
op.type = GRPC_SEND_MESSAGE;
op.dir = GRPC_CALL_DOWN;
op.flags = pending_write_flags;
op.done_cb = done_write;
op.user_data = call;
op.data.message = pending_write;
elem = CALL_ELEM_FROM_CALL(call, 0);
elem->filter->call_op(elem, NULL, &op);
} else {
done_write(call, error);
}
grpc_byte_buffer_destroy(pending_write);
}
if (pending_writes_done) {
if (ok) {
op.type = GRPC_SEND_FINISH;
op.dir = GRPC_CALL_DOWN;
op.flags = 0;
op.done_cb = done_writes_done;
op.user_data = call;
elem = CALL_ELEM_FROM_CALL(call, 0);
elem->filter->call_op(elem, NULL, &op);
} else {
done_writes_done(call, error);
}
}
grpc_call_internal_unref(call);
}
grpc_call_error grpc_call_invoke(grpc_call *call, grpc_completion_queue *cq,
void *metadata_read_tag, void *finished_tag,
gpr_uint32 flags) {
grpc_call_element *elem;
grpc_call_op op;
@ -420,7 +489,6 @@ grpc_call_error grpc_call_start_invoke(grpc_call *call,
/* inform the completion queue of an incoming operation */
grpc_cq_begin_op(cq, call, GRPC_FINISHED);
grpc_cq_begin_op(cq, call, GRPC_CLIENT_METADATA_READ);
grpc_cq_begin_op(cq, call, GRPC_INVOKE_ACCEPTED);
gpr_mu_lock(&call->read_mu);
@ -431,8 +499,6 @@ grpc_call_error grpc_call_start_invoke(grpc_call *call,
if (call->received_finish) {
/* handle early cancellation */
grpc_cq_end_invoke_accepted(call->cq, invoke_accepted_tag, call, NULL, NULL,
GRPC_OP_ERROR);
grpc_cq_end_client_metadata_read(call->cq, metadata_read_tag, call, NULL,
NULL, 0, NULL);
finish_call(call);
@ -442,20 +508,18 @@ grpc_call_error grpc_call_start_invoke(grpc_call *call,
return GRPC_CALL_OK;
}
call->write_tag = invoke_accepted_tag;
call->metadata_tag = metadata_read_tag;
call->have_write = 1;
gpr_mu_unlock(&call->read_mu);
/* call down the filter stack */
op.type = GRPC_SEND_START;
op.dir = GRPC_CALL_DOWN;
op.flags = flags;
op.done_cb = done_invoke;
op.done_cb = call_started;
op.data.start.pollset = grpc_cq_pollset(cq);
op.user_data = call;
grpc_call_internal_ref(call);
elem = CALL_ELEM_FROM_CALL(call, 0);
elem->filter->call_op(elem, NULL, &op);
@ -486,6 +550,7 @@ grpc_call_error grpc_call_server_accept(grpc_call *call,
call->state = CALL_BOUNDCQ;
call->cq = cq;
call->finished_tag = finished_tag;
call->received_start = 1;
if (prq_is_empty(&call->prq) && call->received_finish) {
finish_call(call);
@ -535,26 +600,6 @@ grpc_call_error grpc_call_server_end_initial_metadata(grpc_call *call,
return GRPC_CALL_OK;
}
static void done_writes_done(void *user_data, grpc_op_error error) {
grpc_call *call = user_data;
void *tag = call->write_tag;
GPR_ASSERT(call->have_write);
call->have_write = 0;
call->write_tag = INVALID_TAG;
grpc_cq_end_finish_accepted(call->cq, tag, call, NULL, NULL, error);
}
static void done_write(void *user_data, grpc_op_error error) {
grpc_call *call = user_data;
void *tag = call->write_tag;
GPR_ASSERT(call->have_write);
call->have_write = 0;
call->write_tag = INVALID_TAG;
grpc_cq_end_write_accepted(call->cq, tag, call, NULL, NULL, error);
}
void grpc_call_client_initial_metadata_complete(
grpc_call_element *surface_element) {
grpc_call *call = grpc_call_from_top_element(surface_element);
@ -617,7 +662,7 @@ grpc_call_error grpc_call_start_read(grpc_call *call, void *tag) {
} else {
call->read_tag = tag;
call->have_read = 1;
request_more = 1;
request_more = call->received_start;
}
} else if (prq_is_empty(&call->prq) && call->received_finish) {
finish_call(call);
@ -654,8 +699,6 @@ grpc_call_error grpc_call_start_write(grpc_call *call,
grpc_cq_begin_op(call->cq, call, GRPC_WRITE_ACCEPTED);
/* for now we do no buffering, so a NULL byte_buffer can have no impact
on our behavior -- succeed immediately */
/* TODO(ctiller): if flags & GRPC_WRITE_BUFFER_HINT == 0, this indicates a
flush, and that flush should be propogated down from here */
if (byte_buffer == NULL) {
@ -666,15 +709,25 @@ grpc_call_error grpc_call_start_write(grpc_call *call,
call->write_tag = tag;
call->have_write = 1;
op.type = GRPC_SEND_MESSAGE;
op.dir = GRPC_CALL_DOWN;
op.flags = flags;
op.done_cb = done_write;
op.user_data = call;
op.data.message = byte_buffer;
gpr_mu_lock(&call->read_mu);
if (!call->received_start) {
call->pending_write = grpc_byte_buffer_copy(byte_buffer);
call->pending_write_flags = flags;
elem = CALL_ELEM_FROM_CALL(call, 0);
elem->filter->call_op(elem, NULL, &op);
gpr_mu_unlock(&call->read_mu);
} else {
gpr_mu_unlock(&call->read_mu);
op.type = GRPC_SEND_MESSAGE;
op.dir = GRPC_CALL_DOWN;
op.flags = flags;
op.done_cb = done_write;
op.user_data = call;
op.data.message = byte_buffer;
elem = CALL_ELEM_FROM_CALL(call, 0);
elem->filter->call_op(elem, NULL, &op);
}
return GRPC_CALL_OK;
}
@ -706,14 +759,23 @@ grpc_call_error grpc_call_writes_done(grpc_call *call, void *tag) {
call->write_tag = tag;
call->have_write = 1;
op.type = GRPC_SEND_FINISH;
op.dir = GRPC_CALL_DOWN;
op.flags = 0;
op.done_cb = done_writes_done;
op.user_data = call;
gpr_mu_lock(&call->read_mu);
if (!call->received_start) {
call->pending_writes_done = 1;
elem = CALL_ELEM_FROM_CALL(call, 0);
elem->filter->call_op(elem, NULL, &op);
gpr_mu_unlock(&call->read_mu);
} else {
gpr_mu_unlock(&call->read_mu);
op.type = GRPC_SEND_FINISH;
op.dir = GRPC_CALL_DOWN;
op.flags = 0;
op.done_cb = done_writes_done;
op.user_data = call;
elem = CALL_ELEM_FROM_CALL(call, 0);
elem->filter->call_op(elem, NULL, &op);
}
return GRPC_CALL_OK;
}
@ -760,8 +822,8 @@ grpc_call_error grpc_call_start_write_status(grpc_call *call,
/* always send status */
{
grpc_mdelem *md;
char buffer[32];
sprintf(buffer, "%d", status);
char buffer[GPR_LTOA_MIN_BUFSIZE];
gpr_ltoa(status, buffer);
md =
grpc_mdelem_from_strings(call->metadata_context, "grpc-status", buffer);
@ -801,7 +863,7 @@ static gpr_uint32 decode_status(grpc_mdelem *md) {
gpr_uint32 status;
void *user_data = grpc_mdelem_get_user_data(md, destroy_status);
if (user_data) {
status = ((gpr_uint32)(gpr_intptr) user_data) - STATUS_OFFSET;
status = ((gpr_uint32)(gpr_intptr)user_data) - STATUS_OFFSET;
} else {
if (!gpr_parse_bytes_to_uint32(grpc_mdstr_as_c_string(md->value),
GPR_SLICE_LENGTH(md->value->slice),
@ -818,6 +880,8 @@ void grpc_call_recv_metadata(grpc_call_element *elem, grpc_call_op *op) {
grpc_call *call = CALL_FROM_TOP_ELEM(elem);
grpc_mdelem *md = op->data.metadata;
grpc_mdstr *key = md->key;
gpr_log(GPR_DEBUG, "call %p got metadata %s %s", call,
grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value));
if (key == grpc_channel_get_status_string(call->channel)) {
maybe_set_status_code(call, decode_status(md));
grpc_mdelem_unref(md);
@ -917,3 +981,8 @@ void grpc_call_set_deadline(grpc_call_element *elem, gpr_timespec deadline) {
call->have_alarm = 1;
grpc_alarm_init(&call->alarm, deadline, call_alarm, call, gpr_now());
}
grpc_call_stack *grpc_call_get_call_stack(grpc_call *call) {
return CALL_STACK_FROM_CALL(call);
}

@ -64,6 +64,8 @@ void grpc_call_client_initial_metadata_complete(
void grpc_call_set_deadline(grpc_call_element *surface_element,
gpr_timespec deadline);
grpc_call_stack *grpc_call_get_call_stack(grpc_call *call);
/* Given the top call_element, get the call object. */
grpc_call *grpc_call_from_top_element(grpc_call_element *surface_element);

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

@ -31,6 +31,8 @@
*
*/
#include "src/core/iomgr/sockaddr.h"
#include <grpc/grpc.h>
#include <stdlib.h>
@ -48,10 +50,10 @@
#include "src/core/iomgr/tcp_client.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/client.h"
#include "src/core/support/string.h"
#include "src/core/transport/chttp2_transport.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>

@ -34,13 +34,17 @@
#include "src/core/surface/client.h"
#include "src/core/surface/call.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
typedef struct { void *unused; } call_data;
typedef struct {
void *unused;
} call_data;
typedef struct { void *unused; } channel_data;
typedef struct {
void *unused;
} channel_data;
static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
grpc_call_op *op) {
@ -109,11 +113,6 @@ static void init_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,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"client",
};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "client", };

@ -37,13 +37,13 @@
#include <string.h>
#include "src/core/iomgr/pollset.h"
#include "src/core/support/string.h"
#include "src/core/surface/call.h"
#include "src/core/surface/event_string.h"
#include "src/core/surface/surface_trace.h"
#include <grpc/support/alloc.h>
#include <grpc/support/atm.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#define NUM_TAG_BUCKETS 31
@ -396,12 +396,13 @@ void grpc_event_finish(grpc_event *base) {
void grpc_cq_dump_pending_ops(grpc_completion_queue *cc) {
#ifndef NDEBUG
char tmp[256];
char tmp[GRPC_COMPLETION_DO_NOT_USE * (1 + GPR_LTOA_MIN_BUFSIZE)];
char *p = tmp;
int i;
for (i = 0; i < GRPC_COMPLETION_DO_NOT_USE; i++) {
p += sprintf(p, " %d", (int)cc->pending_op_count[i]);
*p++ = ' ';
p += gpr_ltoa(cc->pending_op_count[i], p);
}
gpr_log(GPR_INFO, "pending ops:%s", tmp);

@ -35,11 +35,13 @@
#include <stdio.h>
#include <grpc/support/string.h>
#include "src/core/support/string.h"
#include <grpc/byte_buffer.h>
static size_t addhdr(char *p, grpc_event *ev) {
return sprintf(p, "tag:%p call:%p", ev->tag, (void *)ev->call);
static void addhdr(gpr_strvec *buf, grpc_event *ev) {
char *tmp;
gpr_asprintf(&tmp, "tag:%p call:%p", ev->tag, (void *)ev->call);
gpr_strvec_add(buf, tmp);
}
static const char *errstr(grpc_op_error err) {
@ -52,72 +54,84 @@ static const char *errstr(grpc_op_error err) {
return "UNKNOWN_UNKNOWN";
}
static size_t adderr(char *p, grpc_op_error err) {
return sprintf(p, " err=%s", errstr(err));
static void adderr(gpr_strvec *buf, grpc_op_error err) {
char *tmp;
gpr_asprintf(&tmp, " err=%s", errstr(err));
gpr_strvec_add(buf, tmp);
}
char *grpc_event_string(grpc_event *ev) {
char buffer[1024];
char *p = buffer;
char *out;
char *tmp;
gpr_strvec buf;
if (ev == NULL) return gpr_strdup("null");
gpr_strvec_init(&buf);
switch (ev->type) {
case GRPC_SERVER_SHUTDOWN:
p += sprintf(p, "SERVER_SHUTDOWN");
gpr_strvec_add(&buf, gpr_strdup("SERVER_SHUTDOWN"));
break;
case GRPC_QUEUE_SHUTDOWN:
p += sprintf(p, "QUEUE_SHUTDOWN");
gpr_strvec_add(&buf, gpr_strdup("QUEUE_SHUTDOWN"));
break;
case GRPC_READ:
p += sprintf(p, "READ: ");
p += addhdr(p, ev);
gpr_strvec_add(&buf, gpr_strdup("READ: "));
addhdr(&buf, ev);
if (ev->data.read) {
p += sprintf(p, " %d bytes",
gpr_asprintf(&tmp, " %d bytes",
(int)grpc_byte_buffer_length(ev->data.read));
gpr_strvec_add(&buf, tmp);
} else {
p += sprintf(p, " end-of-stream");
gpr_strvec_add(&buf, gpr_strdup(" end-of-stream"));
}
break;
case GRPC_INVOKE_ACCEPTED:
p += sprintf(p, "INVOKE_ACCEPTED: ");
p += addhdr(p, ev);
p += adderr(p, ev->data.invoke_accepted);
gpr_strvec_add(&buf, gpr_strdup("INVOKE_ACCEPTED: "));
addhdr(&buf, ev);
adderr(&buf, ev->data.invoke_accepted);
break;
case GRPC_WRITE_ACCEPTED:
p += sprintf(p, "WRITE_ACCEPTED: ");
p += addhdr(p, ev);
p += adderr(p, ev->data.write_accepted);
gpr_strvec_add(&buf, gpr_strdup("WRITE_ACCEPTED: "));
addhdr(&buf, ev);
adderr(&buf, ev->data.write_accepted);
break;
case GRPC_FINISH_ACCEPTED:
p += sprintf(p, "FINISH_ACCEPTED: ");
p += addhdr(p, ev);
p += adderr(p, ev->data.write_accepted);
gpr_strvec_add(&buf, gpr_strdup("FINISH_ACCEPTED: "));
addhdr(&buf, ev);
adderr(&buf, ev->data.write_accepted);
break;
case GRPC_CLIENT_METADATA_READ:
p += sprintf(p, "CLIENT_METADATA_READ: ");
p += addhdr(p, ev);
p += sprintf(p, " %d elements", (int)ev->data.client_metadata_read.count);
gpr_strvec_add(&buf, gpr_strdup("CLIENT_METADATA_READ: "));
addhdr(&buf, ev);
gpr_asprintf(&tmp, " %d elements",
(int)ev->data.client_metadata_read.count);
gpr_strvec_add(&buf, tmp);
break;
case GRPC_FINISHED:
p += sprintf(p, "FINISHED: ");
p += addhdr(p, ev);
p += sprintf(p, " status=%d details='%s' %d metadata elements",
gpr_strvec_add(&buf, gpr_strdup("FINISHED: "));
addhdr(&buf, ev);
gpr_asprintf(&tmp, " status=%d details='%s' %d metadata elements",
ev->data.finished.status, ev->data.finished.details,
(int)ev->data.finished.metadata_count);
gpr_strvec_add(&buf, tmp);
break;
case GRPC_SERVER_RPC_NEW:
p += sprintf(p, "SERVER_RPC_NEW: ");
p += addhdr(p, ev);
p += sprintf(p, " method='%s' host='%s' %d metadata elements",
gpr_strvec_add(&buf, gpr_strdup("SERVER_RPC_NEW: "));
addhdr(&buf, ev);
gpr_asprintf(&tmp, " method='%s' host='%s' %d metadata elements",
ev->data.server_rpc_new.method, ev->data.server_rpc_new.host,
(int)ev->data.server_rpc_new.metadata_count);
gpr_strvec_add(&buf, tmp);
break;
case GRPC_COMPLETION_DO_NOT_USE:
p += sprintf(p, "DO_NOT_USE (this is a bug)");
p += addhdr(p, ev);
gpr_strvec_add(&buf, gpr_strdup("DO_NOT_USE (this is a bug)"));
addhdr(&buf, ev);
break;
}
return gpr_strdup(buffer);
out = gpr_strvec_flatten(&buf, NULL);
gpr_strvec_destroy(&buf);
return out;
}

@ -36,15 +36,19 @@
#include <string.h>
#include "src/core/channel/channel_stack.h"
#include "src/core/support/string.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/call.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
typedef struct { void *unused; } call_data;
typedef struct {
void *unused;
} call_data;
typedef struct { grpc_mdelem *message; } channel_data;
typedef struct {
grpc_mdelem *message;
} channel_data;
static void do_nothing(void *data, grpc_op_error error) {}
@ -111,14 +115,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
static const grpc_channel_filter lame_filter = {
call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"lame-client",
};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "lame-client", };
grpc_channel *grpc_lame_client_channel_create(void) {
static const grpc_channel_filter *filters[] = {&lame_filter};

@ -31,6 +31,8 @@
*
*/
#include "src/core/iomgr/sockaddr.h"
#include <grpc/grpc.h>
#include <stdlib.h>
@ -48,13 +50,13 @@
#include "src/core/security/auth.h"
#include "src/core/security/security_context.h"
#include "src/core/security/secure_transport_setup.h"
#include "src/core/support/string.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/client.h"
#include "src/core/transport/chttp2_transport.h"
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>
#include "src/core/tsi/transport_security_interface.h"

@ -40,12 +40,12 @@
#include "src/core/channel/channel_args.h"
#include "src/core/channel/connected_channel.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/support/string.h"
#include "src/core/surface/call.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/completion_queue.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
typedef enum { PENDING_START, ALL_CALLS, CALL_LIST_COUNT } call_list;
@ -411,14 +411,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
}
static const grpc_channel_filter server_surface_filter = {
call_op, channel_op,
sizeof(call_data), init_call_elem, destroy_call_elem,
sizeof(channel_data), init_channel_elem, destroy_channel_elem,
"server",
};
call_op, channel_op, sizeof(call_data),
init_call_elem, destroy_call_elem, sizeof(channel_data),
init_channel_elem, destroy_channel_elem, "server", };
static void early_terminate_requested_calls(grpc_completion_queue *cq,
void **tags, size_t ntags) {

@ -35,9 +35,9 @@
#include <string.h>
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
#include "src/core/transport/transport.h"
@ -105,28 +105,28 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
}
/* fallthrough */
case GRPC_CHTTP2_DATA_FH_1:
p->frame_size = ((gpr_uint32)*cur) << 24;
p->frame_size = ((gpr_uint32) * cur) << 24;
if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_2;
return GRPC_CHTTP2_PARSE_OK;
}
/* fallthrough */
case GRPC_CHTTP2_DATA_FH_2:
p->frame_size |= ((gpr_uint32)*cur) << 16;
p->frame_size |= ((gpr_uint32) * cur) << 16;
if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_3;
return GRPC_CHTTP2_PARSE_OK;
}
/* fallthrough */
case GRPC_CHTTP2_DATA_FH_3:
p->frame_size |= ((gpr_uint32)*cur) << 8;
p->frame_size |= ((gpr_uint32) * cur) << 8;
if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_4;
return GRPC_CHTTP2_PARSE_OK;
}
/* fallthrough */
case GRPC_CHTTP2_DATA_FH_4:
p->frame_size |= ((gpr_uint32)*cur);
p->frame_size |= ((gpr_uint32) * cur);
p->state = GRPC_CHTTP2_DATA_FRAME;
++cur;
state->need_flush_reads = 1;

@ -75,7 +75,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
p->state = GRPC_CHTTP2_GOAWAY_LSI0;
return GRPC_CHTTP2_PARSE_OK;
}
p->last_stream_id = ((gpr_uint32)*cur) << 24;
p->last_stream_id = ((gpr_uint32) * cur) << 24;
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_LSI1:
@ -83,7 +83,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
p->state = GRPC_CHTTP2_GOAWAY_LSI1;
return GRPC_CHTTP2_PARSE_OK;
}
p->last_stream_id |= ((gpr_uint32)*cur) << 16;
p->last_stream_id |= ((gpr_uint32) * cur) << 16;
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_LSI2:
@ -91,7 +91,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
p->state = GRPC_CHTTP2_GOAWAY_LSI2;
return GRPC_CHTTP2_PARSE_OK;
}
p->last_stream_id |= ((gpr_uint32)*cur) << 8;
p->last_stream_id |= ((gpr_uint32) * cur) << 8;
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_LSI3:
@ -99,7 +99,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
p->state = GRPC_CHTTP2_GOAWAY_LSI3;
return GRPC_CHTTP2_PARSE_OK;
}
p->last_stream_id |= ((gpr_uint32)*cur);
p->last_stream_id |= ((gpr_uint32) * cur);
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_ERR0:
@ -107,7 +107,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
p->state = GRPC_CHTTP2_GOAWAY_ERR0;
return GRPC_CHTTP2_PARSE_OK;
}
p->error_code = ((gpr_uint32)*cur) << 24;
p->error_code = ((gpr_uint32) * cur) << 24;
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_ERR1:
@ -115,7 +115,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
p->state = GRPC_CHTTP2_GOAWAY_ERR1;
return GRPC_CHTTP2_PARSE_OK;
}
p->error_code |= ((gpr_uint32)*cur) << 16;
p->error_code |= ((gpr_uint32) * cur) << 16;
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_ERR2:
@ -123,7 +123,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
p->state = GRPC_CHTTP2_GOAWAY_ERR2;
return GRPC_CHTTP2_PARSE_OK;
}
p->error_code |= ((gpr_uint32)*cur) << 8;
p->error_code |= ((gpr_uint32) * cur) << 8;
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_ERR3:
@ -131,7 +131,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
p->state = GRPC_CHTTP2_GOAWAY_ERR3;
return GRPC_CHTTP2_PARSE_OK;
}
p->error_code |= ((gpr_uint32)*cur);
p->error_code |= ((gpr_uint32) * cur);
++cur;
/* fallthrough */
case GRPC_CHTTP2_GOAWAY_DEBUG:

@ -53,8 +53,7 @@ const grpc_chttp2_setting_parameters
{"MAX_FRAME_SIZE", 16384, 16384, 16777215,
GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE},
{"MAX_HEADER_LIST_SIZE", 0xffffffffu, 0, 0xffffffffu,
GRPC_CHTTP2_CLAMP_INVALID_VALUE},
};
GRPC_CHTTP2_CLAMP_INVALID_VALUE}, };
static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length,
gpr_uint8 flags) {
@ -156,7 +155,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
}
return GRPC_CHTTP2_PARSE_OK;
}
parser->id = ((gpr_uint16)*cur) << 8;
parser->id = ((gpr_uint16) * cur) << 8;
cur++;
/* fallthrough */
case GRPC_CHTTP2_SPS_ID1:
@ -172,7 +171,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
parser->state = GRPC_CHTTP2_SPS_VAL0;
return GRPC_CHTTP2_PARSE_OK;
}
parser->value = ((gpr_uint32)*cur) << 24;
parser->value = ((gpr_uint32) * cur) << 24;
cur++;
/* fallthrough */
case GRPC_CHTTP2_SPS_VAL1:
@ -180,7 +179,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
parser->state = GRPC_CHTTP2_SPS_VAL1;
return GRPC_CHTTP2_PARSE_OK;
}
parser->value |= ((gpr_uint32)*cur) << 16;
parser->value |= ((gpr_uint32) * cur) << 16;
cur++;
/* fallthrough */
case GRPC_CHTTP2_SPS_VAL2:
@ -188,7 +187,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
parser->state = GRPC_CHTTP2_SPS_VAL2;
return GRPC_CHTTP2_PARSE_OK;
}
parser->value |= ((gpr_uint32)*cur) << 8;
parser->value |= ((gpr_uint32) * cur) << 8;
cur++;
/* fallthrough */
case GRPC_CHTTP2_SPS_VAL3:

@ -81,7 +81,7 @@ grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse(
grpc_chttp2_window_update_parser *p = parser;
while (p->byte != 4 && cur != end) {
p->amount |= ((gpr_uint32)*cur) << (8 * (3 - p->byte));
p->amount |= ((gpr_uint32) * cur) << (8 * (3 - p->byte));
cur++;
p->byte++;
}

@ -55,21 +55,19 @@ typedef struct {
unsigned char index;
} spec;
static const spec fields[] = {
{"INDEXED_FIELD", 0X80, 1, 1},
{"INDEXED_FIELD_X", 0X80, 1, 2},
{"LITHDR_INCIDX", 0X40, 2, 1},
{"LITHDR_INCIDX_X", 0X40, 2, 2},
{"LITHDR_INCIDX_V", 0X40, 2, 0},
{"LITHDR_NOTIDX", 0X00, 4, 1},
{"LITHDR_NOTIDX_X", 0X00, 4, 2},
{"LITHDR_NOTIDX_V", 0X00, 4, 0},
{"LITHDR_NVRIDX", 0X10, 4, 1},
{"LITHDR_NVRIDX_X", 0X10, 4, 2},
{"LITHDR_NVRIDX_V", 0X10, 4, 0},
{"MAX_TBL_SIZE", 0X20, 3, 1},
{"MAX_TBL_SIZE_X", 0X20, 3, 2},
};
static const spec fields[] = {{"INDEXED_FIELD", 0X80, 1, 1},
{"INDEXED_FIELD_X", 0X80, 1, 2},
{"LITHDR_INCIDX", 0X40, 2, 1},
{"LITHDR_INCIDX_X", 0X40, 2, 2},
{"LITHDR_INCIDX_V", 0X40, 2, 0},
{"LITHDR_NOTIDX", 0X00, 4, 1},
{"LITHDR_NOTIDX_X", 0X00, 4, 2},
{"LITHDR_NOTIDX_V", 0X00, 4, 0},
{"LITHDR_NVRIDX", 0X10, 4, 1},
{"LITHDR_NVRIDX_X", 0X10, 4, 2},
{"LITHDR_NVRIDX_V", 0X10, 4, 0},
{"MAX_TBL_SIZE", 0X20, 3, 1},
{"MAX_TBL_SIZE_X", 0X20, 3, 2}, };
static const int num_fields = sizeof(fields) / sizeof(*fields);
@ -131,9 +129,13 @@ static void generate_first_byte_lut(void) {
#define MAXHUFFSTATES 1024
/* represents a set of symbols as an array of booleans indicating inclusion */
typedef struct { char included[GRPC_CHTTP2_NUM_HUFFSYMS]; } symset;
typedef struct {
char included[GRPC_CHTTP2_NUM_HUFFSYMS];
} symset;
/* represents a lookup table indexed by a nibble */
typedef struct { int values[16]; } nibblelut;
typedef struct {
int values[16];
} nibblelut;
/* returns a symset that includes all possible symbols */
static symset symset_all(void) {

@ -38,10 +38,10 @@
#include <assert.h>
#include "src/core/transport/chttp2/bin_encoder.h"
#include "src/core/support/string.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
typedef enum {
@ -221,8 +221,7 @@ static const gpr_uint8 first_byte_lut[256] = {
INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X,
};
INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X, };
/* state table for huffman decoding: given a state, gives an index/16 into
next_sub_tbl. Taking that index and adding the value of the nibble being
@ -242,8 +241,7 @@ static const gpr_uint8 next_tbl[256] = {
38, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 2, 2, 26, 3, 3, 39, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 40, 2,
41, 1, 1, 1, 42, 43, 1, 1, 44, 1, 1, 1, 1, 15, 2, 2, 2, 2, 2, 2,
3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2,
};
3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2, };
/* next state, based upon current state and the current nibble: see above.
generated by gen_hpack_tables.c */
static const gpr_int16 next_sub_tbl[48 * 16] = {
@ -298,8 +296,7 @@ static const gpr_int16 next_sub_tbl[48 * 16] = {
4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 245, 246, 247, 248, 249, 250, 251, 252,
253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 255,
};
0, 0, 255, };
/* emission table: indexed like next_tbl, ultimately gives the byte to be
emitted, or -1 for no byte, or 256 for end of stream
@ -322,8 +319,7 @@ static const gpr_uint16 emit_tbl[256] = {
204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
219, 220, 221, 0, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247,
248,
};
248, };
/* generated by gen_hpack_tables.c */
static const gpr_int16 emit_sub_tbl[249 * 16] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@ -591,8 +587,7 @@ static const gpr_int16 emit_sub_tbl[249 * 16] = {
251, 251, 252, 252, 253, 253, 254, 254, 2, 3, 4, 5, 6, 7, 8,
11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27,
28, 29, 30, 31, 127, 220, 249, -1, 10, 10, 10, 10, 13, 13, 13,
13, 22, 22, 22, 22, 256, 256, 256, 256,
};
13, 22, 22, 22, 22, 256, 256, 256, 256, };
static const gpr_uint8 inverse_base64[256] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
@ -612,8 +607,7 @@ static const gpr_uint8 inverse_base64[256] = {
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255,
};
255, };
/* emission helpers */
static void on_hdr(grpc_chttp2_hpack_parser *p, grpc_mdelem *md,
@ -951,7 +945,7 @@ static int parse_value1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
return 1;
}
*p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 7;
*p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 7;
if ((*cur) & 0x80) {
return parse_value2(p, cur + 1, end);
@ -969,7 +963,7 @@ static int parse_value2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
return 1;
}
*p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 14;
*p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 14;
if ((*cur) & 0x80) {
return parse_value3(p, cur + 1, end);
@ -987,7 +981,7 @@ static int parse_value3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
return 1;
}
*p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 21;
*p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 21;
if ((*cur) & 0x80) {
return parse_value4(p, cur + 1, end);
@ -1212,7 +1206,7 @@ static int huff_nibble(grpc_chttp2_hpack_parser *p, gpr_uint8 nibble) {
gpr_int16 next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble];
if (emit != -1) {
if (emit >= 0 && emit < 256) {
gpr_uint8 c = (gpr_uint8) emit;
gpr_uint8 c = (gpr_uint8)emit;
if (!append_string(p, &c, (&c) + 1)) return 0;
} else {
assert(emit == 256);

@ -104,8 +104,7 @@ static struct {
/* 58: */ {"user-agent", ""},
/* 59: */ {"vary", ""},
/* 60: */ {"via", ""},
/* 61: */ {"www-authenticate", ""},
};
/* 61: */ {"www-authenticate", ""}, };
void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx) {
size_t i;

@ -293,5 +293,4 @@ const grpc_chttp2_huffsym grpc_chttp2_huffsyms[GRPC_CHTTP2_NUM_HUFFSYMS] = {
{0x7ffffef, 27},
{0x7fffff0, 27},
{0x3ffffee, 26},
{0x3fffffff, 30},
};
{0x3fffffff, 30}, };

@ -43,7 +43,7 @@
#include "src/core/transport/chttp2/timeout_encoding.h"
#include "src/core/transport/chttp2/varint.h"
#define HASH_FRAGMENT_1(x) ((x)&255)
#define HASH_FRAGMENT_1(x) ((x) & 255)
#define HASH_FRAGMENT_2(x) ((x >> 8) & 255)
#define HASH_FRAGMENT_3(x) ((x >> 16) & 255)
#define HASH_FRAGMENT_4(x) ((x >> 24) & 255)

@ -36,6 +36,8 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
static int round_up(int x, int divisor) {
return (x / divisor + (x % divisor != 0)) * divisor;
}
@ -53,15 +55,21 @@ static int round_up_to_three_sig_figs(int x) {
}
/* encode our minimum viable timeout value */
static void enc_tiny(char *buffer) { strcpy(buffer, "1n"); }
static void enc_tiny(char *buffer) { memcpy(buffer, "1n", 3); }
static void enc_ext(char *buffer, long value, char ext) {
int n = gpr_ltoa(value, buffer);
buffer[n] = ext;
buffer[n + 1] = 0;
}
static void enc_seconds(char *buffer, long sec) {
if (sec % 3600 == 0) {
sprintf(buffer, "%ldH", sec / 3600);
enc_ext(buffer, sec / 3600, 'H');
} else if (sec % 60 == 0) {
sprintf(buffer, "%ldM", sec / 60);
enc_ext(buffer, sec / 60, 'M');
} else {
sprintf(buffer, "%ldS", sec);
enc_ext(buffer, sec, 'S');
}
}
@ -69,23 +77,23 @@ static void enc_nanos(char *buffer, int x) {
x = round_up_to_three_sig_figs(x);
if (x < 100000) {
if (x % 1000 == 0) {
sprintf(buffer, "%du", x / 1000);
enc_ext(buffer, x / 1000, 'u');
} else {
sprintf(buffer, "%dn", x);
enc_ext(buffer, x, 'n');
}
} else if (x < 100000000) {
if (x % 1000000 == 0) {
sprintf(buffer, "%dm", x / 1000000);
enc_ext(buffer, x / 1000000, 'm');
} else {
sprintf(buffer, "%du", x / 1000);
enc_ext(buffer, x / 1000, 'u');
}
} else if (x < 1000000000) {
sprintf(buffer, "%dm", x / 1000000);
enc_ext(buffer, x / 1000000, 'm');
} else {
/* note that this is only ever called with times of less than one second,
so if we reach here the time must have been rounded up to a whole second
(and no more) */
strcpy(buffer, "1S");
memcpy(buffer, "1S", 3);
}
}
@ -93,18 +101,18 @@ static void enc_micros(char *buffer, int x) {
x = round_up_to_three_sig_figs(x);
if (x < 100000) {
if (x % 1000 == 0) {
sprintf(buffer, "%dm", x / 1000);
enc_ext(buffer, x / 1000, 'm');
} else {
sprintf(buffer, "%du", x);
enc_ext(buffer, x, 'u');
}
} else if (x < 100000000) {
if (x % 1000000 == 0) {
sprintf(buffer, "%dS", x / 1000000);
enc_ext(buffer, x / 1000000, 'S');
} else {
sprintf(buffer, "%dm", x / 1000);
enc_ext(buffer, x / 1000, 'm');
}
} else {
sprintf(buffer, "%dS", x / 1000000);
enc_ext(buffer, x / 1000000, 'S');
}
}

@ -34,8 +34,11 @@
#ifndef __GRPC_INTERNAL_TRANSPORT_CHTTP2_TIMEOUT_ENCODING_H_
#define __GRPC_INTERNAL_TRANSPORT_CHTTP2_TIMEOUT_ENCODING_H_
#include "src/core/support/string.h"
#include <grpc/support/time.h>
#define GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE (GPR_LTOA_MIN_BUFSIZE + 1)
/* Encode/decode timeouts to the GRPC over HTTP2 format;
encoding may round up arbitrarily */
void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer);

@ -56,7 +56,7 @@ void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value,
((n) < GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits) \
? 1 \
: grpc_chttp2_hpack_varint_length( \
(n)-GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits)))
(n) - GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits)))
#define GRPC_CHTTP2_WRITE_VARINT(n, prefix_bits, prefix_or, target, length) \
do { \
@ -66,7 +66,8 @@ void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value,
} else { \
(tgt)[0] = (prefix_or) | GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \
grpc_chttp2_hpack_write_varint_tail( \
(n)-GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits), (tgt)+1, (length)-1); \
(n) - GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits), (tgt) + 1, \
(length) - 1); \
} \
} while (0)

@ -37,6 +37,7 @@
#include <stdio.h>
#include <string.h>
#include "src/core/support/string.h"
#include "src/core/transport/chttp2/frame_data.h"
#include "src/core/transport/chttp2/frame_goaway.h"
#include "src/core/transport/chttp2/frame_ping.h"
@ -53,7 +54,6 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice_buffer.h>
#include <grpc/support/string.h>
#include <grpc/support/useful.h>
#define DEFAULT_WINDOW 65535
@ -525,7 +525,7 @@ static int init_stream(grpc_transport *gt, grpc_stream *gs,
lock(t);
s->id = 0;
} else {
s->id = (gpr_uint32)(gpr_uintptr) server_data;
s->id = (gpr_uint32)(gpr_uintptr)server_data;
t->incoming_stream = s;
grpc_chttp2_stream_map_add(&t->stream_map, s->id, s);
}
@ -1002,7 +1002,7 @@ static void cancel_stream_inner(transport *t, stream *s, gpr_uint32 id,
grpc_chttp2_error_code error_code,
int send_rst) {
int had_outgoing;
char buffer[32];
char buffer[GPR_LTOA_MIN_BUFSIZE];
if (s) {
/* clear out any unreported input & output: nobody cares anymore */
@ -1015,7 +1015,7 @@ static void cancel_stream_inner(transport *t, stream *s, gpr_uint32 id,
s->cancelled = 1;
stream_list_join(t, s, CANCELLED);
sprintf(buffer, "%d", local_status);
gpr_ltoa(local_status, buffer);
grpc_sopb_add_metadata(
&s->parser.incoming_sopb,
grpc_mdelem_from_strings(t->metadata_context, "grpc-status", buffer));
@ -1238,7 +1238,7 @@ static int init_header_frame_parser(transport *t, int is_continuation) {
t->incoming_stream = NULL;
/* if stream is accepted, we set incoming_stream in init_stream */
t->cb->accept_stream(t->cb_user_data, &t->base,
(void *)(gpr_uintptr) t->incoming_stream_id);
(void *)(gpr_uintptr)t->incoming_stream_id);
s = t->incoming_stream;
if (!s) {
gpr_log(GPR_ERROR, "stream not accepted");
@ -1503,8 +1503,8 @@ static int process_read(transport *t, gpr_slice slice) {
"Connect string mismatch: expected '%c' (%d) got '%c' (%d) "
"at byte %d",
CLIENT_CONNECT_STRING[t->deframe_state],
(int)(gpr_uint8) CLIENT_CONNECT_STRING[t->deframe_state],
*cur, (int)*cur, t->deframe_state);
(int)(gpr_uint8)CLIENT_CONNECT_STRING[t->deframe_state], *cur,
(int)*cur, t->deframe_state);
drop_connection(t);
return 0;
}
@ -1518,7 +1518,7 @@ static int process_read(transport *t, gpr_slice slice) {
dts_fh_0:
case DTS_FH_0:
GPR_ASSERT(cur < end);
t->incoming_frame_size = ((gpr_uint32)*cur) << 16;
t->incoming_frame_size = ((gpr_uint32) * cur) << 16;
if (++cur == end) {
t->deframe_state = DTS_FH_1;
return 1;
@ -1526,7 +1526,7 @@ static int process_read(transport *t, gpr_slice slice) {
/* fallthrough */
case DTS_FH_1:
GPR_ASSERT(cur < end);
t->incoming_frame_size |= ((gpr_uint32)*cur) << 8;
t->incoming_frame_size |= ((gpr_uint32) * cur) << 8;
if (++cur == end) {
t->deframe_state = DTS_FH_2;
return 1;
@ -1558,7 +1558,7 @@ static int process_read(transport *t, gpr_slice slice) {
/* fallthrough */
case DTS_FH_5:
GPR_ASSERT(cur < end);
t->incoming_stream_id = (((gpr_uint32)*cur) << 24) & 0x7f;
t->incoming_stream_id = (((gpr_uint32) * cur) << 24) & 0x7f;
if (++cur == end) {
t->deframe_state = DTS_FH_6;
return 1;
@ -1566,7 +1566,7 @@ static int process_read(transport *t, gpr_slice slice) {
/* fallthrough */
case DTS_FH_6:
GPR_ASSERT(cur < end);
t->incoming_stream_id |= ((gpr_uint32)*cur) << 16;
t->incoming_stream_id |= ((gpr_uint32) * cur) << 16;
if (++cur == end) {
t->deframe_state = DTS_FH_7;
return 1;
@ -1574,7 +1574,7 @@ static int process_read(transport *t, gpr_slice slice) {
/* fallthrough */
case DTS_FH_7:
GPR_ASSERT(cur < end);
t->incoming_stream_id |= ((gpr_uint32)*cur) << 8;
t->incoming_stream_id |= ((gpr_uint32) * cur) << 8;
if (++cur == end) {
t->deframe_state = DTS_FH_8;
return 1;
@ -1582,7 +1582,7 @@ static int process_read(transport *t, gpr_slice slice) {
/* fallthrough */
case DTS_FH_8:
GPR_ASSERT(cur < end);
t->incoming_stream_id |= ((gpr_uint32)*cur);
t->incoming_stream_id |= ((gpr_uint32) * cur);
t->deframe_state = DTS_FRAME;
if (!init_frame_parser(t)) {
return 0;

@ -31,6 +31,7 @@
*
*/
#include "src/core/iomgr/sockaddr.h"
#include "src/core/transport/metadata.h"
#include <stddef.h>

@ -369,8 +369,7 @@ static void fake_protector_destroy(tsi_frame_protector* self) {
static const tsi_frame_protector_vtable frame_protector_vtable = {
fake_protector_protect, fake_protector_protect_flush,
fake_protector_unprotect, fake_protector_destroy,
};
fake_protector_unprotect, fake_protector_destroy, };
/* --- tsi_handshaker methods implementation. ---*/
@ -485,8 +484,7 @@ static const tsi_handshaker_vtable handshaker_vtable = {
fake_handshaker_get_result,
fake_handshaker_extract_peer,
fake_handshaker_create_frame_protector,
fake_handshaker_destroy,
};
fake_handshaker_destroy, };
tsi_handshaker* tsi_create_fake_handshaker(int is_client) {
tsi_fake_handshaker* impl = calloc(1, sizeof(tsi_fake_handshaker));

@ -703,8 +703,7 @@ 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_destroy,
};
ssl_protector_destroy, };
/* --- tsi_handshaker methods implementation. ---*/
@ -877,8 +876,7 @@ static const tsi_handshaker_vtable handshaker_vtable = {
ssl_handshaker_get_result,
ssl_handshaker_extract_peer,
ssl_handshaker_create_frame_protector,
ssl_handshaker_destroy,
};
ssl_handshaker_destroy, };
/* --- tsi_ssl_handshaker_factory common methods. --- */

@ -104,7 +104,6 @@ Status Channel::StartBlockingRpc(const RpcMethod &method,
context->set_call(call);
grpc_event *ev;
void *finished_tag = reinterpret_cast<char *>(call);
void *invoke_tag = reinterpret_cast<char *>(call) + 1;
void *metadata_read_tag = reinterpret_cast<char *>(call) + 2;
void *write_tag = reinterpret_cast<char *>(call) + 3;
void *halfclose_tag = reinterpret_cast<char *>(call) + 4;
@ -115,19 +114,11 @@ Status Channel::StartBlockingRpc(const RpcMethod &method,
// add_metadata from context
//
// invoke
GPR_ASSERT(grpc_call_start_invoke(call, cq, invoke_tag, metadata_read_tag,
finished_tag,
GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK);
ev = grpc_completion_queue_pluck(cq, invoke_tag, gpr_inf_future);
bool success = ev->data.invoke_accepted == GRPC_OP_OK;
grpc_event_finish(ev);
if (!success) {
GetFinalStatus(cq, finished_tag, &status);
return status;
}
GPR_ASSERT(grpc_call_invoke(call, cq, metadata_read_tag, finished_tag,
GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK);
// write request
grpc_byte_buffer *write_buffer = nullptr;
success = SerializeProto(request, &write_buffer);
bool success = SerializeProto(request, &write_buffer);
if (!success) {
grpc_call_cancel(call);
status =

@ -80,17 +80,9 @@ void StreamContext::Start(bool buffered) {
if (is_client_) {
// TODO(yangg) handle metadata send path
int flag = buffered ? GRPC_WRITE_BUFFER_HINT : 0;
grpc_call_error error = grpc_call_start_invoke(call(), cq(), invoke_tag(),
client_metadata_read_tag(),
finished_tag(), flag);
grpc_call_error error = grpc_call_invoke(
call(), cq(), client_metadata_read_tag(), finished_tag(), flag);
GPR_ASSERT(GRPC_CALL_OK == error);
grpc_event *invoke_ev =
grpc_completion_queue_pluck(cq(), invoke_tag(), gpr_inf_future);
if (invoke_ev->data.invoke_accepted != GRPC_OP_OK) {
peer_halfclosed_ = true;
self_halfclosed_ = true;
}
grpc_event_finish(invoke_ev);
} else {
// TODO(yangg) metadata needs to be added before accept
// TODO(yangg) correctly set flag to accept

@ -76,7 +76,6 @@ class StreamContext final : public StreamContextInterface {
void *read_tag() { return reinterpret_cast<char *>(this) + 1; }
void *write_tag() { return reinterpret_cast<char *>(this) + 2; }
void *halfclose_tag() { return reinterpret_cast<char *>(this) + 3; }
void *invoke_tag() { return reinterpret_cast<char *>(this) + 4; }
void *client_metadata_read_tag() {
return reinterpret_cast<char *>(this) + 5;
}

@ -1,8 +1,13 @@
{
"variables" : {
'no_install': "<!(echo $GRPC_NO_INSTALL)",
'grpc_root': "<!(echo $GRPC_ROOT)",
'grpc_lib_subdir': "<!(echo $GRPC_LIB_SUBDIR)"
},
"targets" : [
{
'include_dirs': [
"<!(node -e \"require('nan')\")"
"<!(nodejs -e \"require('nan')\")"
],
'cxxflags': [
'-Wall',
@ -11,32 +16,50 @@
'-g',
'-zdefs'
'-Werror',
],
],
'ldflags': [
'-g',
'-L/usr/local/google/home/mlumish/grpc_dev/lib'
'-g'
],
'link_settings': {
'libraries': [
'-lgrpc',
'-lrt',
'-lgpr',
'-lpthread'
],
},
"target_name": "grpc",
"sources": [
"byte_buffer.cc",
"call.cc",
"channel.cc",
"completion_queue_async_worker.cc",
"credentials.cc",
"event.cc",
"node_grpc.cc",
"server.cc",
"server_credentials.cc",
"tag.cc",
"timeval.cc"
"ext/byte_buffer.cc",
"ext/call.cc",
"ext/channel.cc",
"ext/completion_queue_async_worker.cc",
"ext/credentials.cc",
"ext/event.cc",
"ext/node_grpc.cc",
"ext/server.cc",
"ext/server_credentials.cc",
"ext/tag.cc",
"ext/timeval.cc"
],
'conditions' : [
['no_install=="yes"', {
'include_dirs': [
"<(grpc_root)/include"
],
'link_settings': {
'libraries': [
'<(grpc_root)/<(grpc_lib_subdir)/libgrpc.a',
'<(grpc_root)/<(grpc_lib_subdir)/libgpr.a'
]
}
}],
['no_install!="yes"', {
'link_settings': {
'libraries': [
'-lgrpc',
'-lgpr'
]
}
}]
]
}
]

@ -52,7 +52,8 @@ var Server = grpc.buildServer([math.Math.service]);
*/
function mathDiv(call, cb) {
var req = call.request;
if (req.divisor == 0) {
// Unary + is explicit coersion to integer
if (+req.divisor === 0) {
cb(new Error('cannot divide by zero'));
}
cb(null, {
@ -89,7 +90,7 @@ function mathSum(call, cb) {
// Here, call is a standard readable Node object Stream
var sum = 0;
call.on('data', function(data) {
sum += data.num | 0;
sum += (+data.num);
});
call.on('end', function() {
cb(null, {num: sum});
@ -104,7 +105,7 @@ function mathDivMany(stream) {
Transform.call(this, options);
}
DivTransform.prototype._transform = function(div_args, encoding, callback) {
if (div_args.divisor == 0) {
if (+div_args.divisor === 0) {
callback(new Error('cannot divide by zero'));
}
callback(null, {

@ -78,8 +78,8 @@ void Call::Init(Handle<Object> exports) {
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NanSetPrototypeTemplate(tpl, "addMetadata",
FunctionTemplate::New(AddMetadata)->GetFunction());
NanSetPrototypeTemplate(tpl, "startInvoke",
FunctionTemplate::New(StartInvoke)->GetFunction());
NanSetPrototypeTemplate(tpl, "invoke",
FunctionTemplate::New(Invoke)->GetFunction());
NanSetPrototypeTemplate(tpl, "serverAccept",
FunctionTemplate::New(ServerAccept)->GetFunction());
NanSetPrototypeTemplate(
@ -203,37 +203,30 @@ NAN_METHOD(Call::AddMetadata) {
NanReturnUndefined();
}
NAN_METHOD(Call::StartInvoke) {
NAN_METHOD(Call::Invoke) {
NanScope();
if (!HasInstance(args.This())) {
return NanThrowTypeError("startInvoke can only be called on Call objects");
return NanThrowTypeError("invoke can only be called on Call objects");
}
if (!args[0]->IsFunction()) {
return NanThrowTypeError("StartInvoke's first argument must be a function");
return NanThrowTypeError("invoke's first argument must be a function");
}
if (!args[1]->IsFunction()) {
return NanThrowTypeError(
"StartInvoke's second argument must be a function");
}
if (!args[2]->IsFunction()) {
return NanThrowTypeError("StartInvoke's third argument must be a function");
return NanThrowTypeError("invoke's second argument must be a function");
}
if (!args[3]->IsUint32()) {
return NanThrowTypeError(
"StartInvoke's fourth argument must be integer flags");
if (!args[2]->IsUint32()) {
return NanThrowTypeError("invoke's third argument must be integer flags");
}
Call *call = ObjectWrap::Unwrap<Call>(args.This());
unsigned int flags = args[3]->Uint32Value();
grpc_call_error error = grpc_call_start_invoke(
grpc_call_error error = grpc_call_invoke(
call->wrapped_call, CompletionQueueAsyncWorker::GetQueue(),
CreateTag(args[0], args.This()), CreateTag(args[1], args.This()),
CreateTag(args[2], args.This()), flags);
CreateTag(args[0], args.This()), CreateTag(args[1], args.This()), flags);
if (error == GRPC_CALL_OK) {
CompletionQueueAsyncWorker::Next();
CompletionQueueAsyncWorker::Next();
CompletionQueueAsyncWorker::Next();
} else {
return NanThrowError("startInvoke failed", error);
return NanThrowError("invoke failed", error);
}
NanReturnUndefined();
}
@ -281,7 +274,7 @@ NAN_METHOD(Call::ServerEndInitialMetadata) {
NAN_METHOD(Call::Cancel) {
NanScope();
if (!HasInstance(args.This())) {
return NanThrowTypeError("startInvoke can only be called on Call objects");
return NanThrowTypeError("cancel can only be called on Call objects");
}
Call *call = ObjectWrap::Unwrap<Call>(args.This());
grpc_call_error error = grpc_call_cancel(call->wrapped_call);

@ -61,7 +61,7 @@ class Call : public ::node::ObjectWrap {
static NAN_METHOD(New);
static NAN_METHOD(AddMetadata);
static NAN_METHOD(StartInvoke);
static NAN_METHOD(Invoke);
static NAN_METHOD(ServerAccept);
static NAN_METHOD(ServerEndInitialMetadata);
static NAN_METHOD(Cancel);

@ -157,8 +157,7 @@ NAN_METHOD(Credentials::CreateSsl) {
}
NanReturnValue(WrapStruct(grpc_ssl_credentials_create(
root_certs,
key_cert_pair.private_key == NULL ? NULL : &key_cert_pair)));
root_certs, key_cert_pair.private_key == NULL ? NULL : &key_cert_pair)));
}
NAN_METHOD(Credentials::CreateComposite) {

@ -148,8 +148,6 @@ void InitCompletionTypeConstants(Handle<Object> exports) {
completion_type->Set(NanNew("QUEUE_SHUTDOWN"), QUEUE_SHUTDOWN);
Handle<Value> READ(NanNew<Uint32, uint32_t>(GRPC_READ));
completion_type->Set(NanNew("READ"), READ);
Handle<Value> INVOKE_ACCEPTED(NanNew<Uint32, uint32_t>(GRPC_INVOKE_ACCEPTED));
completion_type->Set(NanNew("INVOKE_ACCEPTED"), INVOKE_ACCEPTED);
Handle<Value> WRITE_ACCEPTED(NanNew<Uint32, uint32_t>(GRPC_WRITE_ACCEPTED));
completion_type->Set(NanNew("WRITE_ACCEPTED"), WRITE_ACCEPTED);
Handle<Value> FINISH_ACCEPTED(NanNew<Uint32, uint32_t>(GRPC_FINISH_ACCEPTED));

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

Loading…
Cancel
Save