diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/grpc++/impl/codegen/call.h | 17 | ||||
-rw-r--r-- | include/grpc/compression.h | 30 | ||||
-rw-r--r-- | include/grpc/impl/codegen/compression_types.h | 68 | ||||
-rw-r--r-- | include/grpc/impl/codegen/grpc_types.h | 4 | ||||
-rw-r--r-- | include/grpc/impl/codegen/sync.h | 4 | ||||
-rw-r--r-- | include/grpc/impl/codegen/sync_custom.h | 36 | ||||
-rw-r--r-- | include/grpc/support/sync_custom.h | 24 |
7 files changed, 173 insertions, 10 deletions
diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index f45ab239fc..0cb11b4cca 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -204,12 +204,14 @@ class CallOpSendInitialMetadata { public: CallOpSendInitialMetadata() : send_(false) { maybe_compression_level_.is_set = false; + maybe_stream_compression_level_.is_set = false; } void SendInitialMetadata( const std::multimap<grpc::string, grpc::string>& metadata, uint32_t flags) { maybe_compression_level_.is_set = false; + maybe_stream_compression_level_.is_set = false; send_ = true; flags_ = flags; initial_metadata_ = @@ -221,6 +223,11 @@ class CallOpSendInitialMetadata { maybe_compression_level_.level = level; } + void set_stream_compression_level(grpc_stream_compression_level level) { + maybe_stream_compression_level_.is_set = true; + maybe_stream_compression_level_.level = level; + } + protected: void AddOp(grpc_op* ops, size_t* nops) { if (!send_) return; @@ -236,6 +243,12 @@ class CallOpSendInitialMetadata { op->data.send_initial_metadata.maybe_compression_level.level = maybe_compression_level_.level; } + op->data.send_initial_metadata.maybe_stream_compression_level.is_set = + maybe_stream_compression_level_.is_set; + if (maybe_stream_compression_level_.is_set) { + op->data.send_initial_metadata.maybe_stream_compression_level.level = + maybe_stream_compression_level_.level; + } } void FinishOp(bool* status) { if (!send_) return; @@ -251,6 +264,10 @@ class CallOpSendInitialMetadata { bool is_set; grpc_compression_level level; } maybe_compression_level_; + struct { + bool is_set; + grpc_stream_compression_level level; + } maybe_stream_compression_level_; }; class CallOpSendMessage { diff --git a/include/grpc/compression.h b/include/grpc/compression.h index d47074c9b7..3a8de4b7b8 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -30,25 +30,42 @@ extern "C" { #endif -/** Parses the first \a name_length bytes of \a name as a - * grpc_compression_algorithm instance, updating \a algorithm. Returns 1 upon - * success, 0 otherwise. */ +/** Parses the \a slice as a grpc_compression_algorithm instance and updating \a + * algorithm. Returns 1 upon success, 0 otherwise. */ GRPCAPI int grpc_compression_algorithm_parse( grpc_slice value, grpc_compression_algorithm *algorithm); +/** Parses the \a slice as a grpc_stream_compression_algorithm instance and + * updating \a algorithm. Returns 1 upon success, 0 otherwise. */ +int grpc_stream_compression_algorithm_parse( + grpc_slice name, grpc_stream_compression_algorithm *algorithm); + /** Updates \a name with the encoding name corresponding to a valid \a * 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); +/** Updates \a name with the encoding name corresponding to a valid \a + * algorithm. Note that \a name is statically allocated and must *not* be freed. + * Returns 1 upon success, 0 otherwise. */ +GRPCAPI int grpc_stream_compression_algorithm_name( + grpc_stream_compression_algorithm algorithm, char **name); + /** Returns the compression algorithm corresponding to \a level for the * compression algorithms encoded in the \a accepted_encodings bitset. * - * It abort()s for unknown levels . */ + * It abort()s for unknown levels. */ GRPCAPI grpc_compression_algorithm grpc_compression_algorithm_for_level( grpc_compression_level level, uint32_t accepted_encodings); +/** Returns the stream compression algorithm corresponding to \a level for the + * compression algorithms encoded in the \a accepted_stream_encodings bitset. + * It abort()s for unknown levels. */ +GRPCAPI grpc_stream_compression_algorithm +grpc_stream_compression_algorithm_for_level(grpc_stream_compression_level level, + uint32_t accepted_stream_encodings); + GRPCAPI void grpc_compression_options_init(grpc_compression_options *opts); /** Mark \a algorithm as enabled in \a opts. */ @@ -63,6 +80,11 @@ GRPCAPI void grpc_compression_options_disable_algorithm( GRPCAPI int grpc_compression_options_is_algorithm_enabled( const grpc_compression_options *opts, grpc_compression_algorithm algorithm); +/** Returns true if \a algorithm is marked as enabled in \a opts. */ +GRPCAPI int grpc_compression_options_is_stream_compression_algorithm_enabled( + const grpc_compression_options *opts, + grpc_stream_compression_algorithm algorithm); + #ifdef __cplusplus } #endif diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index f1b2de3f7d..4419e2a447 100644 --- a/include/grpc/impl/codegen/compression_types.h +++ b/include/grpc/impl/codegen/compression_types.h @@ -29,6 +29,11 @@ extern "C" { * algorithm */ #define GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ "grpc-internal-encoding-request" +/** To be used as initial metadata key for the request of a concrete stream + * compression + * algorithm */ +#define GRPC_STREAM_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ + "grpc-internal-stream-encoding-request" /** To be used in channel arguments. * @@ -38,9 +43,17 @@ extern "C" { * Its value is an int from the \a grpc_compression_algorithm enum. */ #define GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM \ "grpc.default_compression_algorithm" +/** Default stream compression algorithm for the channel. + * Its value is an int from the \a grpc_stream_compression_algorithm enum. */ +#define GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM \ + "grpc.default_stream_compression_algorithm" /** Default compression level for the channel. * Its value is an int from the \a grpc_compression_level enum. */ #define GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL "grpc.default_compression_level" +/** Default stream compression level for the channel. + * Its value is an int from the \a grpc_stream_compression_level enum. */ +#define GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_LEVEL \ + "grpc.default_stream_compression_level" /** Compression algorithms supported by the channel. * Its value is a bitset (an int). Bits correspond to algorithms in \a * grpc_compression_algorithm. For example, its LSB corresponds to @@ -50,6 +63,15 @@ extern "C" { * be ignored). */ #define GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET \ "grpc.compression_enabled_algorithms_bitset" +/** Stream compression algorithms supported by the channel. + * Its value is a bitset (an int). Bits correspond to algorithms in \a + * grpc_stream_compression_algorithm. For example, its LSB corresponds to + * GRPC_STREAM_COMPRESS_NONE, the next bit to GRPC_STREAM_COMPRESS_DEFLATE, etc. + * Unset bits disable support for the algorithm. By default all algorithms are + * supported. It's not possible to disable GRPC_STREAM_COMPRESS_NONE (the + * attempt will be ignored). */ +#define GRPC_STREAM_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET \ + "grpc.stream_compression_enabled_algorithms_bitset" /** \} */ /** The various compression algorithms supported by gRPC */ @@ -61,6 +83,13 @@ typedef enum { GRPC_COMPRESS_ALGORITHMS_COUNT } grpc_compression_algorithm; +/** Stream compresssion algorithms supported by gRPC */ +typedef enum { + GRPC_STREAM_COMPRESS_NONE = 0, + GRPC_STREAM_COMPRESS_GZIP, + GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT +} grpc_stream_compression_algorithm; + /** Compression levels allow a party with knowledge of its peer's accepted * encodings to request compression in an abstract way. The level-algorithm * mapping is performed internally and depends on the peer's supported @@ -73,23 +102,42 @@ typedef enum { GRPC_COMPRESS_LEVEL_COUNT } grpc_compression_level; +/** Compression levels for stream compression algorithms */ +typedef enum { + GRPC_STREAM_COMPRESS_LEVEL_NONE = 0, + GRPC_STREAM_COMPRESS_LEVEL_LOW, + GRPC_STREAM_COMPRESS_LEVEL_MED, + GRPC_STREAM_COMPRESS_LEVEL_HIGH, + GRPC_STREAM_COMPRESS_LEVEL_COUNT +} grpc_stream_compression_level; + typedef struct grpc_compression_options { /** All algs are enabled by default. This option corresponds to the channel * argument key behind \a GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET */ uint32_t enabled_algorithms_bitset; + uint32_t enabled_stream_compression_algorithms_bitset; - /** 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_LEVEL. If present, takes - * precedence over \a default_algorithm. + /** The default message-wise 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_LEVEL. If present, + * takes precedence over \a default_algorithm and \a + * default_stream_compression_algorithm. * TODO(dgq): currently only available for server channels. */ struct grpc_compression_options_default_level { int is_set; grpc_compression_level level; } default_level; - /** The default channel compression algorithm. It'll be used in the absence of + /** The default stream compression level. It'll be used in the absence of call + * specefic settings. If present, takes precedence over \a default_level, + * \a default_algorithm and \a default_stream_compression_algorithm. */ + struct grpc_stream_compression_options_default_level { + int is_set; + grpc_stream_compression_level level; + } default_stream_compression_level; + + /** The default message 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_ALGORITHM. */ struct grpc_compression_options_default_algorithm { @@ -97,6 +145,16 @@ typedef struct grpc_compression_options { grpc_compression_algorithm algorithm; } default_algorithm; + /** The default stream compression algorithm. It'll be used in the absence of + * call specific settings. If present, takes precedence over \a + * default_algorithm. This option corresponds to the channel + * argument key behind \a GRPC_STREAM_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM. + */ + struct grpc_stream_compression_options_default_algorithm { + int is_set; + grpc_stream_compression_algorithm algorithm; + } default_stream_compression_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 8813ec8f35..9079506463 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -505,6 +505,10 @@ typedef struct grpc_op { uint8_t is_set; grpc_compression_level level; } maybe_compression_level; + struct grpc_op_send_initial_metadata_maybe_stream_compression_level { + uint8_t is_set; + grpc_stream_compression_level level; + } maybe_stream_compression_level; } send_initial_metadata; struct grpc_op_send_message { struct grpc_byte_buffer *send_message; diff --git a/include/grpc/impl/codegen/sync.h b/include/grpc/impl/codegen/sync.h index de4e99be63..6cdb0c5153 100644 --- a/include/grpc/impl/codegen/sync.h +++ b/include/grpc/impl/codegen/sync.h @@ -49,7 +49,9 @@ extern "C" { #include <grpc/impl/codegen/sync_posix.h> #elif defined(GPR_WINDOWS) #include <grpc/impl/codegen/sync_windows.h> -#elif !defined(GPR_CUSTOM_SYNC) +#elif defined(GPR_CUSTOM_SYNC) +#include <grpc/impl/codegen/sync_custom.h> +#else #error Unable to determine platform for sync #endif diff --git a/include/grpc/impl/codegen/sync_custom.h b/include/grpc/impl/codegen/sync_custom.h new file mode 100644 index 0000000000..0840ad26bf --- /dev/null +++ b/include/grpc/impl/codegen/sync_custom.h @@ -0,0 +1,36 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_IMPL_CODEGEN_SYNC_CUSTOM_H +#define GRPC_IMPL_CODEGEN_SYNC_CUSTOM_H + +#include <grpc/impl/codegen/sync_generic.h> + +/* Users defining GPR_CUSTOM_SYNC need to define the following macros. */ + +#ifdef GPR_CUSTOM_SYNC + +typedef GPR_CUSTOM_MU_TYPE gpr_mu; +typedef GPR_CUSTOM_CV_TYPE gpr_cv; +typedef GPR_CUSTOM_ONCE_TYPE gpr_once; + +#define GPR_ONCE_INIT GPR_CUSTOM_ONCE_INIT + +#endif + +#endif /* GRPC_IMPL_CODEGEN_SYNC_CUSTOM_H */ diff --git a/include/grpc/support/sync_custom.h b/include/grpc/support/sync_custom.h new file mode 100644 index 0000000000..b575f5e002 --- /dev/null +++ b/include/grpc/support/sync_custom.h @@ -0,0 +1,24 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_SUPPORT_SYNC_CUSTOM_H +#define GRPC_SUPPORT_SYNC_CUSTOM_H + +#include <grpc/impl/codegen/sync_custom.h> + +#endif /* GRPC_SUPPORT_SYNC_CUSTOM_H */ |