diff options
author | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2016-06-08 19:17:20 -0700 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2016-06-08 19:17:20 -0700 |
commit | 1bc2976a0f51e14d3525aecbf4b3450445ed2d1b (patch) | |
tree | 62dc4761183d959c135a46bfa83bb1f9ef8994c9 /include | |
parent | b81f1722061052456b6f472d7c72fe4be8901d55 (diff) | |
parent | 37e516e7c99ed08da6b8619701b542e2bd15a732 (diff) |
Merge pull request #6481 from dgquintas/compression_md_level_bis
Allow servers to select compression level via initial MD & overall compression cleanup
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc++/impl/codegen/call.h | 12 | ||||
-rw-r--r-- | include/grpc++/server_builder.h | 48 | ||||
-rw-r--r-- | include/grpc/compression.h | 3 | ||||
-rw-r--r-- | include/grpc/impl/codegen/compression_types.h | 27 | ||||
-rw-r--r-- | include/grpc/impl/codegen/grpc_types.h | 6 |
5 files changed, 76 insertions, 20 deletions
diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index 4f550b42a2..d720f27a8f 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -47,7 +47,9 @@ #include <grpc++/impl/codegen/serialization_traits.h> #include <grpc++/impl/codegen/status.h> #include <grpc++/impl/codegen/string_ref.h> + #include <grpc/impl/codegen/alloc.h> +#include <grpc/impl/codegen/compression_types.h> #include <grpc/impl/codegen/grpc_types.h> struct grpc_byte_buffer; @@ -187,6 +189,8 @@ class CallOpSendInitialMetadata { flags_ = flags; initial_metadata_count_ = metadata.size(); initial_metadata_ = FillMetadataArray(metadata); + // TODO(dgq): expose compression level in API so it can be properly set. + maybe_compression_level_.is_set = false; } protected: @@ -198,6 +202,10 @@ class CallOpSendInitialMetadata { op->reserved = NULL; op->data.send_initial_metadata.count = initial_metadata_count_; op->data.send_initial_metadata.metadata = initial_metadata_; + op->data.send_initial_metadata.maybe_compression_level.is_set = + maybe_compression_level_.is_set; + op->data.send_initial_metadata.maybe_compression_level.level = + maybe_compression_level_.level; } void FinishOp(bool* status, int max_message_size) { if (!send_) return; @@ -209,6 +217,10 @@ class CallOpSendInitialMetadata { uint32_t flags_; size_t initial_metadata_count_; grpc_metadata* initial_metadata_; + struct { + bool is_set; + grpc_compression_level level; + } maybe_compression_level_; }; class CallOpSendMessage { diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h index 8525cb70cb..54f01d11b5 100644 --- a/include/grpc++/server_builder.h +++ b/include/grpc++/server_builder.h @@ -66,29 +66,43 @@ class ServerBuilder { /// The service must exist for the lifetime of the \a Server instance returned /// by \a BuildAndStart(). /// Matches requests with any :authority - void RegisterService(Service* service); + ServerBuilder& RegisterService(Service* service); /// Register a generic service. /// Matches requests with any :authority - void RegisterAsyncGenericService(AsyncGenericService* service); + ServerBuilder& RegisterAsyncGenericService(AsyncGenericService* service); /// Register a service. This call does not take ownership of the service. /// The service must exist for the lifetime of the \a Server instance returned /// by BuildAndStart(). /// Only matches requests with :authority \a host - void RegisterService(const grpc::string& host, Service* service); + ServerBuilder& RegisterService(const grpc::string& host, Service* service); /// Set max message size in bytes. - void SetMaxMessageSize(int max_message_size) { + ServerBuilder& SetMaxMessageSize(int max_message_size) { max_message_size_ = max_message_size; + return *this; } - /// Set the compression options to be used by the server. - void SetCompressionOptions(const grpc_compression_options& options) { - compression_options_ = options; - } + /// Set the support status for compression algorithms. All algorithms are + /// enabled by default. + /// + /// Incoming calls compressed with an unsupported algorithm will fail with + /// GRPC_STATUS_UNIMPLEMENTED. + ServerBuilder& SetCompressionAlgorithmSupportStatus( + grpc_compression_algorithm algorithm, bool enabled); + + /// The default compression level to use for all channel calls in the + /// absence of a call-specific level. + ServerBuilder& SetDefaultCompressionLevel(grpc_compression_level level); + + /// The default compression algorithm to use for all channel calls in the + /// absence of a call-specific level. Note that it overrides any compression + /// level set by \a SetDefaultCompressionLevel. + ServerBuilder& SetDefaultCompressionAlgorithm( + grpc_compression_algorithm algorithm); - void SetOption(std::unique_ptr<ServerBuilderOption> option); + ServerBuilder& SetOption(std::unique_ptr<ServerBuilderOption> option); /// Tries to bind \a server to the given \a addr. /// @@ -101,9 +115,9 @@ class ServerBuilder { /// number. \a nullptr otherwise. /// // TODO(dgq): the "port" part seems to be a misnomer. - void AddListeningPort(const grpc::string& addr, - std::shared_ptr<ServerCredentials> creds, - int* selected_port = nullptr); + ServerBuilder& AddListeningPort(const grpc::string& addr, + std::shared_ptr<ServerCredentials> creds, + int* selected_port = nullptr); /// Add a completion queue for handling asynchronous services /// Caller is required to keep this completion queue live until @@ -144,7 +158,6 @@ class ServerBuilder { }; int max_message_size_; - grpc_compression_options compression_options_; std::vector<std::unique_ptr<ServerBuilderOption>> options_; std::vector<std::unique_ptr<NamedService>> services_; std::vector<Port> ports_; @@ -152,6 +165,15 @@ class ServerBuilder { std::shared_ptr<ServerCredentials> creds_; std::map<grpc::string, std::unique_ptr<ServerBuilderPlugin>> plugins_; AsyncGenericService* generic_service_; + struct { + bool is_set; + grpc_compression_level level; + } maybe_default_compression_level_; + struct { + bool is_set; + grpc_compression_algorithm algorithm; + } maybe_default_compression_algorithm_; + uint32_t enabled_compression_algorithms_bitset_; }; } // namespace grpc diff --git a/include/grpc/compression.h b/include/grpc/compression.h index 8de4b133d4..22bcf0e302 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -51,7 +51,8 @@ GRPCAPI int grpc_compression_algorithm_parse( grpc_compression_algorithm *algorithm); /** Updates \a name with the encoding name corresponding to a valid \a - * algorithm. Returns 1 upon success, 0 otherwise. */ + * algorithm. Note that \a name is statically allocated and must *not* be freed. + * Returns 1 upon success, 0 otherwise. */ GRPCAPI int grpc_compression_algorithm_name( grpc_compression_algorithm algorithm, char **name); diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index 8d2ec3b9d7..9065d1edd0 100644 --- a/include/grpc/impl/codegen/compression_types.h +++ b/include/grpc/impl/codegen/compression_types.h @@ -35,11 +35,17 @@ #define GRPC_IMPL_CODEGEN_COMPRESSION_TYPES_H #include <grpc/impl/codegen/port_platform.h> +#include <stdbool.h> #ifdef __cplusplus extern "C" { #endif +/** To be used as initial metadata key for the request of a concrete compression + * algorithm */ +#define GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ + "grpc-internal-encoding-request" + /** To be used in channel arguments */ #define GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM \ "grpc.default_compression_algorithm" @@ -74,15 +80,24 @@ typedef struct grpc_compression_options { */ uint32_t enabled_algorithms_bitset; - /** The default channel compression algorithm. It'll be used in the absence of + /** The default channel compression level. It'll be used in the absence of * call specific settings. This option corresponds to the channel argument key - * behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM */ - grpc_compression_algorithm default_compression_algorithm; + * behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL. If present, takes + * precedence over \a default_algorithm. + * TODO(dgq): currently only available for server channels. */ + struct { + bool is_set; + grpc_compression_level level; + } default_level; - /** The default channel compression level. It'll be used in the absence of + /** The default channel compression algorithm. It'll be used in the absence of * call specific settings. This option corresponds to the channel argument key - * behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL */ - grpc_compression_algorithm default_compression_level; + * behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM. */ + struct { + bool is_set; + grpc_compression_algorithm algorithm; + } default_algorithm; + } grpc_compression_options; #ifdef __cplusplus diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 7181be4a34..c51ffa4493 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -334,6 +334,12 @@ typedef struct grpc_op { struct { size_t count; grpc_metadata *metadata; + /** If \a is_set, \a compression_level will be used for the call. + * Otherwise, \a compression_level won't be considered */ + struct { + uint8_t is_set; + grpc_compression_level level; + } maybe_compression_level; } send_initial_metadata; grpc_byte_buffer *send_message; struct { |