diff options
author | neksard <neksard@yandex-team.ru> | 2022-02-10 16:45:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:23 +0300 |
commit | 8f7cf138264e0caa318144bf8a2c950e0b0a8593 (patch) | |
tree | 83bf5c8c8047c42d8475e6095df90ccdc3d1b57f /contrib/libs/grpc/include | |
parent | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (diff) | |
download | ydb-8f7cf138264e0caa318144bf8a2c950e0b0a8593.tar.gz |
Restoring authorship annotation for <neksard@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/grpc/include')
55 files changed, 3723 insertions, 3723 deletions
diff --git a/contrib/libs/grpc/include/grpc/grpc.h b/contrib/libs/grpc/include/grpc/grpc.h index 6001117521..044c9c53df 100644 --- a/contrib/libs/grpc/include/grpc/grpc.h +++ b/contrib/libs/grpc/include/grpc/grpc.h @@ -63,8 +63,8 @@ GRPCAPI void grpc_dont_init_openssl(void); /** Initialize the grpc library. - After it's called, a matching invocation to grpc_shutdown() is expected. - + After it's called, a matching invocation to grpc_shutdown() is expected. + It is not safe to call any other grpc functions before calling this. (To avoid overhead, little checking is done, and some things may work. We do not warrant that they will continue to do so in future revisions of this @@ -73,9 +73,9 @@ GRPCAPI void grpc_init(void); /** Shut down the grpc library. - Before it's called, there should haven been a matching invocation to - grpc_init(). - + Before it's called, there should haven been a matching invocation to + grpc_init(). + The last call to grpc_shutdown will initiate cleaning up of grpc library internals, which can happen in another thread. Once the clean-up is done, no memory is used by grpc, nor are any instructions executing within the @@ -83,12 +83,12 @@ GRPCAPI void grpc_init(void); have been destroyed. */ GRPCAPI void grpc_shutdown(void); -/** EXPERIMENTAL. Returns 1 if the grpc library has been initialized. - TODO(ericgribkoff) Decide if this should be promoted to non-experimental as - part of stabilizing the fork support API, as tracked in - https://github.com/grpc/grpc/issues/15334 */ -GRPCAPI int grpc_is_initialized(void); - +/** EXPERIMENTAL. Returns 1 if the grpc library has been initialized. + TODO(ericgribkoff) Decide if this should be promoted to non-experimental as + part of stabilizing the fork support API, as tracked in + https://github.com/grpc/grpc/issues/15334 */ +GRPCAPI int grpc_is_initialized(void); + /** EXPERIMENTAL. Blocking shut down grpc library. This is only for wrapped language to use now. */ GRPCAPI void grpc_shutdown_blocking(void); @@ -115,13 +115,13 @@ GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_next( GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_pluck( void* reserved); -/** Helper function to create a completion queue with grpc_cq_completion_type - of GRPC_CQ_CALLBACK and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING. - This function is experimental. */ -GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_callback( - grpc_experimental_completion_queue_functor* shutdown_callback, - void* reserved); - +/** Helper function to create a completion queue with grpc_cq_completion_type + of GRPC_CQ_CALLBACK and grpc_cq_polling_type of GRPC_CQ_DEFAULT_POLLING. + This function is experimental. */ +GRPCAPI grpc_completion_queue* grpc_completion_queue_create_for_callback( + grpc_experimental_completion_queue_functor* shutdown_callback, + void* reserved); + /** Create a completion queue */ GRPCAPI grpc_completion_queue* grpc_completion_queue_create( const grpc_completion_queue_factory* factory, @@ -253,13 +253,13 @@ GRPCAPI void* grpc_call_arena_alloc(grpc_call* call, size_t size); appropriate to call grpc_completion_queue_next or grpc_completion_queue_pluck consequent to the failed grpc_call_start_batch call. - If a call to grpc_call_start_batch with an empty batch returns - GRPC_CALL_OK, the tag is put in the completion queue immediately. + If a call to grpc_call_start_batch with an empty batch returns + GRPC_CALL_OK, the tag is put in the completion queue immediately. THREAD SAFETY: access to grpc_call_start_batch in multi-threaded environment needs to be synchronized. As an optimization, you may synchronize batches containing just send operations independently from batches containing just - receive operations. Access to grpc_call_start_batch with an empty batch is - thread-compatible. */ + receive operations. Access to grpc_call_start_batch with an empty batch is + thread-compatible. */ GRPCAPI grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, size_t nops, void* tag, void* reserved); @@ -295,11 +295,11 @@ GRPCAPI char* grpc_channel_get_target(grpc_channel* channel); GRPCAPI void grpc_channel_get_info(grpc_channel* channel, const grpc_channel_info* channel_info); -/** EXPERIMENTAL. Resets the channel's connect backoff. - TODO(roth): When we see whether this proves useful, either promote - to non-experimental or remove it. */ -GRPCAPI void grpc_channel_reset_connect_backoff(grpc_channel* channel); - +/** EXPERIMENTAL. Resets the channel's connect backoff. + TODO(roth): When we see whether this proves useful, either promote + to non-experimental or remove it. */ +GRPCAPI void grpc_channel_reset_connect_backoff(grpc_channel* channel); + /** Create a client channel to 'target'. Additional channel level configuration MAY be provided by grpc_channel_args, though the expectation is that most clients will want to simply pass NULL. The user data in 'args' need only @@ -481,56 +481,56 @@ GRPCAPI void grpc_resource_quota_unref(grpc_resource_quota* resource_quota); GRPCAPI void grpc_resource_quota_resize(grpc_resource_quota* resource_quota, size_t new_size); -/** Update the size of the maximum number of threads allowed */ -GRPCAPI void grpc_resource_quota_set_max_threads( - grpc_resource_quota* resource_quota, int new_max_threads); - +/** Update the size of the maximum number of threads allowed */ +GRPCAPI void grpc_resource_quota_set_max_threads( + grpc_resource_quota* resource_quota, int new_max_threads); + /** Fetch a vtable for a grpc_channel_arg that points to a grpc_resource_quota */ GRPCAPI const grpc_arg_pointer_vtable* grpc_resource_quota_arg_vtable(void); -/************* CHANNELZ API *************/ -/** Channelz is under active development. The following APIs will see some - churn as the feature is implemented. This comment will be removed once - channelz is officially supported, and these APIs become stable. For now - you may track the progress by following this github issue: - https://github.com/grpc/grpc/issues/15340 - - the following APIs return allocated JSON strings that match the response - objects from the channelz proto, found here: - https://github.com/grpc/grpc/blob/master/src/proto/grpc/channelz/channelz.proto. - - For easy conversion to protobuf, The JSON is formatted according to: - https://developers.google.com/protocol-buffers/docs/proto3#json. */ - -/* Gets all root channels (i.e. channels the application has directly - created). This does not include subchannels nor non-top level channels. - The returned string is allocated and must be freed by the application. */ -GRPCAPI char* grpc_channelz_get_top_channels(intptr_t start_channel_id); - -/* Gets all servers that exist in the process. */ -GRPCAPI char* grpc_channelz_get_servers(intptr_t start_server_id); - -/* Returns a single Server, or else a NOT_FOUND code. */ -GRPCAPI char* grpc_channelz_get_server(intptr_t server_id); - -/* Gets all server sockets that exist in the server. */ -GRPCAPI char* grpc_channelz_get_server_sockets(intptr_t server_id, - intptr_t start_socket_id, - intptr_t max_results); - -/* Returns a single Channel, or else a NOT_FOUND code. The returned string - is allocated and must be freed by the application. */ -GRPCAPI char* grpc_channelz_get_channel(intptr_t channel_id); - -/* Returns a single Subchannel, or else a NOT_FOUND code. The returned string - is allocated and must be freed by the application. */ -GRPCAPI char* grpc_channelz_get_subchannel(intptr_t subchannel_id); - -/* Returns a single Socket, or else a NOT_FOUND code. The returned string - is allocated and must be freed by the application. */ -GRPCAPI char* grpc_channelz_get_socket(intptr_t socket_id); - +/************* CHANNELZ API *************/ +/** Channelz is under active development. The following APIs will see some + churn as the feature is implemented. This comment will be removed once + channelz is officially supported, and these APIs become stable. For now + you may track the progress by following this github issue: + https://github.com/grpc/grpc/issues/15340 + + the following APIs return allocated JSON strings that match the response + objects from the channelz proto, found here: + https://github.com/grpc/grpc/blob/master/src/proto/grpc/channelz/channelz.proto. + + For easy conversion to protobuf, The JSON is formatted according to: + https://developers.google.com/protocol-buffers/docs/proto3#json. */ + +/* Gets all root channels (i.e. channels the application has directly + created). This does not include subchannels nor non-top level channels. + The returned string is allocated and must be freed by the application. */ +GRPCAPI char* grpc_channelz_get_top_channels(intptr_t start_channel_id); + +/* Gets all servers that exist in the process. */ +GRPCAPI char* grpc_channelz_get_servers(intptr_t start_server_id); + +/* Returns a single Server, or else a NOT_FOUND code. */ +GRPCAPI char* grpc_channelz_get_server(intptr_t server_id); + +/* Gets all server sockets that exist in the server. */ +GRPCAPI char* grpc_channelz_get_server_sockets(intptr_t server_id, + intptr_t start_socket_id, + intptr_t max_results); + +/* Returns a single Channel, or else a NOT_FOUND code. The returned string + is allocated and must be freed by the application. */ +GRPCAPI char* grpc_channelz_get_channel(intptr_t channel_id); + +/* Returns a single Subchannel, or else a NOT_FOUND code. The returned string + is allocated and must be freed by the application. */ +GRPCAPI char* grpc_channelz_get_subchannel(intptr_t subchannel_id); + +/* Returns a single Socket, or else a NOT_FOUND code. The returned string + is allocated and must be freed by the application. */ +GRPCAPI char* grpc_channelz_get_socket(intptr_t socket_id); + #ifdef __cplusplus } #endif diff --git a/contrib/libs/grpc/include/grpc/grpc_security.h b/contrib/libs/grpc/include/grpc/grpc_security.h index 1810681b76..9d9ed59b77 100644 --- a/contrib/libs/grpc/include/grpc/grpc_security.h +++ b/contrib/libs/grpc/include/grpc/grpc_security.h @@ -213,26 +213,26 @@ typedef struct { void (*verify_peer_destruct)(void* userdata); } verify_peer_options; -/** Object that holds additional peer-verification options on a secure - channel. */ -typedef struct { - /** If non-NULL this callback will be invoked with the expected - target_name, the peer's certificate (in PEM format), and whatever - userdata pointer is set below. If a non-zero value is returned by this - callback then it is treated as a verification failure. Invocation of - the callback is blocking, so any implementation should be light-weight. - */ - int (*verify_peer_callback)(const char* target_name, const char* peer_pem, - void* userdata); - /** Arbitrary userdata that will be passed as the last argument to - verify_peer_callback. */ - void* verify_peer_callback_userdata; - /** A destruct callback that will be invoked when the channel is being - cleaned up. The userdata argument will be passed to it. The intent is - to perform any cleanup associated with that userdata. */ - void (*verify_peer_destruct)(void* userdata); +/** Object that holds additional peer-verification options on a secure + channel. */ +typedef struct { + /** If non-NULL this callback will be invoked with the expected + target_name, the peer's certificate (in PEM format), and whatever + userdata pointer is set below. If a non-zero value is returned by this + callback then it is treated as a verification failure. Invocation of + the callback is blocking, so any implementation should be light-weight. + */ + int (*verify_peer_callback)(const char* target_name, const char* peer_pem, + void* userdata); + /** Arbitrary userdata that will be passed as the last argument to + verify_peer_callback. */ + void* verify_peer_callback_userdata; + /** A destruct callback that will be invoked when the channel is being + cleaned up. The userdata argument will be passed to it. The intent is + to perform any cleanup associated with that userdata. */ + void (*verify_peer_destruct)(void* userdata); } grpc_ssl_verify_peer_options; - + /** Deprecated in favor of grpc_ssl_server_credentials_create_ex. It will be removed after all of its call sites are migrated to grpc_ssl_server_credentials_create_ex. Creates an SSL credentials object. @@ -255,17 +255,17 @@ typedef struct { particularly on mobile platforms such as iOS. - pem_key_cert_pair is a pointer on the object containing client's private key and certificate chain. This parameter can be NULL if the client does - not have such a key/cert pair. - - verify_options is an optional verify_peer_options object which holds - additional options controlling how peer certificates are verified. For - example, you can supply a callback which receives the peer's certificate - with which you can do additional verification. Can be NULL, in which - case verification will retain default behavior. Any settings in - verify_options are copied during this call, so the verify_options - object can be released afterwards. */ + not have such a key/cert pair. + - verify_options is an optional verify_peer_options object which holds + additional options controlling how peer certificates are verified. For + example, you can supply a callback which receives the peer's certificate + with which you can do additional verification. Can be NULL, in which + case verification will retain default behavior. Any settings in + verify_options are copied during this call, so the verify_options + object can be released afterwards. */ GRPCAPI grpc_channel_credentials* grpc_ssl_credentials_create( const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair, - const verify_peer_options* verify_options, void* reserved); + const verify_peer_options* verify_options, void* reserved); /* Creates an SSL credentials object. The security level of the resulting connection is GRPC_PRIVACY_AND_INTEGRITY. @@ -656,14 +656,14 @@ typedef struct grpc_alts_credentials_options grpc_alts_credentials_options; * It is used for experimental purpose for now and subject to change. */ GRPCAPI grpc_alts_credentials_options* -grpc_alts_credentials_client_options_create(void); +grpc_alts_credentials_client_options_create(void); /** * This method creates a grpc ALTS credentials server options instance. * It is used for experimental purpose for now and subject to change. */ GRPCAPI grpc_alts_credentials_options* -grpc_alts_credentials_server_options_create(void); +grpc_alts_credentials_server_options_create(void); /** * This method adds a target service account to grpc client's ALTS credentials @@ -710,69 +710,69 @@ GRPCAPI grpc_channel_credentials* grpc_alts_credentials_create( GRPCAPI grpc_server_credentials* grpc_alts_server_credentials_create( const grpc_alts_credentials_options* options); -/** --- Local channel/server credentials --- **/ - -/** +/** --- Local channel/server credentials --- **/ + +/** * This method creates a local channel credential object. The security level * of the resulting connection is GRPC_PRIVACY_AND_INTEGRITY for UDS and * GRPC_SECURITY_NONE for LOCAL_TCP. It is used for experimental purpose * for now and subject to change. - * - * - type: local connection type - * - * It returns the created local channel credential object. - */ -GRPCAPI grpc_channel_credentials* grpc_local_credentials_create( - grpc_local_connect_type type); - -/** - * This method creates a local server credential object. It is used for - * experimental purpose for now and subject to change. - * - * - type: local connection type - * - * It returns the created local server credential object. - */ -GRPCAPI grpc_server_credentials* grpc_local_server_credentials_create( - grpc_local_connect_type type); - + * + * - type: local connection type + * + * It returns the created local channel credential object. + */ +GRPCAPI grpc_channel_credentials* grpc_local_credentials_create( + grpc_local_connect_type type); + +/** + * This method creates a local server credential object. It is used for + * experimental purpose for now and subject to change. + * + * - type: local connection type + * + * It returns the created local server credential object. + */ +GRPCAPI grpc_server_credentials* grpc_local_server_credentials_create( + grpc_local_connect_type type); + /** --- TLS channel/server credentials --- - * It is used for experimental purpose for now and subject to change. */ - + * It is used for experimental purpose for now and subject to change. */ + /** Struct for indicating errors. It is used for * experimental purpose for now and subject to change. */ typedef struct grpc_tls_error_details grpc_tls_error_details; -/** Config for TLS key materials. It is used for - * experimental purpose for now and subject to change. */ -typedef struct grpc_tls_key_materials_config grpc_tls_key_materials_config; - -/** Config for TLS credential reload. It is used for - * experimental purpose for now and subject to change. */ -typedef struct grpc_tls_credential_reload_config - grpc_tls_credential_reload_config; - -/** Config for TLS server authorization check. It is used for - * experimental purpose for now and subject to change. */ -typedef struct grpc_tls_server_authorization_check_config - grpc_tls_server_authorization_check_config; - -/** TLS credentials options. It is used for - * experimental purpose for now and subject to change. */ -typedef struct grpc_tls_credentials_options grpc_tls_credentials_options; - -/** Create an empty TLS credentials options. It is used for - * experimental purpose for now and subject to change. */ +/** Config for TLS key materials. It is used for + * experimental purpose for now and subject to change. */ +typedef struct grpc_tls_key_materials_config grpc_tls_key_materials_config; + +/** Config for TLS credential reload. It is used for + * experimental purpose for now and subject to change. */ +typedef struct grpc_tls_credential_reload_config + grpc_tls_credential_reload_config; + +/** Config for TLS server authorization check. It is used for + * experimental purpose for now and subject to change. */ +typedef struct grpc_tls_server_authorization_check_config + grpc_tls_server_authorization_check_config; + +/** TLS credentials options. It is used for + * experimental purpose for now and subject to change. */ +typedef struct grpc_tls_credentials_options grpc_tls_credentials_options; + +/** Create an empty TLS credentials options. It is used for + * experimental purpose for now and subject to change. */ GRPCAPI grpc_tls_credentials_options* grpc_tls_credentials_options_create(void); - -/** Set grpc_ssl_client_certificate_request_type field in credentials options - with the provided type. options should not be NULL. - It returns 1 on success and 0 on failure. It is used for - experimental purpose for now and subject to change. */ -GRPCAPI int grpc_tls_credentials_options_set_cert_request_type( - grpc_tls_credentials_options* options, - grpc_ssl_client_certificate_request_type type); - + +/** Set grpc_ssl_client_certificate_request_type field in credentials options + with the provided type. options should not be NULL. + It returns 1 on success and 0 on failure. It is used for + experimental purpose for now and subject to change. */ +GRPCAPI int grpc_tls_credentials_options_set_cert_request_type( + grpc_tls_credentials_options* options, + grpc_ssl_client_certificate_request_type type); + /** Set grpc_tls_server_verification_option field in credentials options with the provided server_verification_option. options should not be NULL. This should be called only on the client side. @@ -786,55 +786,55 @@ GRPCAPI int grpc_tls_credentials_options_set_server_verification_option( grpc_tls_credentials_options* options, grpc_tls_server_verification_option server_verification_option); -/** Set grpc_tls_key_materials_config field in credentials options - with the provided config struct whose ownership is transferred. - Both parameters should not be NULL. - It returns 1 on success and 0 on failure. It is used for - experimental purpose for now and subject to change. */ -GRPCAPI int grpc_tls_credentials_options_set_key_materials_config( - grpc_tls_credentials_options* options, - grpc_tls_key_materials_config* config); - -/** Set grpc_tls_credential_reload_config field in credentials options - with the provided config struct whose ownership is transferred. - Both parameters should not be NULL. - It returns 1 on success and 0 on failure. It is used for - experimental purpose for now and subject to change. */ -GRPCAPI int grpc_tls_credentials_options_set_credential_reload_config( - grpc_tls_credentials_options* options, - grpc_tls_credential_reload_config* config); - -/** Set grpc_tls_server_authorization_check_config field in credentials options - with the provided config struct whose ownership is transferred. - Both parameters should not be NULL. - It returns 1 on success and 0 on failure. It is used for - experimental purpose for now and subject to change. */ -GRPCAPI int grpc_tls_credentials_options_set_server_authorization_check_config( - grpc_tls_credentials_options* options, - grpc_tls_server_authorization_check_config* config); - -/** --- TLS key materials config. --- - It is used for experimental purpose for now and subject to change. */ - -/** Create an empty grpc_tls_key_materials_config instance. - * It is used for experimental purpose for now and subject to change. */ +/** Set grpc_tls_key_materials_config field in credentials options + with the provided config struct whose ownership is transferred. + Both parameters should not be NULL. + It returns 1 on success and 0 on failure. It is used for + experimental purpose for now and subject to change. */ +GRPCAPI int grpc_tls_credentials_options_set_key_materials_config( + grpc_tls_credentials_options* options, + grpc_tls_key_materials_config* config); + +/** Set grpc_tls_credential_reload_config field in credentials options + with the provided config struct whose ownership is transferred. + Both parameters should not be NULL. + It returns 1 on success and 0 on failure. It is used for + experimental purpose for now and subject to change. */ +GRPCAPI int grpc_tls_credentials_options_set_credential_reload_config( + grpc_tls_credentials_options* options, + grpc_tls_credential_reload_config* config); + +/** Set grpc_tls_server_authorization_check_config field in credentials options + with the provided config struct whose ownership is transferred. + Both parameters should not be NULL. + It returns 1 on success and 0 on failure. It is used for + experimental purpose for now and subject to change. */ +GRPCAPI int grpc_tls_credentials_options_set_server_authorization_check_config( + grpc_tls_credentials_options* options, + grpc_tls_server_authorization_check_config* config); + +/** --- TLS key materials config. --- + It is used for experimental purpose for now and subject to change. */ + +/** Create an empty grpc_tls_key_materials_config instance. + * It is used for experimental purpose for now and subject to change. */ GRPCAPI grpc_tls_key_materials_config* grpc_tls_key_materials_config_create( void); - -/** Set grpc_tls_key_materials_config instance with provided a TLS certificate. - It's valid for the caller to provide nullptr pem_root_certs, in which case - the gRPC-provided root cert will be used. pem_key_cert_pairs should not be + +/** Set grpc_tls_key_materials_config instance with provided a TLS certificate. + It's valid for the caller to provide nullptr pem_root_certs, in which case + the gRPC-provided root cert will be used. pem_key_cert_pairs should not be NULL. The ownerships of |pem_root_certs| and |pem_key_cert_pairs| remain with the caller. It returns 1 on success and 0 on failure. It is used for experimental purpose for now and subject to change. - */ -GRPCAPI int grpc_tls_key_materials_config_set_key_materials( - grpc_tls_key_materials_config* config, const char* pem_root_certs, - const grpc_ssl_pem_key_cert_pair** pem_key_cert_pairs, - size_t num_key_cert_pairs); - + */ +GRPCAPI int grpc_tls_key_materials_config_set_key_materials( + grpc_tls_key_materials_config* config, const char* pem_root_certs, + const grpc_ssl_pem_key_cert_pair** pem_key_cert_pairs, + size_t num_key_cert_pairs); + /** Set grpc_tls_key_materials_config instance with a provided version number, which is used to keep track of the version of key materials. It returns 1 on success and 0 on failure. It is used for @@ -850,18 +850,18 @@ GRPCAPI int grpc_tls_key_materials_config_set_version( GRPCAPI int grpc_tls_key_materials_config_get_version( grpc_tls_key_materials_config* config); -/** --- TLS credential reload config. --- - It is used for experimental purpose for now and subject to change.*/ - -typedef struct grpc_tls_credential_reload_arg grpc_tls_credential_reload_arg; - -/** A callback function provided by gRPC to handle the result of credential - reload. It is used when schedule API is implemented asynchronously and - serves to bring the control back to grpc C core. It is used for - experimental purpose for now and subject to change. */ -typedef void (*grpc_tls_on_credential_reload_done_cb)( - grpc_tls_credential_reload_arg* arg); - +/** --- TLS credential reload config. --- + It is used for experimental purpose for now and subject to change.*/ + +typedef struct grpc_tls_credential_reload_arg grpc_tls_credential_reload_arg; + +/** A callback function provided by gRPC to handle the result of credential + reload. It is used when schedule API is implemented asynchronously and + serves to bring the control back to grpc C core. It is used for + experimental purpose for now and subject to change. */ +typedef void (*grpc_tls_on_credential_reload_done_cb)( + grpc_tls_credential_reload_arg* arg); + /** A struct containing all information necessary to schedule/cancel a credential reload request. - cb and cb_user_data represent a gRPC-provided @@ -881,60 +881,60 @@ typedef void (*grpc_tls_on_credential_reload_done_cb)( up any data associated with the context pointer. It is used for experimental purposes for now and subject to change. */ -struct grpc_tls_credential_reload_arg { - grpc_tls_on_credential_reload_done_cb cb; - void* cb_user_data; - grpc_tls_key_materials_config* key_materials_config; +struct grpc_tls_credential_reload_arg { + grpc_tls_on_credential_reload_done_cb cb; + void* cb_user_data; + grpc_tls_key_materials_config* key_materials_config; grpc_ssl_certificate_config_reload_status status; grpc_tls_error_details* error_details; grpc_tls_credential_reload_config* config; void* context; void (*destroy_context)(void* ctx); -}; - -/** Create a grpc_tls_credential_reload_config instance. - - config_user_data is config-specific, read-only user data - that works for all channels created with a credential using the config. - - schedule is a pointer to an application-provided callback used to invoke - credential reload API. The implementation of this method has to be - non-blocking, but can be performed synchronously or asynchronously. +}; + +/** Create a grpc_tls_credential_reload_config instance. + - config_user_data is config-specific, read-only user data + that works for all channels created with a credential using the config. + - schedule is a pointer to an application-provided callback used to invoke + credential reload API. The implementation of this method has to be + non-blocking, but can be performed synchronously or asynchronously. 1) If processing occurs synchronously, it populates arg->key_materials_config, arg->status, and arg->error_details and returns zero. - 2) If processing occurs asynchronously, it returns a non-zero value. - The application then invokes arg->cb when processing is completed. Note - that arg->cb cannot be invoked before schedule API returns. - - cancel is a pointer to an application-provided callback used to cancel - a credential reload request scheduled via an asynchronous schedule API. - arg is used to pinpoint an exact reloading request to be cancelled. - The operation may not have any effect if the request has already been - processed. - - destruct is a pointer to an application-provided callback used to clean up - any data associated with the config. - It is used for experimental purpose for now and subject to change. -*/ -GRPCAPI grpc_tls_credential_reload_config* -grpc_tls_credential_reload_config_create( - const void* config_user_data, - int (*schedule)(void* config_user_data, - grpc_tls_credential_reload_arg* arg), - void (*cancel)(void* config_user_data, grpc_tls_credential_reload_arg* arg), - void (*destruct)(void* config_user_data)); - -/** --- TLS server authorization check config. --- - * It is used for experimental purpose for now and subject to change. */ - -typedef struct grpc_tls_server_authorization_check_arg - grpc_tls_server_authorization_check_arg; - -/** callback function provided by gRPC used to handle the result of server - authorization check. It is used when schedule API is implemented - asynchronously, and serves to bring the control back to gRPC C core. It is - used for experimental purpose for now and subject to change. */ -typedef void (*grpc_tls_on_server_authorization_check_done_cb)( - grpc_tls_server_authorization_check_arg* arg); - -/** A struct containing all information necessary to schedule/cancel a server + 2) If processing occurs asynchronously, it returns a non-zero value. + The application then invokes arg->cb when processing is completed. Note + that arg->cb cannot be invoked before schedule API returns. + - cancel is a pointer to an application-provided callback used to cancel + a credential reload request scheduled via an asynchronous schedule API. + arg is used to pinpoint an exact reloading request to be cancelled. + The operation may not have any effect if the request has already been + processed. + - destruct is a pointer to an application-provided callback used to clean up + any data associated with the config. + It is used for experimental purpose for now and subject to change. +*/ +GRPCAPI grpc_tls_credential_reload_config* +grpc_tls_credential_reload_config_create( + const void* config_user_data, + int (*schedule)(void* config_user_data, + grpc_tls_credential_reload_arg* arg), + void (*cancel)(void* config_user_data, grpc_tls_credential_reload_arg* arg), + void (*destruct)(void* config_user_data)); + +/** --- TLS server authorization check config. --- + * It is used for experimental purpose for now and subject to change. */ + +typedef struct grpc_tls_server_authorization_check_arg + grpc_tls_server_authorization_check_arg; + +/** callback function provided by gRPC used to handle the result of server + authorization check. It is used when schedule API is implemented + asynchronously, and serves to bring the control back to gRPC C core. It is + used for experimental purpose for now and subject to change. */ +typedef void (*grpc_tls_on_server_authorization_check_done_cb)( + grpc_tls_server_authorization_check_arg* arg); + +/** A struct containing all information necessary to schedule/cancel a server authorization check request. - cb and cb_user_data represent a gRPC-provided callback and an argument passed to it. @@ -956,49 +956,49 @@ typedef void (*grpc_tls_on_server_authorization_check_done_cb)( up any data associated with the context pointer. It is used for experimental purpose for now and subject to change. */ -struct grpc_tls_server_authorization_check_arg { - grpc_tls_on_server_authorization_check_done_cb cb; - void* cb_user_data; +struct grpc_tls_server_authorization_check_arg { + grpc_tls_on_server_authorization_check_done_cb cb; + void* cb_user_data; int success; - const char* target_name; - const char* peer_cert; + const char* target_name; + const char* peer_cert; const char* peer_cert_full_chain; - grpc_status_code status; + grpc_status_code status; grpc_tls_error_details* error_details; grpc_tls_server_authorization_check_config* config; void* context; void (*destroy_context)(void* ctx); -}; - -/** Create a grpc_tls_server_authorization_check_config instance. - - config_user_data is config-specific, read-only user data - that works for all channels created with a credential using the config. - - schedule is a pointer to an application-provided callback used to invoke - server authorization check API. The implementation of this method has to - be non-blocking, but can be performed synchronously or asynchronously. - 1)If processing occurs synchronously, it populates arg->result, - arg->status, and arg->error_details and returns zero. - 2) If processing occurs asynchronously, it returns a non-zero value. The - application then invokes arg->cb when processing is completed. Note that - arg->cb cannot be invoked before schedule API returns. - - cancel is a pointer to an application-provided callback used to cancel a - server authorization check request scheduled via an asynchronous schedule - API. arg is used to pinpoint an exact check request to be cancelled. The - operation may not have any effect if the request has already been - processed. - - destruct is a pointer to an application-provided callback used to clean up - any data associated with the config. - It is used for experimental purpose for now and subject to change. -*/ -GRPCAPI grpc_tls_server_authorization_check_config* -grpc_tls_server_authorization_check_config_create( - const void* config_user_data, - int (*schedule)(void* config_user_data, - grpc_tls_server_authorization_check_arg* arg), - void (*cancel)(void* config_user_data, - grpc_tls_server_authorization_check_arg* arg), - void (*destruct)(void* config_user_data)); - +}; + +/** Create a grpc_tls_server_authorization_check_config instance. + - config_user_data is config-specific, read-only user data + that works for all channels created with a credential using the config. + - schedule is a pointer to an application-provided callback used to invoke + server authorization check API. The implementation of this method has to + be non-blocking, but can be performed synchronously or asynchronously. + 1)If processing occurs synchronously, it populates arg->result, + arg->status, and arg->error_details and returns zero. + 2) If processing occurs asynchronously, it returns a non-zero value. The + application then invokes arg->cb when processing is completed. Note that + arg->cb cannot be invoked before schedule API returns. + - cancel is a pointer to an application-provided callback used to cancel a + server authorization check request scheduled via an asynchronous schedule + API. arg is used to pinpoint an exact check request to be cancelled. The + operation may not have any effect if the request has already been + processed. + - destruct is a pointer to an application-provided callback used to clean up + any data associated with the config. + It is used for experimental purpose for now and subject to change. +*/ +GRPCAPI grpc_tls_server_authorization_check_config* +grpc_tls_server_authorization_check_config_create( + const void* config_user_data, + int (*schedule)(void* config_user_data, + grpc_tls_server_authorization_check_arg* arg), + void (*cancel)(void* config_user_data, + grpc_tls_server_authorization_check_arg* arg), + void (*destruct)(void* config_user_data)); + /** * This method creates a TLS channel credential object. * It takes ownership of the options parameter. The security level diff --git a/contrib/libs/grpc/include/grpc/grpc_security_constants.h b/contrib/libs/grpc/include/grpc/grpc_security_constants.h index a62f76753b..6ab519db7e 100644 --- a/contrib/libs/grpc/include/grpc/grpc_security_constants.h +++ b/contrib/libs/grpc/include/grpc/grpc_security_constants.h @@ -60,51 +60,51 @@ typedef enum { } grpc_ssl_certificate_config_reload_status; typedef enum { - /** Server does not request client certificate. - The certificate presented by the client is not checked by the server at - all. (A client may present a self signed or signed certificate or not - present a certificate at all and any of those option would be accepted) */ + /** Server does not request client certificate. + The certificate presented by the client is not checked by the server at + all. (A client may present a self signed or signed certificate or not + present a certificate at all and any of those option would be accepted) */ GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, /** Server requests client certificate but does not enforce that the client presents a certificate. If the client presents a certificate, the client authentication is left to - the application (the necessary metadata will be available to the - application via authentication context properties, see grpc_auth_context). + the application (the necessary metadata will be available to the + application via authentication context properties, see grpc_auth_context). - The client's key certificate pair must be valid for the SSL connection to - be established. */ + The client's key certificate pair must be valid for the SSL connection to + be established. */ GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, /** Server requests client certificate but does not enforce that the client presents a certificate. If the client presents a certificate, the client authentication is done by - the gRPC framework. (For a successful connection the client needs to either - present a certificate that can be verified against the root certificate - configured by the server or not present a certificate at all) + the gRPC framework. (For a successful connection the client needs to either + present a certificate that can be verified against the root certificate + configured by the server or not present a certificate at all) - The client's key certificate pair must be valid for the SSL connection to - be established. */ + The client's key certificate pair must be valid for the SSL connection to + be established. */ GRPC_SSL_REQUEST_CLIENT_CERTIFICATE_AND_VERIFY, - /** Server requests client certificate and enforces that the client presents a + /** Server requests client certificate and enforces that the client presents a certificate. If the client presents a certificate, the client authentication is left to - the application (the necessary metadata will be available to the - application via authentication context properties, see grpc_auth_context). + the application (the necessary metadata will be available to the + application via authentication context properties, see grpc_auth_context). - The client's key certificate pair must be valid for the SSL connection to - be established. */ + The client's key certificate pair must be valid for the SSL connection to + be established. */ GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_BUT_DONT_VERIFY, - /** Server requests client certificate and enforces that the client presents a + /** Server requests client certificate and enforces that the client presents a certificate. The certificate presented by the client is verified by the gRPC framework. - (For a successful connection the client needs to present a certificate that - can be verified against the root certificate configured by the server) + (For a successful connection the client needs to present a certificate that + can be verified against the root certificate configured by the server) - The client's key certificate pair must be valid for the SSL connection to - be established. */ + The client's key certificate pair must be valid for the SSL connection to + be established. */ GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY } grpc_ssl_client_certificate_request_type; @@ -133,12 +133,12 @@ typedef enum { GRPC_TLS_SKIP_ALL_SERVER_VERIFICATION } grpc_tls_server_verification_option; -/** - * Type of local connections for which local channel/server credentials will be - * applied. It supports UDS and local TCP connections. - */ -typedef enum { UDS = 0, LOCAL_TCP } grpc_local_connect_type; - +/** + * Type of local connections for which local channel/server credentials will be + * applied. It supports UDS and local TCP connections. + */ +typedef enum { UDS = 0, LOCAL_TCP } grpc_local_connect_type; + /** The TLS versions that are supported by the SSL stack. **/ typedef enum { TLS1_2, TLS1_3 } grpc_tls_version; diff --git a/contrib/libs/grpc/include/grpc/impl/codegen/atm_gcc_sync.h b/contrib/libs/grpc/include/grpc/impl/codegen/atm_gcc_sync.h index 728c3d5412..159d00d49b 100644 --- a/contrib/libs/grpc/include/grpc/impl/codegen/atm_gcc_sync.h +++ b/contrib/libs/grpc/include/grpc/impl/codegen/atm_gcc_sync.h @@ -26,8 +26,8 @@ typedef intptr_t gpr_atm; #define GPR_ATM_MAX INTPTR_MAX #define GPR_ATM_MIN INTPTR_MIN -#define GPR_ATM_INC_CAS_THEN(blah) blah -#define GPR_ATM_INC_ADD_THEN(blah) blah +#define GPR_ATM_INC_CAS_THEN(blah) blah +#define GPR_ATM_INC_ADD_THEN(blah) blah #define GPR_ATM_COMPILE_BARRIER_() __asm__ __volatile__("" : : : "memory") diff --git a/contrib/libs/grpc/include/grpc/impl/codegen/atm_windows.h b/contrib/libs/grpc/include/grpc/impl/codegen/atm_windows.h index c016b90095..046580a03c 100644 --- a/contrib/libs/grpc/include/grpc/impl/codegen/atm_windows.h +++ b/contrib/libs/grpc/include/grpc/impl/codegen/atm_windows.h @@ -25,8 +25,8 @@ typedef intptr_t gpr_atm; #define GPR_ATM_MAX INTPTR_MAX #define GPR_ATM_MIN INTPTR_MIN -#define GPR_ATM_INC_CAS_THEN(blah) blah -#define GPR_ATM_INC_ADD_THEN(blah) blah +#define GPR_ATM_INC_CAS_THEN(blah) blah +#define GPR_ATM_INC_ADD_THEN(blah) blah #define gpr_atm_full_barrier MemoryBarrier diff --git a/contrib/libs/grpc/include/grpc/impl/codegen/compression_types.h b/contrib/libs/grpc/include/grpc/impl/codegen/compression_types.h index f778b005b9..eeb74ed993 100644 --- a/contrib/libs/grpc/include/grpc/impl/codegen/compression_types.h +++ b/contrib/libs/grpc/include/grpc/impl/codegen/compression_types.h @@ -52,8 +52,8 @@ extern "C" { "grpc.compression_enabled_algorithms_bitset" /** \} */ -/** The various compression algorithms supported by gRPC (not sorted by - * compression level) */ +/** The various compression algorithms supported by gRPC (not sorted by + * compression level) */ typedef enum { GRPC_COMPRESS_NONE = 0, GRPC_COMPRESS_DEFLATE, diff --git a/contrib/libs/grpc/include/grpc/impl/codegen/fork.h b/contrib/libs/grpc/include/grpc/impl/codegen/fork.h index 555df3490f..6d653f8c41 100644 --- a/contrib/libs/grpc/include/grpc/impl/codegen/fork.h +++ b/contrib/libs/grpc/include/grpc/impl/codegen/fork.h @@ -37,12 +37,12 @@ * } */ -void grpc_prefork(void); +void grpc_prefork(void); -void grpc_postfork_parent(void); +void grpc_postfork_parent(void); -void grpc_postfork_child(void); +void grpc_postfork_child(void); -void grpc_fork_handlers_auto_register(void); +void grpc_fork_handlers_auto_register(void); #endif /* GRPC_IMPL_CODEGEN_FORK_H */ diff --git a/contrib/libs/grpc/include/grpc/impl/codegen/grpc_types.h b/contrib/libs/grpc/include/grpc/impl/codegen/grpc_types.h index 07066f0e1d..b2a01c7ce5 100644 --- a/contrib/libs/grpc/include/grpc/impl/codegen/grpc_types.h +++ b/contrib/libs/grpc/include/grpc/impl/codegen/grpc_types.h @@ -164,7 +164,7 @@ typedef struct { /** Maximum time that a channel may exist. Int valued, milliseconds. * INT_MAX means unlimited. */ #define GRPC_ARG_MAX_CONNECTION_AGE_MS "grpc.max_connection_age_ms" -/** Grace period after the channel reaches its max age. Int valued, +/** Grace period after the channel reaches its max age. Int valued, milliseconds. INT_MAX means unlimited. */ #define GRPC_ARG_MAX_CONNECTION_AGE_GRACE_MS "grpc.max_connection_age_grace_ms" /** Timeout after the last RPC finishes on the client channel at which the @@ -206,7 +206,7 @@ typedef struct { data/header frame, Int valued, milliseconds. */ #define GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS \ "grpc.http2.min_time_between_pings_ms" -/** Minimum allowed time between a server receiving successive ping frames +/** Minimum allowed time between a server receiving successive ping frames without sending any data/header frame. Int valued, milliseconds */ #define GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS \ @@ -304,16 +304,16 @@ typedef struct { #define GRPC_ARG_SOCKET_MUTATOR "grpc.socket_mutator" /** The grpc_socket_factory instance to create and bind sockets. A pointer. */ #define GRPC_ARG_SOCKET_FACTORY "grpc.socket_factory" -/** The maximum amount of memory used by trace events per channel trace node. - * Once the maximum is reached, subsequent events will evict the oldest events - * from the buffer. The unit for this knob is bytes. Setting it to zero causes - * channel tracing to be disabled. */ -#define GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE \ - "grpc.max_channel_trace_event_memory_per_node" -/** If non-zero, gRPC library will track stats and information at at per channel - * level. Disabling channelz naturally disables channel tracing. The default - * is for channelz to be enabled. */ -#define GRPC_ARG_ENABLE_CHANNELZ "grpc.enable_channelz" +/** The maximum amount of memory used by trace events per channel trace node. + * Once the maximum is reached, subsequent events will evict the oldest events + * from the buffer. The unit for this knob is bytes. Setting it to zero causes + * channel tracing to be disabled. */ +#define GRPC_ARG_MAX_CHANNEL_TRACE_EVENT_MEMORY_PER_NODE \ + "grpc.max_channel_trace_event_memory_per_node" +/** If non-zero, gRPC library will track stats and information at at per channel + * level. Disabling channelz naturally disables channel tracing. The default + * is for channelz to be enabled. */ +#define GRPC_ARG_ENABLE_CHANNELZ "grpc.enable_channelz" /** If non-zero, Cronet transport will coalesce packets to fewer frames * when possible. */ #define GRPC_ARG_USE_CRONET_PACKET_COALESCING \ @@ -376,40 +376,40 @@ typedef struct { #define GRPC_ARG_PER_RPC_RETRY_BUFFER_SIZE "grpc.per_rpc_retry_buffer_size" /** Channel arg that carries the bridged objective c object for custom metrics * logging filter. */ -#define GRPC_ARG_MOBILE_LOG_CONTEXT "grpc.mobile_log_context" +#define GRPC_ARG_MOBILE_LOG_CONTEXT "grpc.mobile_log_context" /** If non-zero, client authority filter is disabled for the channel */ #define GRPC_ARG_DISABLE_CLIENT_AUTHORITY_FILTER \ "grpc.disable_client_authority_filter" -/** If set to zero, disables use of http proxies. Enabled by default. */ -#define GRPC_ARG_ENABLE_HTTP_PROXY "grpc.enable_http_proxy" +/** If set to zero, disables use of http proxies. Enabled by default. */ +#define GRPC_ARG_ENABLE_HTTP_PROXY "grpc.enable_http_proxy" /** Channel arg to set http proxy per channel. If set, the channel arg * value will be prefered over the envrionment variable settings. */ #define GRPC_ARG_HTTP_PROXY "grpc.http_proxy" -/** If set to non zero, surfaces the user agent string to the server. User - agent is surfaced by default. */ -#define GRPC_ARG_SURFACE_USER_AGENT "grpc.surface_user_agent" -/** If set, inhibits health checking (which may be enabled via the - * service config.) */ -#define GRPC_ARG_INHIBIT_HEALTH_CHECKING "grpc.inhibit_health_checking" -/** If set, the channel's resolver is allowed to query for SRV records. - * For example, this is useful as a way to enable the "grpclb" - * load balancing policy. Note that this only works with the "ares" - * DNS resolver, and isn't supported by the "native" DNS resolver. */ -#define GRPC_ARG_DNS_ENABLE_SRV_QUERIES "grpc.dns_enable_srv_queries" +/** If set to non zero, surfaces the user agent string to the server. User + agent is surfaced by default. */ +#define GRPC_ARG_SURFACE_USER_AGENT "grpc.surface_user_agent" +/** If set, inhibits health checking (which may be enabled via the + * service config.) */ +#define GRPC_ARG_INHIBIT_HEALTH_CHECKING "grpc.inhibit_health_checking" +/** If set, the channel's resolver is allowed to query for SRV records. + * For example, this is useful as a way to enable the "grpclb" + * load balancing policy. Note that this only works with the "ares" + * DNS resolver, and isn't supported by the "native" DNS resolver. */ +#define GRPC_ARG_DNS_ENABLE_SRV_QUERIES "grpc.dns_enable_srv_queries" /** If set, determines an upper bound on the number of milliseconds that the * c-ares based DNS resolver will wait on queries before cancelling them. * The default value is 120,000. Setting this to "0" will disable the * overall timeout entirely. Note that this doesn't include internal c-ares * timeouts/backoff/retry logic, and so the actual DNS resolution may time out * sooner than the value specified here. */ -#define GRPC_ARG_DNS_ARES_QUERY_TIMEOUT_MS "grpc.dns_ares_query_timeout" -/** If set, uses a local subchannel pool within the channel. Otherwise, uses the - * global subchannel pool. */ -#define GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL "grpc.use_local_subchannel_pool" -/** gRPC Objective-C channel pooling domain string. */ -#define GRPC_ARG_CHANNEL_POOL_DOMAIN "grpc.channel_pooling_domain" -/** gRPC Objective-C channel pooling id. */ -#define GRPC_ARG_CHANNEL_ID "grpc.channel_id" +#define GRPC_ARG_DNS_ARES_QUERY_TIMEOUT_MS "grpc.dns_ares_query_timeout" +/** If set, uses a local subchannel pool within the channel. Otherwise, uses the + * global subchannel pool. */ +#define GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL "grpc.use_local_subchannel_pool" +/** gRPC Objective-C channel pooling domain string. */ +#define GRPC_ARG_CHANNEL_POOL_DOMAIN "grpc.channel_pooling_domain" +/** gRPC Objective-C channel pooling id. */ +#define GRPC_ARG_CHANNEL_ID "grpc.channel_id" /** \} */ /** Result of a grpc call. If the caller satisfies the prerequisites of a @@ -722,37 +722,37 @@ typedef enum { GRPC_CQ_NEXT, /** Events are popped out by calling grpc_completion_queue_pluck() API ONLY*/ - GRPC_CQ_PLUCK, - - /** EXPERIMENTAL: Events trigger a callback specified as the tag */ - GRPC_CQ_CALLBACK + GRPC_CQ_PLUCK, + + /** EXPERIMENTAL: Events trigger a callback specified as the tag */ + GRPC_CQ_CALLBACK } grpc_cq_completion_type; -/** EXPERIMENTAL: Specifies an interface class to be used as a tag - for callback-based completion queues. This can be used directly, - as the first element of a struct in C, or as a base class in C++. - Its "run" value should be assigned to some non-member function, such as - a static method. */ -typedef struct grpc_experimental_completion_queue_functor { - /** The run member specifies a function that will be called when this - tag is extracted from the completion queue. Its arguments will be a - pointer to this functor and a boolean that indicates whether the - operation succeeded (non-zero) or failed (zero) */ - void (*functor_run)(struct grpc_experimental_completion_queue_functor*, int); - +/** EXPERIMENTAL: Specifies an interface class to be used as a tag + for callback-based completion queues. This can be used directly, + as the first element of a struct in C, or as a base class in C++. + Its "run" value should be assigned to some non-member function, such as + a static method. */ +typedef struct grpc_experimental_completion_queue_functor { + /** The run member specifies a function that will be called when this + tag is extracted from the completion queue. Its arguments will be a + pointer to this functor and a boolean that indicates whether the + operation succeeded (non-zero) or failed (zero) */ + void (*functor_run)(struct grpc_experimental_completion_queue_functor*, int); + /** The inlineable member specifies whether this functor can be run inline. This should only be used for trivial internally-defined functors. */ int inlineable; - /** The following fields are not API. They are meant for internal use. */ - int internal_success; - struct grpc_experimental_completion_queue_functor* internal_next; -} grpc_experimental_completion_queue_functor; - -/* The upgrade to version 2 is currently experimental. */ - -#define GRPC_CQ_CURRENT_VERSION 2 -#define GRPC_CQ_VERSION_MINIMUM_FOR_CALLBACKABLE 2 + /** The following fields are not API. They are meant for internal use. */ + int internal_success; + struct grpc_experimental_completion_queue_functor* internal_next; +} grpc_experimental_completion_queue_functor; + +/* The upgrade to version 2 is currently experimental. */ + +#define GRPC_CQ_CURRENT_VERSION 2 +#define GRPC_CQ_VERSION_MINIMUM_FOR_CALLBACKABLE 2 typedef struct grpc_completion_queue_attributes { /** The version number of this structure. More fields might be added to this structure in future. */ @@ -761,15 +761,15 @@ typedef struct grpc_completion_queue_attributes { grpc_cq_completion_type cq_completion_type; grpc_cq_polling_type cq_polling_type; - - /* END OF VERSION 1 CQ ATTRIBUTES */ - - /* EXPERIMENTAL: START OF VERSION 2 CQ ATTRIBUTES */ - /** When creating a callbackable CQ, pass in a functor to get invoked when - * shutdown is complete */ - grpc_experimental_completion_queue_functor* cq_shutdown_cb; - - /* END OF VERSION 2 CQ ATTRIBUTES */ + + /* END OF VERSION 1 CQ ATTRIBUTES */ + + /* EXPERIMENTAL: START OF VERSION 2 CQ ATTRIBUTES */ + /** When creating a callbackable CQ, pass in a functor to get invoked when + * shutdown is complete */ + grpc_experimental_completion_queue_functor* cq_shutdown_cb; + + /* END OF VERSION 2 CQ ATTRIBUTES */ } grpc_completion_queue_attributes; /** The completion queue factory structure is opaque to the callers of grpc */ diff --git a/contrib/libs/grpc/include/grpc/impl/codegen/log.h b/contrib/libs/grpc/include/grpc/impl/codegen/log.h index ad7f024158..e09ace5f95 100644 --- a/contrib/libs/grpc/include/grpc/impl/codegen/log.h +++ b/contrib/libs/grpc/include/grpc/impl/codegen/log.h @@ -1,112 +1,112 @@ -/* - * - * Copyright 2015 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_LOG_H -#define GRPC_IMPL_CODEGEN_LOG_H - -#include <grpc/impl/codegen/port_platform.h> - -#include <stdarg.h> -#include <stdlib.h> /* for abort() */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** GPR log API. - - Usage (within grpc): - - int argument1 = 3; - char* argument2 = "hello"; - gpr_log(GPR_DEBUG, "format string %d", argument1); - gpr_log(GPR_INFO, "hello world"); - gpr_log(GPR_ERROR, "%d %s!!", argument1, argument2); */ - -/** The severity of a log message - use the #defines below when calling into - gpr_log to additionally supply file and line data */ -typedef enum gpr_log_severity { - GPR_LOG_SEVERITY_DEBUG, - GPR_LOG_SEVERITY_INFO, - GPR_LOG_SEVERITY_ERROR -} gpr_log_severity; - -#define GPR_LOG_VERBOSITY_UNSET -1 - -/** Returns a string representation of the log severity */ -GPRAPI const char* gpr_log_severity_string(gpr_log_severity severity); - -/** Macros to build log contexts at various severity levels */ -#define GPR_DEBUG __FILE__, __LINE__, GPR_LOG_SEVERITY_DEBUG -#define GPR_INFO __FILE__, __LINE__, GPR_LOG_SEVERITY_INFO -#define GPR_ERROR __FILE__, __LINE__, GPR_LOG_SEVERITY_ERROR - -/** Log a message. It's advised to use GPR_xxx above to generate the context - * for each message */ -GPRAPI void gpr_log(const char* file, int line, gpr_log_severity severity, - const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); - -GPRAPI int gpr_should_log(gpr_log_severity severity); - -GPRAPI void gpr_log_message(const char* file, int line, - gpr_log_severity severity, const char* message); - -/** Set global log verbosity */ -GPRAPI void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print); - -GPRAPI void gpr_log_verbosity_init(void); - -/** Log overrides: applications can use this API to intercept logging calls - and use their own implementations */ - -struct gpr_log_func_args { - const char* file; - int line; - gpr_log_severity severity; - const char* message; -}; - -typedef struct gpr_log_func_args gpr_log_func_args; - -typedef void (*gpr_log_func)(gpr_log_func_args* args); -GPRAPI void gpr_set_log_function(gpr_log_func func); - -/** abort() the process if x is zero, having written a line to the log. - - Intended for internal invariants. If the error can be recovered from, - without the possibility of corruption, or might best be reflected via - an exception in a higher-level language, consider returning error code. */ -#define GPR_ASSERT(x) \ - do { \ - if (GPR_UNLIKELY(!(x))) { \ - gpr_log(GPR_ERROR, "assertion failed: %s", #x); \ - abort(); \ - } \ - } while (0) - -#ifndef NDEBUG -#define GPR_DEBUG_ASSERT(x) GPR_ASSERT(x) -#else -#define GPR_DEBUG_ASSERT(x) -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* GRPC_IMPL_CODEGEN_LOG_H */ +/* + * + * Copyright 2015 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_LOG_H +#define GRPC_IMPL_CODEGEN_LOG_H + +#include <grpc/impl/codegen/port_platform.h> + +#include <stdarg.h> +#include <stdlib.h> /* for abort() */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** GPR log API. + + Usage (within grpc): + + int argument1 = 3; + char* argument2 = "hello"; + gpr_log(GPR_DEBUG, "format string %d", argument1); + gpr_log(GPR_INFO, "hello world"); + gpr_log(GPR_ERROR, "%d %s!!", argument1, argument2); */ + +/** The severity of a log message - use the #defines below when calling into + gpr_log to additionally supply file and line data */ +typedef enum gpr_log_severity { + GPR_LOG_SEVERITY_DEBUG, + GPR_LOG_SEVERITY_INFO, + GPR_LOG_SEVERITY_ERROR +} gpr_log_severity; + +#define GPR_LOG_VERBOSITY_UNSET -1 + +/** Returns a string representation of the log severity */ +GPRAPI const char* gpr_log_severity_string(gpr_log_severity severity); + +/** Macros to build log contexts at various severity levels */ +#define GPR_DEBUG __FILE__, __LINE__, GPR_LOG_SEVERITY_DEBUG +#define GPR_INFO __FILE__, __LINE__, GPR_LOG_SEVERITY_INFO +#define GPR_ERROR __FILE__, __LINE__, GPR_LOG_SEVERITY_ERROR + +/** Log a message. It's advised to use GPR_xxx above to generate the context + * for each message */ +GPRAPI void gpr_log(const char* file, int line, gpr_log_severity severity, + const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); + +GPRAPI int gpr_should_log(gpr_log_severity severity); + +GPRAPI void gpr_log_message(const char* file, int line, + gpr_log_severity severity, const char* message); + +/** Set global log verbosity */ +GPRAPI void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print); + +GPRAPI void gpr_log_verbosity_init(void); + +/** Log overrides: applications can use this API to intercept logging calls + and use their own implementations */ + +struct gpr_log_func_args { + const char* file; + int line; + gpr_log_severity severity; + const char* message; +}; + +typedef struct gpr_log_func_args gpr_log_func_args; + +typedef void (*gpr_log_func)(gpr_log_func_args* args); +GPRAPI void gpr_set_log_function(gpr_log_func func); + +/** abort() the process if x is zero, having written a line to the log. + + Intended for internal invariants. If the error can be recovered from, + without the possibility of corruption, or might best be reflected via + an exception in a higher-level language, consider returning error code. */ +#define GPR_ASSERT(x) \ + do { \ + if (GPR_UNLIKELY(!(x))) { \ + gpr_log(GPR_ERROR, "assertion failed: %s", #x); \ + abort(); \ + } \ + } while (0) + +#ifndef NDEBUG +#define GPR_DEBUG_ASSERT(x) GPR_ASSERT(x) +#else +#define GPR_DEBUG_ASSERT(x) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* GRPC_IMPL_CODEGEN_LOG_H */ diff --git a/contrib/libs/grpc/include/grpc/impl/codegen/port_platform.h b/contrib/libs/grpc/include/grpc/impl/codegen/port_platform.h index 35419f017b..bf508f05fe 100644 --- a/contrib/libs/grpc/include/grpc/impl/codegen/port_platform.h +++ b/contrib/libs/grpc/include/grpc/impl/codegen/port_platform.h @@ -113,10 +113,10 @@ #elif defined(ANDROID) || defined(__ANDROID__) #define GPR_PLATFORM_STRING "android" #define GPR_ANDROID 1 -// TODO(apolcyn): re-evaluate support for c-ares -// on android after upgrading our c-ares dependency. -// See https://github.com/grpc/grpc/issues/18038. -#define GRPC_ARES 0 +// TODO(apolcyn): re-evaluate support for c-ares +// on android after upgrading our c-ares dependency. +// See https://github.com/grpc/grpc/issues/18038. +#define GRPC_ARES 0 #ifdef _LP64 #define GPR_ARCH_64 1 #else /* _LP64 */ @@ -169,7 +169,7 @@ #ifdef __GLIBC__ #define GPR_POSIX_CRASH_HANDLER 1 #define GPR_LINUX_PTHREAD_NAME 1 -#include <linux/version.h> +#include <linux/version.h> #else /* musl libc */ #define GPR_MUSL_LIBC_COMPAT 1 #endif @@ -205,7 +205,7 @@ #define GPR_PTHREAD_TLS 1 #define GRPC_CFSTREAM 1 /* the c-ares resolver isn't safe to enable on iOS */ -#define GRPC_ARES 0 +#define GRPC_ARES 0 #else /* TARGET_OS_IPHONE */ #define GPR_PLATFORM_STRING "osx" #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED @@ -247,9 +247,9 @@ #define GPR_POSIX_TIME 1 #define GPR_HAS_PTHREAD_H 1 #define GPR_GETPID_IN_UNISTD_H 1 -#ifndef GRPC_CFSTREAM +#ifndef GRPC_CFSTREAM #define GPR_SUPPORT_CHANNELS_FROM_FD 1 -#endif +#endif #ifdef _LP64 #define GPR_ARCH_64 1 #else /* _LP64 */ @@ -303,49 +303,49 @@ #else /* _LP64 */ #define GPR_ARCH_32 1 #endif /* _LP64 */ -#elif defined(__sun) && defined(__SVR4) -#define GPR_PLATFORM_STRING "solaris" -#define GPR_SOLARIS 1 -#define GPR_CPU_POSIX 1 -#define GPR_GCC_ATOMIC 1 -#define GPR_GCC_TLS 1 -#define GPR_POSIX_LOG 1 -#define GPR_POSIX_ENV 1 -#define GPR_POSIX_TMPFILE 1 -#define GPR_POSIX_STRING 1 -#define GPR_POSIX_SUBPROCESS 1 -#define GPR_POSIX_SYNC 1 -#define GPR_POSIX_TIME 1 +#elif defined(__sun) && defined(__SVR4) +#define GPR_PLATFORM_STRING "solaris" +#define GPR_SOLARIS 1 +#define GPR_CPU_POSIX 1 +#define GPR_GCC_ATOMIC 1 +#define GPR_GCC_TLS 1 +#define GPR_POSIX_LOG 1 +#define GPR_POSIX_ENV 1 +#define GPR_POSIX_TMPFILE 1 +#define GPR_POSIX_STRING 1 +#define GPR_POSIX_SUBPROCESS 1 +#define GPR_POSIX_SYNC 1 +#define GPR_POSIX_TIME 1 #define GPR_HAS_PTHREAD_H 1 -#define GPR_GETPID_IN_UNISTD_H 1 -#ifdef _LP64 -#define GPR_ARCH_64 1 -#else /* _LP64 */ -#define GPR_ARCH_32 1 -#endif /* _LP64 */ -#elif defined(_AIX) -#define GPR_PLATFORM_STRING "aix" -#ifndef _ALL_SOURCE -#define _ALL_SOURCE -#endif -#define GPR_AIX 1 -#define GPR_CPU_POSIX 1 -#define GPR_GCC_ATOMIC 1 -#define GPR_GCC_TLS 1 -#define GPR_POSIX_LOG 1 -#define GPR_POSIX_ENV 1 -#define GPR_POSIX_TMPFILE 1 -#define GPR_POSIX_STRING 1 -#define GPR_POSIX_SUBPROCESS 1 -#define GPR_POSIX_SYNC 1 -#define GPR_POSIX_TIME 1 +#define GPR_GETPID_IN_UNISTD_H 1 +#ifdef _LP64 +#define GPR_ARCH_64 1 +#else /* _LP64 */ +#define GPR_ARCH_32 1 +#endif /* _LP64 */ +#elif defined(_AIX) +#define GPR_PLATFORM_STRING "aix" +#ifndef _ALL_SOURCE +#define _ALL_SOURCE +#endif +#define GPR_AIX 1 +#define GPR_CPU_POSIX 1 +#define GPR_GCC_ATOMIC 1 +#define GPR_GCC_TLS 1 +#define GPR_POSIX_LOG 1 +#define GPR_POSIX_ENV 1 +#define GPR_POSIX_TMPFILE 1 +#define GPR_POSIX_STRING 1 +#define GPR_POSIX_SUBPROCESS 1 +#define GPR_POSIX_SYNC 1 +#define GPR_POSIX_TIME 1 #define GPR_HAS_PTHREAD_H 1 -#define GPR_GETPID_IN_UNISTD_H 1 -#ifdef _LP64 -#define GPR_ARCH_64 1 -#else /* _LP64 */ -#define GPR_ARCH_32 1 -#endif /* _LP64 */ +#define GPR_GETPID_IN_UNISTD_H 1 +#ifdef _LP64 +#define GPR_ARCH_64 1 +#else /* _LP64 */ +#define GPR_ARCH_32 1 +#endif /* _LP64 */ #elif defined(__native_client__) #define GPR_PLATFORM_STRING "nacl" #ifndef _BSD_SOURCE @@ -537,9 +537,9 @@ typedef unsigned __int64 uint64_t; #ifndef GRPC_ARES #define GRPC_ARES 1 #endif - -#ifndef GRPC_IF_NAMETOINDEX -#define GRPC_IF_NAMETOINDEX 1 + +#ifndef GRPC_IF_NAMETOINDEX +#define GRPC_IF_NAMETOINDEX 1 #endif #ifndef GRPC_MUST_USE_RESULT @@ -592,14 +592,14 @@ typedef unsigned __int64 uint64_t; #define CENSUSAPI GRPCAPI #endif -#ifndef GPR_HAS_ATTRIBUTE -#ifdef __has_attribute -#define GPR_HAS_ATTRIBUTE(a) __has_attribute(a) -#else -#define GPR_HAS_ATTRIBUTE(a) 0 -#endif -#endif /* GPR_HAS_ATTRIBUTE */ - +#ifndef GPR_HAS_ATTRIBUTE +#ifdef __has_attribute +#define GPR_HAS_ATTRIBUTE(a) __has_attribute(a) +#else +#define GPR_HAS_ATTRIBUTE(a) 0 +#endif +#endif /* GPR_HAS_ATTRIBUTE */ + #ifndef GPR_HAS_FEATURE #ifdef __has_feature #define GPR_HAS_FEATURE(a) __has_feature(a) @@ -608,27 +608,27 @@ typedef unsigned __int64 uint64_t; #endif #endif /* GPR_HAS_FEATURE */ -#ifndef GPR_ATTRIBUTE_NOINLINE -#if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__)) -#define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline)) -#define GPR_HAS_ATTRIBUTE_NOINLINE 1 -#else -#define GPR_ATTRIBUTE_NOINLINE -#endif -#endif /* GPR_ATTRIBUTE_NOINLINE */ - -#ifndef GPR_ATTRIBUTE_WEAK -/* Attribute weak is broken on LLVM/windows: - * https://bugs.llvm.org/show_bug.cgi?id=37598 */ -#if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \ - !(defined(__llvm__) && defined(_WIN32)) -#define GPR_ATTRIBUTE_WEAK __attribute__((weak)) -#define GPR_HAS_ATTRIBUTE_WEAK 1 -#else -#define GPR_ATTRIBUTE_WEAK -#endif -#endif /* GPR_ATTRIBUTE_WEAK */ - +#ifndef GPR_ATTRIBUTE_NOINLINE +#if GPR_HAS_ATTRIBUTE(noinline) || (defined(__GNUC__) && !defined(__clang__)) +#define GPR_ATTRIBUTE_NOINLINE __attribute__((noinline)) +#define GPR_HAS_ATTRIBUTE_NOINLINE 1 +#else +#define GPR_ATTRIBUTE_NOINLINE +#endif +#endif /* GPR_ATTRIBUTE_NOINLINE */ + +#ifndef GPR_ATTRIBUTE_WEAK +/* Attribute weak is broken on LLVM/windows: + * https://bugs.llvm.org/show_bug.cgi?id=37598 */ +#if (GPR_HAS_ATTRIBUTE(weak) || (defined(__GNUC__) && !defined(__clang__))) && \ + !(defined(__llvm__) && defined(_WIN32)) +#define GPR_ATTRIBUTE_WEAK __attribute__((weak)) +#define GPR_HAS_ATTRIBUTE_WEAK 1 +#else +#define GPR_ATTRIBUTE_WEAK +#endif +#endif /* GPR_ATTRIBUTE_WEAK */ + #ifndef GPR_ATTRIBUTE_NO_TSAN /* (1) */ #if GPR_HAS_FEATURE(thread_sanitizer) #define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread"))) @@ -638,13 +638,13 @@ typedef unsigned __int64 uint64_t; #endif /* GPR_ATTRIBUTE_NO_TSAN (2) */ #endif /* GPR_ATTRIBUTE_NO_TSAN (1) */ -/* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */ +/* GRPC_TSAN_ENABLED will be defined, when compiled with thread sanitizer. */ #ifndef GRPC_TSAN_SUPPRESSED -#if defined(__SANITIZE_THREAD__) -#define GRPC_TSAN_ENABLED +#if defined(__SANITIZE_THREAD__) +#define GRPC_TSAN_ENABLED #elif GPR_HAS_FEATURE(thread_sanitizer) -#define GRPC_TSAN_ENABLED -#endif +#define GRPC_TSAN_ENABLED +#endif #endif /* GRPC_ASAN_ENABLED will be defined, when compiled with address sanitizer. */ @@ -653,9 +653,9 @@ typedef unsigned __int64 uint64_t; #define GRPC_ASAN_ENABLED #elif GPR_HAS_FEATURE(address_sanitizer) #define GRPC_ASAN_ENABLED +#endif #endif -#endif - + /* GRPC_ALLOW_EXCEPTIONS should be 0 or 1 if exceptions are allowed or not */ #ifndef GRPC_ALLOW_EXCEPTIONS #ifdef GPR_WINDOWS diff --git a/contrib/libs/grpc/include/grpc/impl/codegen/slice.h b/contrib/libs/grpc/include/grpc/impl/codegen/slice.h index 3567b1e88b..1318fe2812 100644 --- a/contrib/libs/grpc/include/grpc/impl/codegen/slice.h +++ b/contrib/libs/grpc/include/grpc/impl/codegen/slice.h @@ -61,7 +61,7 @@ struct grpc_slice { struct grpc_slice_refcount* refcount; union grpc_slice_data { struct grpc_slice_refcounted { - size_t length; + size_t length; uint8_t* bytes; } refcounted; struct grpc_slice_inlined { diff --git a/contrib/libs/grpc/include/grpc/module.modulemap b/contrib/libs/grpc/include/grpc/module.modulemap index 06c1e97736..922e29a188 100644 --- a/contrib/libs/grpc/include/grpc/module.modulemap +++ b/contrib/libs/grpc/include/grpc/module.modulemap @@ -11,7 +11,7 @@ framework module grpc { header "impl/codegen/gpr_slice.h" header "impl/codegen/gpr_types.h" header "impl/codegen/grpc_types.h" - header "impl/codegen/log.h" + header "impl/codegen/log.h" header "impl/codegen/port_platform.h" header "impl/codegen/propagation_bits.h" header "impl/codegen/slice.h" diff --git a/contrib/libs/grpc/include/grpc/support/log.h b/contrib/libs/grpc/include/grpc/support/log.h index 8d8742b95d..6970c6ddef 100644 --- a/contrib/libs/grpc/include/grpc/support/log.h +++ b/contrib/libs/grpc/include/grpc/support/log.h @@ -19,8 +19,8 @@ #ifndef GRPC_SUPPORT_LOG_H #define GRPC_SUPPORT_LOG_H -#include <grpc/support/port_platform.h> +#include <grpc/support/port_platform.h> -#include <grpc/impl/codegen/log.h> +#include <grpc/impl/codegen/log.h> #endif /* GRPC_SUPPORT_LOG_H */ diff --git a/contrib/libs/grpc/include/grpc/support/string_util.h b/contrib/libs/grpc/include/grpc/support/string_util.h index 2679160c1b..59c60fc041 100644 --- a/contrib/libs/grpc/include/grpc/support/string_util.h +++ b/contrib/libs/grpc/include/grpc/support/string_util.h @@ -21,8 +21,8 @@ #include <grpc/support/port_platform.h> -#include <grpc/impl/codegen/gpr_types.h> - +#include <grpc/impl/codegen/gpr_types.h> + #ifdef __cplusplus extern "C" { #endif diff --git a/contrib/libs/grpc/include/grpcpp/channel.h b/contrib/libs/grpc/include/grpcpp/channel.h index 6a31ff7aa9..f569b4c419 100644 --- a/contrib/libs/grpc/include/grpcpp/channel.h +++ b/contrib/libs/grpc/include/grpcpp/channel.h @@ -43,13 +43,13 @@ std::shared_ptr<Channel> CreateChannelInternal( std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> interceptor_creators); -namespace experimental { -/// Resets the channel's connection backoff. -/// TODO(roth): Once we see whether this proves useful, either create a gRFC -/// and change this to be a method of the Channel class, or remove it. -void ChannelResetConnectionBackoff(Channel* channel); -} // namespace experimental - +namespace experimental { +/// Resets the channel's connection backoff. +/// TODO(roth): Once we see whether this proves useful, either create a gRFC +/// and change this to be a method of the Channel class, or remove it. +void ChannelResetConnectionBackoff(Channel* channel); +} // namespace experimental + /// Channels represent a connection to an endpoint. Created by \a CreateChannel. class Channel final : public ::grpc::ChannelInterface, public ::grpc::internal::CallHook, diff --git a/contrib/libs/grpc/include/grpcpp/create_channel.h b/contrib/libs/grpc/include/grpcpp/create_channel.h index 4b94a08e45..0c2cca87a0 100644 --- a/contrib/libs/grpc/include/grpcpp/create_channel.h +++ b/contrib/libs/grpc/include/grpcpp/create_channel.h @@ -53,7 +53,7 @@ std::shared_ptr<Channel> CreateCustomChannel( const std::shared_ptr<ChannelCredentials>& creds, const ChannelArguments& args); -namespace experimental { +namespace experimental { /// Create a new \em custom \a Channel pointing to \a target with \a /// interceptors being invoked per call. /// @@ -66,13 +66,13 @@ namespace experimental { /// fail) is returned. /// \param args Options for channel creation. std::shared_ptr<Channel> CreateCustomChannelWithInterceptors( - const grpc::string& target, - const std::shared_ptr<ChannelCredentials>& creds, - const ChannelArguments& args, - std::vector< - std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> + const grpc::string& target, + const std::shared_ptr<ChannelCredentials>& creds, + const ChannelArguments& args, + std::vector< + std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> interceptor_creators); -} // namespace experimental +} // namespace experimental } // namespace grpc #endif // GRPCPP_CREATE_CHANNEL_H diff --git a/contrib/libs/grpc/include/grpcpp/create_channel_posix.h b/contrib/libs/grpc/include/grpcpp/create_channel_posix.h index c6755b0aa6..c5840f1511 100644 --- a/contrib/libs/grpc/include/grpcpp/create_channel_posix.h +++ b/contrib/libs/grpc/include/grpcpp/create_channel_posix.h @@ -45,8 +45,8 @@ std::shared_ptr<grpc::Channel> CreateInsecureChannelFromFd( std::shared_ptr<grpc::Channel> CreateCustomInsecureChannelFromFd( const TString& target, int fd, const grpc::ChannelArguments& args); -namespace experimental { - +namespace experimental { + /// Create a new \a Channel communicating over given file descriptor with custom /// channel arguments. /// @@ -57,12 +57,12 @@ namespace experimental { std::shared_ptr<grpc::Channel> CreateCustomInsecureChannelWithInterceptorsFromFd( const TString& target, int fd, const grpc::ChannelArguments& args, - std::unique_ptr<std::vector< + std::unique_ptr<std::vector< std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>> interceptor_creators); - -} // namespace experimental - + +} // namespace experimental + #endif // GPR_SUPPORT_CHANNELS_FROM_FD } // namespace grpc diff --git a/contrib/libs/grpc/include/grpcpp/ext/channelz_service_plugin.h b/contrib/libs/grpc/include/grpcpp/ext/channelz_service_plugin.h index 95cb93e321..2485e13f35 100644 --- a/contrib/libs/grpc/include/grpcpp/ext/channelz_service_plugin.h +++ b/contrib/libs/grpc/include/grpcpp/ext/channelz_service_plugin.h @@ -1,36 +1,36 @@ -/* - * - * Copyright 2018 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 GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_H -#define GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_H - +/* + * + * Copyright 2018 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 GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_H +#define GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_H + #include <grpcpp/ext/channelz_service_plugin_impl.h> - -namespace grpc { -namespace channelz { -namespace experimental { - + +namespace grpc { +namespace channelz { +namespace experimental { + static inline void InitChannelzService() { ::grpc_impl::channelz::experimental::InitChannelzService(); } - -} // namespace experimental -} // namespace channelz -} // namespace grpc - -#endif // GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_H + +} // namespace experimental +} // namespace channelz +} // namespace grpc + +#endif // GRPCPP_EXT_CHANNELZ_SERVICE_PLUGIN_H diff --git a/contrib/libs/grpc/include/grpcpp/ext/server_load_reporting.h b/contrib/libs/grpc/include/grpcpp/ext/server_load_reporting.h index 987a48ee79..90f0a68d69 100644 --- a/contrib/libs/grpc/include/grpcpp/ext/server_load_reporting.h +++ b/contrib/libs/grpc/include/grpcpp/ext/server_load_reporting.h @@ -1,35 +1,35 @@ -/* - * - * Copyright 2018 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 GRPCPP_EXT_SERVER_LOAD_REPORTING_H -#define GRPCPP_EXT_SERVER_LOAD_REPORTING_H - +/* + * + * Copyright 2018 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 GRPCPP_EXT_SERVER_LOAD_REPORTING_H +#define GRPCPP_EXT_SERVER_LOAD_REPORTING_H + #include <grpc/support/port_platform.h> - + #include <grpc/load_reporting.h> #include <grpcpp/impl/codegen/config.h> #include <grpcpp/impl/codegen/server_context.h> #include <grpcpp/impl/server_builder_option.h> -namespace grpc { -namespace load_reporter { -namespace experimental { - +namespace grpc { +namespace load_reporter { +namespace experimental { + // The ServerBuilderOption to enable server-side load reporting feature. To // enable the feature, please make sure the binary builds with the // grpcpp_server_load_reporting library and set this option in the @@ -41,14 +41,14 @@ class LoadReportingServiceServerBuilderOption void UpdatePlugins(std::vector<std::unique_ptr<::grpc::ServerBuilderPlugin>>* plugins) override; }; - + // Adds the load reporting cost with \a cost_name and \a cost_value in the // trailing metadata of the server context. void AddLoadReportingCost(grpc::ServerContext* ctx, const TString& cost_name, double cost_value); - -} // namespace experimental -} // namespace load_reporter -} // namespace grpc - -#endif // GRPCPP_EXT_SERVER_LOAD_REPORTING_H + +} // namespace experimental +} // namespace load_reporter +} // namespace grpc + +#endif // GRPCPP_EXT_SERVER_LOAD_REPORTING_H diff --git a/contrib/libs/grpc/include/grpcpp/generic/async_generic_service.h b/contrib/libs/grpc/include/grpcpp/generic/async_generic_service.h index 2c67edc517..8607c0f5c9 100644 --- a/contrib/libs/grpc/include/grpcpp/generic/async_generic_service.h +++ b/contrib/libs/grpc/include/grpcpp/generic/async_generic_service.h @@ -1,6 +1,6 @@ /* * - * Copyright 2018 gRPC authors. + * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,6 @@ #ifndef GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H #define GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H -#include <grpcpp/impl/codegen/async_generic_service.h> +#include <grpcpp/impl/codegen/async_generic_service.h> #endif // GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H diff --git a/contrib/libs/grpc/include/grpcpp/generic/generic_stub.h b/contrib/libs/grpc/include/grpcpp/generic/generic_stub.h index 102d2591c9..0412867636 100644 --- a/contrib/libs/grpc/include/grpcpp/generic/generic_stub.h +++ b/contrib/libs/grpc/include/grpcpp/generic/generic_stub.h @@ -20,7 +20,7 @@ #define GRPCPP_GENERIC_GENERIC_STUB_H #include <functional> - + #include <grpcpp/client_context.h> #include <grpcpp/impl/rpc_method.h> #include <grpcpp/support/async_stream.h> diff --git a/contrib/libs/grpc/include/grpcpp/health_check_service_interface.h b/contrib/libs/grpc/include/grpcpp/health_check_service_interface.h index de055a82ea..925cce16df 100644 --- a/contrib/libs/grpc/include/grpcpp/health_check_service_interface.h +++ b/contrib/libs/grpc/include/grpcpp/health_check_service_interface.h @@ -37,7 +37,7 @@ class HealthCheckServiceInterface { bool serving) = 0; /// Apply to all registered service names. virtual void SetServingStatus(bool serving) = 0; - + /// Set all registered service names to not serving and prevent future /// state changes. virtual void Shutdown() {} diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/async_generic_service.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/async_generic_service.h index a812b086a2..cb82f446da 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/async_generic_service.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/async_generic_service.h @@ -1,84 +1,84 @@ -/* - * - * Copyright 2015 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 GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H -#define GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H - +/* + * + * Copyright 2015 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 GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H +#define GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H + #include <grpc/impl/codegen/port_platform.h> #include <grpcpp/impl/codegen/async_stream.h> -#include <grpcpp/impl/codegen/byte_buffer.h> +#include <grpcpp/impl/codegen/byte_buffer.h> #include <grpcpp/impl/codegen/server_callback.h> #include <grpcpp/impl/codegen/server_callback_handlers.h> - -struct grpc_server; - -namespace grpc { - + +struct grpc_server; + +namespace grpc { + typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer> - GenericServerAsyncReaderWriter; + GenericServerAsyncReaderWriter; typedef ServerAsyncResponseWriter<ByteBuffer> GenericServerAsyncResponseWriter; typedef ServerAsyncReader<ByteBuffer, ByteBuffer> GenericServerAsyncReader; typedef ServerAsyncWriter<ByteBuffer> GenericServerAsyncWriter; - + class GenericServerContext final : public ServerContext { - public: + public: const TString& method() const { return method_; } const TString& host() const { return host_; } - - private: + + private: friend class ServerInterface; - + TString method_; TString host_; -}; - -// A generic service at the server side accepts all RPC methods and hosts. It is -// typically used in proxies. The generic service can be registered to a server -// which also has other services. -// Sample usage: -// ServerBuilder builder; -// auto cq = builder.AddCompletionQueue(); -// AsyncGenericService generic_service; -// builder.RegisterAsyncGenericService(&generic_service); -// auto server = builder.BuildAndStart(); -// -// // request a new call -// GenericServerContext context; -// GenericServerAsyncReaderWriter stream; -// generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag); -// -// When tag is retrieved from cq->Next(), context.method() can be used to look -// at the method and the RPC can be handled accordingly. -class AsyncGenericService final { - public: - AsyncGenericService() : server_(nullptr) {} - - void RequestCall(GenericServerContext* ctx, - GenericServerAsyncReaderWriter* reader_writer, +}; + +// A generic service at the server side accepts all RPC methods and hosts. It is +// typically used in proxies. The generic service can be registered to a server +// which also has other services. +// Sample usage: +// ServerBuilder builder; +// auto cq = builder.AddCompletionQueue(); +// AsyncGenericService generic_service; +// builder.RegisterAsyncGenericService(&generic_service); +// auto server = builder.BuildAndStart(); +// +// // request a new call +// GenericServerContext context; +// GenericServerAsyncReaderWriter stream; +// generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag); +// +// When tag is retrieved from cq->Next(), context.method() can be used to look +// at the method and the RPC can be handled accordingly. +class AsyncGenericService final { + public: + AsyncGenericService() : server_(nullptr) {} + + void RequestCall(GenericServerContext* ctx, + GenericServerAsyncReaderWriter* reader_writer, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag); - - private: + + private: friend class grpc::Server; grpc::Server* server_; -}; - +}; + #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL namespace experimental { #endif @@ -137,6 +137,6 @@ class CallbackGenericService { #ifndef GRPC_CALLBACK_API_NONEXPERIMENTAL } // namespace experimental #endif -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h index 6e64ec9981..5b157cb43e 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/byte_buffer.h @@ -54,7 +54,7 @@ class ExternalConnectionAcceptorImpl; template <class R> class DeserializeFuncType; class GrpcByteBufferPeer; - + } // namespace internal /// A sequence of bytes. class ByteBuffer final { @@ -89,9 +89,9 @@ class ByteBuffer final { } /// Constuct a byte buffer by referencing elements of existing buffer - /// \a buf. Wrapper of core function grpc_byte_buffer_copy . This is not - /// a deep copy; it is just a referencing. As a result, its performance is - /// size-independent. + /// \a buf. Wrapper of core function grpc_byte_buffer_copy . This is not + /// a deep copy; it is just a referencing. As a result, its performance is + /// size-independent. ByteBuffer(const ByteBuffer& buf) : buffer_(nullptr) { operator=(buf); } ~ByteBuffer() { @@ -100,9 +100,9 @@ class ByteBuffer final { } } - /// Wrapper of core function grpc_byte_buffer_copy . This is not - /// a deep copy; it is just a referencing. As a result, its performance is - /// size-independent. + /// Wrapper of core function grpc_byte_buffer_copy . This is not + /// a deep copy; it is just a referencing. As a result, its performance is + /// size-independent. ByteBuffer& operator=(const ByteBuffer& buf) { if (this != &buf) { Clear(); // first remove existing data @@ -127,9 +127,9 @@ class ByteBuffer final { /// Make a duplicate copy of the internals of this byte /// buffer so that we have our own owned version of it. - /// bbuf.Duplicate(); is equivalent to bbuf=bbuf; but is actually readable. - /// This is not a deep copy; it is a referencing and its performance - /// is size-independent. + /// bbuf.Duplicate(); is equivalent to bbuf=bbuf; but is actually readable. + /// This is not a deep copy; it is a referencing and its performance + /// is size-independent. void Duplicate() { buffer_ = g_core_codegen_interface->grpc_byte_buffer_copy(buffer_); } @@ -164,13 +164,13 @@ class ByteBuffer final { friend class internal::CallOpGenericRecvMessage; template <class ServiceType, class RequestType, class ResponseType> friend class internal::RpcMethodHandler; - template <class ServiceType, class RequestType, class ResponseType> + template <class ServiceType, class RequestType, class ResponseType> friend class internal::ServerStreamingHandler; - template <class RequestType, class ResponseType> + template <class RequestType, class ResponseType> friend class internal::CallbackUnaryHandler; - template <class RequestType, class ResponseType> + template <class RequestType, class ResponseType> friend class internal::CallbackServerStreamingHandler; - template <StatusCode code> + template <StatusCode code> friend class internal::ErrorMethodHandler; template <class R> friend class internal::DeserializeFuncType; diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h index b229286215..eda6697777 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/call.h @@ -1,6 +1,6 @@ /* * - * Copyright 2018 gRPC authors. + * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,27 +18,27 @@ #ifndef GRPCPP_IMPL_CODEGEN_CALL_H #define GRPCPP_IMPL_CODEGEN_CALL_H -#include <grpc/impl/codegen/grpc_types.h> +#include <grpc/impl/codegen/grpc_types.h> #include <grpcpp/impl/codegen/call_hook.h> namespace grpc { class CompletionQueue; -namespace experimental { -class ClientRpcInfo; -class ServerRpcInfo; -} // namespace experimental +namespace experimental { +class ClientRpcInfo; +class ServerRpcInfo; +} // namespace experimental namespace internal { class CallHook; -class CallOpSetInterface; +class CallOpSetInterface; /// Straightforward wrapping of the C call object class Call final { public: - Call() - : call_hook_(nullptr), - cq_(nullptr), - call_(nullptr), - max_receive_message_size_(-1) {} + Call() + : call_hook_(nullptr), + cq_(nullptr), + call_(nullptr), + max_receive_message_size_(-1) {} /** call is owned by the caller */ Call(grpc_call* call, CallHook* call_hook, ::grpc::CompletionQueue* cq) : call_hook_(call_hook), @@ -47,21 +47,21 @@ class Call final { max_receive_message_size_(-1) {} Call(grpc_call* call, CallHook* call_hook, ::grpc::CompletionQueue* cq, - experimental::ClientRpcInfo* rpc_info) + experimental::ClientRpcInfo* rpc_info) : call_hook_(call_hook), cq_(cq), call_(call), - max_receive_message_size_(-1), - client_rpc_info_(rpc_info) {} + max_receive_message_size_(-1), + client_rpc_info_(rpc_info) {} Call(grpc_call* call, CallHook* call_hook, ::grpc::CompletionQueue* cq, - int max_receive_message_size, experimental::ServerRpcInfo* rpc_info) - : call_hook_(call_hook), - cq_(cq), - call_(call), - max_receive_message_size_(max_receive_message_size), - server_rpc_info_(rpc_info) {} - + int max_receive_message_size, experimental::ServerRpcInfo* rpc_info) + : call_hook_(call_hook), + cq_(cq), + call_(call), + max_receive_message_size_(max_receive_message_size), + server_rpc_info_(rpc_info) {} + void PerformOps(CallOpSetInterface* ops) { call_hook_->PerformOpsOnCall(ops, this); } @@ -71,21 +71,21 @@ class Call final { int max_receive_message_size() const { return max_receive_message_size_; } - experimental::ClientRpcInfo* client_rpc_info() const { - return client_rpc_info_; - } - - experimental::ServerRpcInfo* server_rpc_info() const { - return server_rpc_info_; - } - + experimental::ClientRpcInfo* client_rpc_info() const { + return client_rpc_info_; + } + + experimental::ServerRpcInfo* server_rpc_info() const { + return server_rpc_info_; + } + private: CallHook* call_hook_; ::grpc::CompletionQueue* cq_; grpc_call* call_; int max_receive_message_size_; - experimental::ClientRpcInfo* client_rpc_info_ = nullptr; - experimental::ServerRpcInfo* server_rpc_info_ = nullptr; + experimental::ClientRpcInfo* client_rpc_info_ = nullptr; + experimental::ServerRpcInfo* server_rpc_info_ = nullptr; }; } // namespace internal } // namespace grpc diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set.h index 379333164a..21baa3ad19 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set.h @@ -1,460 +1,460 @@ -/* - * - * Copyright 2018 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. - * - */ - -#if defined(__GNUC__) -#pragma GCC system_header -#endif - -#ifndef GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H -#define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H - -#include <cstring> -#include <map> -#include <memory> - +/* + * + * Copyright 2018 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. + * + */ + +#if defined(__GNUC__) +#pragma GCC system_header +#endif + +#ifndef GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H +#define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H + +#include <cstring> +#include <map> +#include <memory> + #include <grpc/impl/codegen/compression_types.h> #include <grpc/impl/codegen/grpc_types.h> -#include <grpcpp/impl/codegen/byte_buffer.h> -#include <grpcpp/impl/codegen/call.h> -#include <grpcpp/impl/codegen/call_hook.h> -#include <grpcpp/impl/codegen/call_op_set_interface.h> +#include <grpcpp/impl/codegen/byte_buffer.h> +#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/call_hook.h> +#include <grpcpp/impl/codegen/call_op_set_interface.h> #include <grpcpp/impl/codegen/client_context.h> #include <grpcpp/impl/codegen/completion_queue.h> -#include <grpcpp/impl/codegen/completion_queue_tag.h> -#include <grpcpp/impl/codegen/config.h> -#include <grpcpp/impl/codegen/core_codegen_interface.h> -#include <grpcpp/impl/codegen/intercepted_channel.h> -#include <grpcpp/impl/codegen/interceptor_common.h> -#include <grpcpp/impl/codegen/serialization_traits.h> -#include <grpcpp/impl/codegen/slice.h> -#include <grpcpp/impl/codegen/string_ref.h> - -namespace grpc { - -extern CoreCodegenInterface* g_core_codegen_interface; - -namespace internal { -class Call; -class CallHook; - -// TODO(yangg) if the map is changed before we send, the pointers will be a -// mess. Make sure it does not happen. -inline grpc_metadata* FillMetadataArray( +#include <grpcpp/impl/codegen/completion_queue_tag.h> +#include <grpcpp/impl/codegen/config.h> +#include <grpcpp/impl/codegen/core_codegen_interface.h> +#include <grpcpp/impl/codegen/intercepted_channel.h> +#include <grpcpp/impl/codegen/interceptor_common.h> +#include <grpcpp/impl/codegen/serialization_traits.h> +#include <grpcpp/impl/codegen/slice.h> +#include <grpcpp/impl/codegen/string_ref.h> + +namespace grpc { + +extern CoreCodegenInterface* g_core_codegen_interface; + +namespace internal { +class Call; +class CallHook; + +// TODO(yangg) if the map is changed before we send, the pointers will be a +// mess. Make sure it does not happen. +inline grpc_metadata* FillMetadataArray( const std::multimap<TString, TString>& metadata, size_t* metadata_count, const TString& optional_error_details) { - *metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1); - if (*metadata_count == 0) { - return nullptr; - } - grpc_metadata* metadata_array = - (grpc_metadata*)(g_core_codegen_interface->gpr_malloc( - (*metadata_count) * sizeof(grpc_metadata))); - size_t i = 0; - for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { - metadata_array[i].key = SliceReferencingString(iter->first); - metadata_array[i].value = SliceReferencingString(iter->second); - } - if (!optional_error_details.empty()) { - metadata_array[i].key = - g_core_codegen_interface->grpc_slice_from_static_buffer( - kBinaryErrorDetailsKey, sizeof(kBinaryErrorDetailsKey) - 1); - metadata_array[i].value = SliceReferencingString(optional_error_details); - } - return metadata_array; -} -} // namespace internal - -/// Per-message write options. -class WriteOptions { - public: - WriteOptions() : flags_(0), last_message_(false) {} - WriteOptions(const WriteOptions& other) - : flags_(other.flags_), last_message_(other.last_message_) {} - + *metadata_count = metadata.size() + (optional_error_details.empty() ? 0 : 1); + if (*metadata_count == 0) { + return nullptr; + } + grpc_metadata* metadata_array = + (grpc_metadata*)(g_core_codegen_interface->gpr_malloc( + (*metadata_count) * sizeof(grpc_metadata))); + size_t i = 0; + for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { + metadata_array[i].key = SliceReferencingString(iter->first); + metadata_array[i].value = SliceReferencingString(iter->second); + } + if (!optional_error_details.empty()) { + metadata_array[i].key = + g_core_codegen_interface->grpc_slice_from_static_buffer( + kBinaryErrorDetailsKey, sizeof(kBinaryErrorDetailsKey) - 1); + metadata_array[i].value = SliceReferencingString(optional_error_details); + } + return metadata_array; +} +} // namespace internal + +/// Per-message write options. +class WriteOptions { + public: + WriteOptions() : flags_(0), last_message_(false) {} + WriteOptions(const WriteOptions& other) + : flags_(other.flags_), last_message_(other.last_message_) {} + /// Default assignment operator WriteOptions& operator=(const WriteOptions& other) = default; - /// Clear all flags. - inline void Clear() { flags_ = 0; } - - /// Returns raw flags bitset. - inline uint32_t flags() const { return flags_; } - - /// Sets flag for the disabling of compression for the next message write. - /// - /// \sa GRPC_WRITE_NO_COMPRESS - inline WriteOptions& set_no_compression() { - SetBit(GRPC_WRITE_NO_COMPRESS); - return *this; - } - - /// Clears flag for the disabling of compression for the next message write. - /// - /// \sa GRPC_WRITE_NO_COMPRESS - inline WriteOptions& clear_no_compression() { - ClearBit(GRPC_WRITE_NO_COMPRESS); - return *this; - } - - /// Get value for the flag indicating whether compression for the next - /// message write is forcefully disabled. - /// - /// \sa GRPC_WRITE_NO_COMPRESS - inline bool get_no_compression() const { - return GetBit(GRPC_WRITE_NO_COMPRESS); - } - - /// Sets flag indicating that the write may be buffered and need not go out on - /// the wire immediately. - /// - /// \sa GRPC_WRITE_BUFFER_HINT - inline WriteOptions& set_buffer_hint() { - SetBit(GRPC_WRITE_BUFFER_HINT); - return *this; - } - - /// Clears flag indicating that the write may be buffered and need not go out - /// on the wire immediately. - /// - /// \sa GRPC_WRITE_BUFFER_HINT - inline WriteOptions& clear_buffer_hint() { - ClearBit(GRPC_WRITE_BUFFER_HINT); - return *this; - } - - /// Get value for the flag indicating that the write may be buffered and need - /// not go out on the wire immediately. - /// - /// \sa GRPC_WRITE_BUFFER_HINT - inline bool get_buffer_hint() const { return GetBit(GRPC_WRITE_BUFFER_HINT); } - - /// corked bit: aliases set_buffer_hint currently, with the intent that - /// set_buffer_hint will be removed in the future - inline WriteOptions& set_corked() { - SetBit(GRPC_WRITE_BUFFER_HINT); - return *this; - } - - inline WriteOptions& clear_corked() { - ClearBit(GRPC_WRITE_BUFFER_HINT); - return *this; - } - - inline bool is_corked() const { return GetBit(GRPC_WRITE_BUFFER_HINT); } - - /// last-message bit: indicates this is the last message in a stream - /// client-side: makes Write the equivalent of performing Write, WritesDone - /// in a single step - /// server-side: hold the Write until the service handler returns (sync api) - /// or until Finish is called (async api) - inline WriteOptions& set_last_message() { - last_message_ = true; - return *this; - } - - /// Clears flag indicating that this is the last message in a stream, - /// disabling coalescing. - inline WriteOptions& clear_last_message() { - last_message_ = false; - return *this; - } - - /// Guarantee that all bytes have been written to the socket before completing - /// this write (usually writes are completed when they pass flow control). - inline WriteOptions& set_write_through() { - SetBit(GRPC_WRITE_THROUGH); - return *this; - } - - inline bool is_write_through() const { return GetBit(GRPC_WRITE_THROUGH); } - - /// Get value for the flag indicating that this is the last message, and - /// should be coalesced with trailing metadata. - /// - /// \sa GRPC_WRITE_LAST_MESSAGE - bool is_last_message() const { return last_message_; } - - private: - void SetBit(const uint32_t mask) { flags_ |= mask; } - - void ClearBit(const uint32_t mask) { flags_ &= ~mask; } - - bool GetBit(const uint32_t mask) const { return (flags_ & mask) != 0; } - - uint32_t flags_; - bool last_message_; -}; - -namespace internal { - + /// Clear all flags. + inline void Clear() { flags_ = 0; } + + /// Returns raw flags bitset. + inline uint32_t flags() const { return flags_; } + + /// Sets flag for the disabling of compression for the next message write. + /// + /// \sa GRPC_WRITE_NO_COMPRESS + inline WriteOptions& set_no_compression() { + SetBit(GRPC_WRITE_NO_COMPRESS); + return *this; + } + + /// Clears flag for the disabling of compression for the next message write. + /// + /// \sa GRPC_WRITE_NO_COMPRESS + inline WriteOptions& clear_no_compression() { + ClearBit(GRPC_WRITE_NO_COMPRESS); + return *this; + } + + /// Get value for the flag indicating whether compression for the next + /// message write is forcefully disabled. + /// + /// \sa GRPC_WRITE_NO_COMPRESS + inline bool get_no_compression() const { + return GetBit(GRPC_WRITE_NO_COMPRESS); + } + + /// Sets flag indicating that the write may be buffered and need not go out on + /// the wire immediately. + /// + /// \sa GRPC_WRITE_BUFFER_HINT + inline WriteOptions& set_buffer_hint() { + SetBit(GRPC_WRITE_BUFFER_HINT); + return *this; + } + + /// Clears flag indicating that the write may be buffered and need not go out + /// on the wire immediately. + /// + /// \sa GRPC_WRITE_BUFFER_HINT + inline WriteOptions& clear_buffer_hint() { + ClearBit(GRPC_WRITE_BUFFER_HINT); + return *this; + } + + /// Get value for the flag indicating that the write may be buffered and need + /// not go out on the wire immediately. + /// + /// \sa GRPC_WRITE_BUFFER_HINT + inline bool get_buffer_hint() const { return GetBit(GRPC_WRITE_BUFFER_HINT); } + + /// corked bit: aliases set_buffer_hint currently, with the intent that + /// set_buffer_hint will be removed in the future + inline WriteOptions& set_corked() { + SetBit(GRPC_WRITE_BUFFER_HINT); + return *this; + } + + inline WriteOptions& clear_corked() { + ClearBit(GRPC_WRITE_BUFFER_HINT); + return *this; + } + + inline bool is_corked() const { return GetBit(GRPC_WRITE_BUFFER_HINT); } + + /// last-message bit: indicates this is the last message in a stream + /// client-side: makes Write the equivalent of performing Write, WritesDone + /// in a single step + /// server-side: hold the Write until the service handler returns (sync api) + /// or until Finish is called (async api) + inline WriteOptions& set_last_message() { + last_message_ = true; + return *this; + } + + /// Clears flag indicating that this is the last message in a stream, + /// disabling coalescing. + inline WriteOptions& clear_last_message() { + last_message_ = false; + return *this; + } + + /// Guarantee that all bytes have been written to the socket before completing + /// this write (usually writes are completed when they pass flow control). + inline WriteOptions& set_write_through() { + SetBit(GRPC_WRITE_THROUGH); + return *this; + } + + inline bool is_write_through() const { return GetBit(GRPC_WRITE_THROUGH); } + + /// Get value for the flag indicating that this is the last message, and + /// should be coalesced with trailing metadata. + /// + /// \sa GRPC_WRITE_LAST_MESSAGE + bool is_last_message() const { return last_message_; } + + private: + void SetBit(const uint32_t mask) { flags_ |= mask; } + + void ClearBit(const uint32_t mask) { flags_ &= ~mask; } + + bool GetBit(const uint32_t mask) const { return (flags_ & mask) != 0; } + + uint32_t flags_; + bool last_message_; +}; + +namespace internal { + /// Default argument for CallOpSet. The Unused parameter is unused by /// the class, but can be used for generating multiple names for the /// same thing. template <int Unused> -class CallNoOp { - protected: +class CallNoOp { + protected: void AddOp(grpc_op* /*ops*/, size_t* /*nops*/) {} void FinishOp(bool* /*status*/) {} - void SetInterceptionHookPoint( + void SetInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} - void SetFinishInterceptionHookPoint( + void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { } -}; - -class CallOpSendInitialMetadata { - public: - CallOpSendInitialMetadata() : send_(false) { - maybe_compression_level_.is_set = false; - } - +}; + +class CallOpSendInitialMetadata { + public: + CallOpSendInitialMetadata() : send_(false) { + maybe_compression_level_.is_set = false; + } + void SendInitialMetadata(std::multimap<TString, TString>* metadata, - uint32_t flags) { - maybe_compression_level_.is_set = false; - send_ = true; - flags_ = flags; - metadata_map_ = metadata; - } - - void set_compression_level(grpc_compression_level level) { - maybe_compression_level_.is_set = true; - maybe_compression_level_.level = level; - } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (!send_ || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_SEND_INITIAL_METADATA; - op->flags = flags_; - op->reserved = NULL; - initial_metadata_ = - FillMetadataArray(*metadata_map_, &initial_metadata_count_, ""); - 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; - if (maybe_compression_level_.is_set) { - op->data.send_initial_metadata.maybe_compression_level.level = - maybe_compression_level_.level; - } - } + uint32_t flags) { + maybe_compression_level_.is_set = false; + send_ = true; + flags_ = flags; + metadata_map_ = metadata; + } + + void set_compression_level(grpc_compression_level level) { + maybe_compression_level_.is_set = true; + maybe_compression_level_.level = level; + } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (!send_ || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->flags = flags_; + op->reserved = NULL; + initial_metadata_ = + FillMetadataArray(*metadata_map_, &initial_metadata_count_, ""); + 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; + if (maybe_compression_level_.is_set) { + op->data.send_initial_metadata.maybe_compression_level.level = + maybe_compression_level_.level; + } + } void FinishOp(bool* /*status*/) { - if (!send_ || hijacked_) return; - g_core_codegen_interface->gpr_free(initial_metadata_); - send_ = false; - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!send_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA); - interceptor_methods->SetSendInitialMetadata(metadata_map_); - } - - void SetFinishInterceptionHookPoint( + if (!send_ || hijacked_) return; + g_core_codegen_interface->gpr_free(initial_metadata_); + send_ = false; + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!send_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_SEND_INITIAL_METADATA); + interceptor_methods->SetSendInitialMetadata(metadata_map_); + } + + void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} - + void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { - hijacked_ = true; - } - - bool hijacked_ = false; - bool send_; - uint32_t flags_; - size_t initial_metadata_count_; + hijacked_ = true; + } + + bool hijacked_ = false; + bool send_; + uint32_t flags_; + size_t initial_metadata_count_; std::multimap<TString, TString>* metadata_map_; - grpc_metadata* initial_metadata_; - struct { - bool is_set; - grpc_compression_level level; - } maybe_compression_level_; -}; - -class CallOpSendMessage { - public: - CallOpSendMessage() : send_buf_() {} - - /// Send \a message using \a options for the write. The \a options are cleared - /// after use. - template <class M> - Status SendMessage(const M& message, - WriteOptions options) GRPC_MUST_USE_RESULT; - - template <class M> - Status SendMessage(const M& message) GRPC_MUST_USE_RESULT; - - /// Send \a message using \a options for the write. The \a options are cleared - /// after use. This form of SendMessage allows gRPC to reference \a message - /// beyond the lifetime of SendMessage. - template <class M> - Status SendMessagePtr(const M* message, - WriteOptions options) GRPC_MUST_USE_RESULT; - - /// This form of SendMessage allows gRPC to reference \a message beyond the - /// lifetime of SendMessage. - template <class M> - Status SendMessagePtr(const M* message) GRPC_MUST_USE_RESULT; - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (msg_ == nullptr && !send_buf_.Valid()) return; - if (hijacked_) { - serializer_ = nullptr; - return; - } - if (msg_ != nullptr) { - GPR_CODEGEN_ASSERT(serializer_(msg_).ok()); - } - serializer_ = nullptr; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_SEND_MESSAGE; - op->flags = write_options_.flags(); - op->reserved = NULL; - op->data.send_message.send_message = send_buf_.c_buffer(); - // Flags are per-message: clear them after use. - write_options_.Clear(); - } - void FinishOp(bool* status) { - if (msg_ == nullptr && !send_buf_.Valid()) return; - if (hijacked_ && failed_send_) { - // Hijacking interceptor failed this Op - *status = false; - } else if (!*status) { - // This Op was passed down to core and the Op failed - failed_send_ = true; - } - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (msg_ == nullptr && !send_buf_.Valid()) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_SEND_MESSAGE); - interceptor_methods->SetSendMessage(&send_buf_, &msg_, &failed_send_, - serializer_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (msg_ != nullptr || send_buf_.Valid()) { - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_SEND_MESSAGE); - } - send_buf_.Clear(); - msg_ = nullptr; - // The contents of the SendMessage value that was previously set - // has had its references stolen by core's operations - interceptor_methods->SetSendMessage(nullptr, nullptr, &failed_send_, - nullptr); - } - + grpc_metadata* initial_metadata_; + struct { + bool is_set; + grpc_compression_level level; + } maybe_compression_level_; +}; + +class CallOpSendMessage { + public: + CallOpSendMessage() : send_buf_() {} + + /// Send \a message using \a options for the write. The \a options are cleared + /// after use. + template <class M> + Status SendMessage(const M& message, + WriteOptions options) GRPC_MUST_USE_RESULT; + + template <class M> + Status SendMessage(const M& message) GRPC_MUST_USE_RESULT; + + /// Send \a message using \a options for the write. The \a options are cleared + /// after use. This form of SendMessage allows gRPC to reference \a message + /// beyond the lifetime of SendMessage. + template <class M> + Status SendMessagePtr(const M* message, + WriteOptions options) GRPC_MUST_USE_RESULT; + + /// This form of SendMessage allows gRPC to reference \a message beyond the + /// lifetime of SendMessage. + template <class M> + Status SendMessagePtr(const M* message) GRPC_MUST_USE_RESULT; + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (msg_ == nullptr && !send_buf_.Valid()) return; + if (hijacked_) { + serializer_ = nullptr; + return; + } + if (msg_ != nullptr) { + GPR_CODEGEN_ASSERT(serializer_(msg_).ok()); + } + serializer_ = nullptr; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_SEND_MESSAGE; + op->flags = write_options_.flags(); + op->reserved = NULL; + op->data.send_message.send_message = send_buf_.c_buffer(); + // Flags are per-message: clear them after use. + write_options_.Clear(); + } + void FinishOp(bool* status) { + if (msg_ == nullptr && !send_buf_.Valid()) return; + if (hijacked_ && failed_send_) { + // Hijacking interceptor failed this Op + *status = false; + } else if (!*status) { + // This Op was passed down to core and the Op failed + failed_send_ = true; + } + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (msg_ == nullptr && !send_buf_.Valid()) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_SEND_MESSAGE); + interceptor_methods->SetSendMessage(&send_buf_, &msg_, &failed_send_, + serializer_); + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (msg_ != nullptr || send_buf_.Valid()) { + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_SEND_MESSAGE); + } + send_buf_.Clear(); + msg_ = nullptr; + // The contents of the SendMessage value that was previously set + // has had its references stolen by core's operations + interceptor_methods->SetSendMessage(nullptr, nullptr, &failed_send_, + nullptr); + } + void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { - hijacked_ = true; - } - - private: - const void* msg_ = nullptr; // The original non-serialized message - bool hijacked_ = false; - bool failed_send_ = false; - ByteBuffer send_buf_; - WriteOptions write_options_; - std::function<Status(const void*)> serializer_; -}; - -template <class M> -Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { - write_options_ = options; - serializer_ = [this](const void* message) { - bool own_buf; - send_buf_.Clear(); - // TODO(vjpai): Remove the void below when possible - // The void in the template parameter below should not be needed - // (since it should be implicit) but is needed due to an observed - // difference in behavior between clang and gcc for certain internal users - Status result = SerializationTraits<M, void>::Serialize( - *static_cast<const M*>(message), send_buf_.bbuf_ptr(), &own_buf); - if (!own_buf) { - send_buf_.Duplicate(); - } - return result; - }; - // Serialize immediately only if we do not have access to the message pointer - if (msg_ == nullptr) { - Status result = serializer_(&message); - serializer_ = nullptr; - return result; - } - return Status(); -} - -template <class M> -Status CallOpSendMessage::SendMessage(const M& message) { - return SendMessage(message, WriteOptions()); -} - -template <class M> -Status CallOpSendMessage::SendMessagePtr(const M* message, - WriteOptions options) { - msg_ = message; - return SendMessage(*message, options); -} - -template <class M> -Status CallOpSendMessage::SendMessagePtr(const M* message) { - msg_ = message; - return SendMessage(*message, WriteOptions()); -} - -template <class R> -class CallOpRecvMessage { - public: - void RecvMessage(R* message) { message_ = message; } - - // Do not change status if no message is received. - void AllowNoMessage() { allow_not_getting_message_ = true; } - + hijacked_ = true; + } + + private: + const void* msg_ = nullptr; // The original non-serialized message + bool hijacked_ = false; + bool failed_send_ = false; + ByteBuffer send_buf_; + WriteOptions write_options_; + std::function<Status(const void*)> serializer_; +}; + +template <class M> +Status CallOpSendMessage::SendMessage(const M& message, WriteOptions options) { + write_options_ = options; + serializer_ = [this](const void* message) { + bool own_buf; + send_buf_.Clear(); + // TODO(vjpai): Remove the void below when possible + // The void in the template parameter below should not be needed + // (since it should be implicit) but is needed due to an observed + // difference in behavior between clang and gcc for certain internal users + Status result = SerializationTraits<M, void>::Serialize( + *static_cast<const M*>(message), send_buf_.bbuf_ptr(), &own_buf); + if (!own_buf) { + send_buf_.Duplicate(); + } + return result; + }; + // Serialize immediately only if we do not have access to the message pointer + if (msg_ == nullptr) { + Status result = serializer_(&message); + serializer_ = nullptr; + return result; + } + return Status(); +} + +template <class M> +Status CallOpSendMessage::SendMessage(const M& message) { + return SendMessage(message, WriteOptions()); +} + +template <class M> +Status CallOpSendMessage::SendMessagePtr(const M* message, + WriteOptions options) { + msg_ = message; + return SendMessage(*message, options); +} + +template <class M> +Status CallOpSendMessage::SendMessagePtr(const M* message) { + msg_ = message; + return SendMessage(*message, WriteOptions()); +} + +template <class R> +class CallOpRecvMessage { + public: + void RecvMessage(R* message) { message_ = message; } + + // Do not change status if no message is received. + void AllowNoMessage() { allow_not_getting_message_ = true; } + bool got_message = false; - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (message_ == nullptr || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_RECV_MESSAGE; - op->flags = 0; - op->reserved = NULL; - op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); - } - - void FinishOp(bool* status) { + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (message_ == nullptr || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_RECV_MESSAGE; + op->flags = 0; + op->reserved = NULL; + op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); + } + + void FinishOp(bool* status) { if (message_ == nullptr) return; - if (recv_buf_.Valid()) { - if (*status) { - got_message = *status = - SerializationTraits<R>::Deserialize(recv_buf_.bbuf_ptr(), message_) - .ok(); - recv_buf_.Release(); - } else { - got_message = false; - recv_buf_.Clear(); - } + if (recv_buf_.Valid()) { + if (*status) { + got_message = *status = + SerializationTraits<R>::Deserialize(recv_buf_.bbuf_ptr(), message_) + .ok(); + recv_buf_.Release(); + } else { + got_message = false; + recv_buf_.Clear(); + } } else if (hijacked_) { if (hijacked_recv_message_failed_) { FinishOpRecvMessageFailureHandler(status); @@ -463,34 +463,34 @@ class CallOpRecvMessage { // to be performed since the message is already in its non-serialized // form. } - } else { + } else { FinishOpRecvMessageFailureHandler(status); - } - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (message_ == nullptr) return; + } + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (message_ == nullptr) return; interceptor_methods->SetRecvMessage(message_, &hijacked_recv_message_failed_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (message_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_MESSAGE); - if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr); - } - void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { - hijacked_ = true; - if (message_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_RECV_MESSAGE); - got_message = true; - } - - private: + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (message_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_MESSAGE); + if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr); + } + void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { + hijacked_ = true; + if (message_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_RECV_MESSAGE); + got_message = true; + } + + private: // Sets got_message and \a status for a failed recv message op void FinishOpRecvMessageFailureHandler(bool* status) { got_message = false; @@ -500,69 +500,69 @@ class CallOpRecvMessage { } R* message_ = nullptr; - ByteBuffer recv_buf_; + ByteBuffer recv_buf_; bool allow_not_getting_message_ = false; - bool hijacked_ = false; + bool hijacked_ = false; bool hijacked_recv_message_failed_ = false; -}; - -class DeserializeFunc { - public: - virtual Status Deserialize(ByteBuffer* buf) = 0; - virtual ~DeserializeFunc() {} -}; - -template <class R> -class DeserializeFuncType final : public DeserializeFunc { - public: - DeserializeFuncType(R* message) : message_(message) {} - Status Deserialize(ByteBuffer* buf) override { - return SerializationTraits<R>::Deserialize(buf->bbuf_ptr(), message_); - } - - ~DeserializeFuncType() override {} - - private: - R* message_; // Not a managed pointer because management is external to this -}; - -class CallOpGenericRecvMessage { - public: - template <class R> - void RecvMessage(R* message) { - // Use an explicit base class pointer to avoid resolution error in the - // following unique_ptr::reset for some old implementations. - DeserializeFunc* func = new DeserializeFuncType<R>(message); - deserialize_.reset(func); - message_ = message; - } - - // Do not change status if no message is received. - void AllowNoMessage() { allow_not_getting_message_ = true; } - +}; + +class DeserializeFunc { + public: + virtual Status Deserialize(ByteBuffer* buf) = 0; + virtual ~DeserializeFunc() {} +}; + +template <class R> +class DeserializeFuncType final : public DeserializeFunc { + public: + DeserializeFuncType(R* message) : message_(message) {} + Status Deserialize(ByteBuffer* buf) override { + return SerializationTraits<R>::Deserialize(buf->bbuf_ptr(), message_); + } + + ~DeserializeFuncType() override {} + + private: + R* message_; // Not a managed pointer because management is external to this +}; + +class CallOpGenericRecvMessage { + public: + template <class R> + void RecvMessage(R* message) { + // Use an explicit base class pointer to avoid resolution error in the + // following unique_ptr::reset for some old implementations. + DeserializeFunc* func = new DeserializeFuncType<R>(message); + deserialize_.reset(func); + message_ = message; + } + + // Do not change status if no message is received. + void AllowNoMessage() { allow_not_getting_message_ = true; } + bool got_message = false; - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (!deserialize_ || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_RECV_MESSAGE; - op->flags = 0; - op->reserved = NULL; - op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); - } - - void FinishOp(bool* status) { + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (!deserialize_ || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_RECV_MESSAGE; + op->flags = 0; + op->reserved = NULL; + op->data.recv_message.recv_message = recv_buf_.c_buffer_ptr(); + } + + void FinishOp(bool* status) { if (!deserialize_) return; - if (recv_buf_.Valid()) { - if (*status) { - got_message = true; - *status = deserialize_->Deserialize(&recv_buf_).ok(); - recv_buf_.Release(); - } else { - got_message = false; - recv_buf_.Clear(); - } + if (recv_buf_.Valid()) { + if (*status) { + got_message = true; + *status = deserialize_->Deserialize(&recv_buf_).ok(); + recv_buf_.Release(); + } else { + got_message = false; + recv_buf_.Clear(); + } } else if (hijacked_) { if (hijacked_recv_message_failed_) { FinishOpRecvMessageFailureHandler(status); @@ -571,38 +571,38 @@ class CallOpGenericRecvMessage { // to be performed since the message is already in its non-serialized // form. } - } else { - got_message = false; - if (!allow_not_getting_message_) { - *status = false; - } - } - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!deserialize_) return; + } else { + got_message = false; + if (!allow_not_getting_message_) { + *status = false; + } + } + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!deserialize_) return; interceptor_methods->SetRecvMessage(message_, &hijacked_recv_message_failed_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!deserialize_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_MESSAGE); - if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr); + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!deserialize_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_MESSAGE); + if (!got_message) interceptor_methods->SetRecvMessage(nullptr, nullptr); deserialize_.reset(); - } - void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { - hijacked_ = true; - if (!deserialize_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_RECV_MESSAGE); - got_message = true; - } - - private: + } + void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { + hijacked_ = true; + if (!deserialize_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_RECV_MESSAGE); + got_message = true; + } + + private: // Sets got_message and \a status for a failed recv message op void FinishOpRecvMessageFailureHandler(bool* status) { got_message = false; @@ -612,190 +612,190 @@ class CallOpGenericRecvMessage { } void* message_ = nullptr; - std::unique_ptr<DeserializeFunc> deserialize_; - ByteBuffer recv_buf_; + std::unique_ptr<DeserializeFunc> deserialize_; + ByteBuffer recv_buf_; bool allow_not_getting_message_ = false; bool hijacked_ = false; bool hijacked_recv_message_failed_ = false; -}; - -class CallOpClientSendClose { - public: - CallOpClientSendClose() : send_(false) {} - - void ClientSendClose() { send_ = true; } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (!send_ || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; - op->flags = 0; - op->reserved = NULL; - } +}; + +class CallOpClientSendClose { + public: + CallOpClientSendClose() : send_(false) {} + + void ClientSendClose() { send_ = true; } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (!send_ || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = NULL; + } void FinishOp(bool* /*status*/) { send_ = false; } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!send_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_SEND_CLOSE); - } - - void SetFinishInterceptionHookPoint( + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!send_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_SEND_CLOSE); + } + + void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} - + void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { - hijacked_ = true; - } - - private: - bool hijacked_ = false; - bool send_; -}; - -class CallOpServerSendStatus { - public: - CallOpServerSendStatus() : send_status_available_(false) {} - - void ServerSendStatus( + hijacked_ = true; + } + + private: + bool hijacked_ = false; + bool send_; +}; + +class CallOpServerSendStatus { + public: + CallOpServerSendStatus() : send_status_available_(false) {} + + void ServerSendStatus( std::multimap<TString, TString>* trailing_metadata, - const Status& status) { - send_error_details_ = status.error_details(); - metadata_map_ = trailing_metadata; - send_status_available_ = true; - send_status_code_ = static_cast<grpc_status_code>(status.error_code()); - send_error_message_ = status.error_message(); - } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (!send_status_available_ || hijacked_) return; - trailing_metadata_ = FillMetadataArray( - *metadata_map_, &trailing_metadata_count_, send_error_details_); - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; - op->data.send_status_from_server.trailing_metadata_count = - trailing_metadata_count_; - op->data.send_status_from_server.trailing_metadata = trailing_metadata_; - op->data.send_status_from_server.status = send_status_code_; - error_message_slice_ = SliceReferencingString(send_error_message_); - op->data.send_status_from_server.status_details = - send_error_message_.empty() ? nullptr : &error_message_slice_; - op->flags = 0; - op->reserved = NULL; - } - + const Status& status) { + send_error_details_ = status.error_details(); + metadata_map_ = trailing_metadata; + send_status_available_ = true; + send_status_code_ = static_cast<grpc_status_code>(status.error_code()); + send_error_message_ = status.error_message(); + } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (!send_status_available_ || hijacked_) return; + trailing_metadata_ = FillMetadataArray( + *metadata_map_, &trailing_metadata_count_, send_error_details_); + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = + trailing_metadata_count_; + op->data.send_status_from_server.trailing_metadata = trailing_metadata_; + op->data.send_status_from_server.status = send_status_code_; + error_message_slice_ = SliceReferencingString(send_error_message_); + op->data.send_status_from_server.status_details = + send_error_message_.empty() ? nullptr : &error_message_slice_; + op->flags = 0; + op->reserved = NULL; + } + void FinishOp(bool* /*status*/) { - if (!send_status_available_ || hijacked_) return; - g_core_codegen_interface->gpr_free(trailing_metadata_); - send_status_available_ = false; - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (!send_status_available_) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_SEND_STATUS); - interceptor_methods->SetSendTrailingMetadata(metadata_map_); - interceptor_methods->SetSendStatus(&send_status_code_, &send_error_details_, - &send_error_message_); - } - - void SetFinishInterceptionHookPoint( + if (!send_status_available_ || hijacked_) return; + g_core_codegen_interface->gpr_free(trailing_metadata_); + send_status_available_ = false; + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (!send_status_available_) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_SEND_STATUS); + interceptor_methods->SetSendTrailingMetadata(metadata_map_); + interceptor_methods->SetSendStatus(&send_status_code_, &send_error_details_, + &send_error_message_); + } + + void SetFinishInterceptionHookPoint( InterceptorBatchMethodsImpl* /*interceptor_methods*/) {} - + void SetHijackingState(InterceptorBatchMethodsImpl* /*interceptor_methods*/) { - hijacked_ = true; - } - - private: - bool hijacked_ = false; - bool send_status_available_; - grpc_status_code send_status_code_; + hijacked_ = true; + } + + private: + bool hijacked_ = false; + bool send_status_available_; + grpc_status_code send_status_code_; TString send_error_details_; TString send_error_message_; - size_t trailing_metadata_count_; + size_t trailing_metadata_count_; std::multimap<TString, TString>* metadata_map_; - grpc_metadata* trailing_metadata_; - grpc_slice error_message_slice_; -}; - -class CallOpRecvInitialMetadata { - public: - CallOpRecvInitialMetadata() : metadata_map_(nullptr) {} - + grpc_metadata* trailing_metadata_; + grpc_slice error_message_slice_; +}; + +class CallOpRecvInitialMetadata { + public: + CallOpRecvInitialMetadata() : metadata_map_(nullptr) {} + void RecvInitialMetadata(::grpc::ClientContext* context) { - context->initial_metadata_received_ = true; - metadata_map_ = &context->recv_initial_metadata_; - } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (metadata_map_ == nullptr || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata.recv_initial_metadata = metadata_map_->arr(); - op->flags = 0; - op->reserved = NULL; - } - + context->initial_metadata_received_ = true; + metadata_map_ = &context->recv_initial_metadata_; + } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (metadata_map_ == nullptr || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata.recv_initial_metadata = metadata_map_->arr(); + op->flags = 0; + op->reserved = NULL; + } + void FinishOp(bool* /*status*/) { - if (metadata_map_ == nullptr || hijacked_) return; - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - interceptor_methods->SetRecvInitialMetadata(metadata_map_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (metadata_map_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA); - metadata_map_ = nullptr; - } - - void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { - hijacked_ = true; - if (metadata_map_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_RECV_INITIAL_METADATA); - } - - private: - bool hijacked_ = false; - MetadataMap* metadata_map_; -}; - -class CallOpClientRecvStatus { - public: - CallOpClientRecvStatus() - : recv_status_(nullptr), debug_error_string_(nullptr) {} - + if (metadata_map_ == nullptr || hijacked_) return; + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + interceptor_methods->SetRecvInitialMetadata(metadata_map_); + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (metadata_map_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_INITIAL_METADATA); + metadata_map_ = nullptr; + } + + void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { + hijacked_ = true; + if (metadata_map_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_RECV_INITIAL_METADATA); + } + + private: + bool hijacked_ = false; + MetadataMap* metadata_map_; +}; + +class CallOpClientRecvStatus { + public: + CallOpClientRecvStatus() + : recv_status_(nullptr), debug_error_string_(nullptr) {} + void ClientRecvStatus(::grpc::ClientContext* context, Status* status) { - client_context_ = context; - metadata_map_ = &client_context_->trailing_metadata_; - recv_status_ = status; - error_message_ = g_core_codegen_interface->grpc_empty_slice(); - } - - protected: - void AddOp(grpc_op* ops, size_t* nops) { - if (recv_status_ == nullptr || hijacked_) return; - grpc_op* op = &ops[(*nops)++]; - op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = metadata_map_->arr(); - op->data.recv_status_on_client.status = &status_code_; - op->data.recv_status_on_client.status_details = &error_message_; - op->data.recv_status_on_client.error_string = &debug_error_string_; - op->flags = 0; - op->reserved = NULL; - } - + client_context_ = context; + metadata_map_ = &client_context_->trailing_metadata_; + recv_status_ = status; + error_message_ = g_core_codegen_interface->grpc_empty_slice(); + } + + protected: + void AddOp(grpc_op* ops, size_t* nops) { + if (recv_status_ == nullptr || hijacked_) return; + grpc_op* op = &ops[(*nops)++]; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = metadata_map_->arr(); + op->data.recv_status_on_client.status = &status_code_; + op->data.recv_status_on_client.status_details = &error_message_; + op->data.recv_status_on_client.error_string = &debug_error_string_; + op->flags = 0; + op->reserved = NULL; + } + void FinishOp(bool* /*status*/) { - if (recv_status_ == nullptr || hijacked_) return; + if (recv_status_ == nullptr || hijacked_) return; if (static_cast<StatusCode>(status_code_) == StatusCode::OK) { *recv_status_ = Status(); GPR_CODEGEN_DEBUG_ASSERT(debug_error_string_ == nullptr); @@ -814,156 +814,156 @@ class CallOpClientRecvStatus { } // TODO(soheil): Find callers that set debug string even for status OK, // and fix them. - g_core_codegen_interface->grpc_slice_unref(error_message_); - } - - void SetInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - interceptor_methods->SetRecvStatus(recv_status_); - interceptor_methods->SetRecvTrailingMetadata(metadata_map_); - } - - void SetFinishInterceptionHookPoint( - InterceptorBatchMethodsImpl* interceptor_methods) { - if (recv_status_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_STATUS); - recv_status_ = nullptr; - } - - void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { - hijacked_ = true; - if (recv_status_ == nullptr) return; - interceptor_methods->AddInterceptionHookPoint( - experimental::InterceptionHookPoints::PRE_RECV_STATUS); - } - - private: - bool hijacked_ = false; + g_core_codegen_interface->grpc_slice_unref(error_message_); + } + + void SetInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + interceptor_methods->SetRecvStatus(recv_status_); + interceptor_methods->SetRecvTrailingMetadata(metadata_map_); + } + + void SetFinishInterceptionHookPoint( + InterceptorBatchMethodsImpl* interceptor_methods) { + if (recv_status_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_STATUS); + recv_status_ = nullptr; + } + + void SetHijackingState(InterceptorBatchMethodsImpl* interceptor_methods) { + hijacked_ = true; + if (recv_status_ == nullptr) return; + interceptor_methods->AddInterceptionHookPoint( + experimental::InterceptionHookPoints::PRE_RECV_STATUS); + } + + private: + bool hijacked_ = false; ::grpc::ClientContext* client_context_; - MetadataMap* metadata_map_; - Status* recv_status_; - const char* debug_error_string_; - grpc_status_code status_code_; - grpc_slice error_message_; -}; - -template <class Op1 = CallNoOp<1>, class Op2 = CallNoOp<2>, - class Op3 = CallNoOp<3>, class Op4 = CallNoOp<4>, - class Op5 = CallNoOp<5>, class Op6 = CallNoOp<6>> -class CallOpSet; - -/// Primary implementation of CallOpSetInterface. -/// Since we cannot use variadic templates, we declare slots up to -/// the maximum count of ops we'll need in a set. We leverage the -/// empty base class optimization to slim this class (especially -/// when there are many unused slots used). To avoid duplicate base classes, + MetadataMap* metadata_map_; + Status* recv_status_; + const char* debug_error_string_; + grpc_status_code status_code_; + grpc_slice error_message_; +}; + +template <class Op1 = CallNoOp<1>, class Op2 = CallNoOp<2>, + class Op3 = CallNoOp<3>, class Op4 = CallNoOp<4>, + class Op5 = CallNoOp<5>, class Op6 = CallNoOp<6>> +class CallOpSet; + +/// Primary implementation of CallOpSetInterface. +/// Since we cannot use variadic templates, we declare slots up to +/// the maximum count of ops we'll need in a set. We leverage the +/// empty base class optimization to slim this class (especially +/// when there are many unused slots used). To avoid duplicate base classes, /// the template parameter for CallNoOp is varied by argument position. -template <class Op1, class Op2, class Op3, class Op4, class Op5, class Op6> -class CallOpSet : public CallOpSetInterface, - public Op1, - public Op2, - public Op3, - public Op4, - public Op5, - public Op6 { - public: - CallOpSet() : core_cq_tag_(this), return_tag_(this) {} - // The copy constructor and assignment operator reset the value of - // core_cq_tag_, return_tag_, done_intercepting_ and interceptor_methods_ - // since those are only meaningful on a specific object, not across objects. - CallOpSet(const CallOpSet& other) - : core_cq_tag_(this), - return_tag_(this), - call_(other.call_), - done_intercepting_(false), - interceptor_methods_(InterceptorBatchMethodsImpl()) {} - - CallOpSet& operator=(const CallOpSet& other) { - core_cq_tag_ = this; - return_tag_ = this; - call_ = other.call_; - done_intercepting_ = false; - interceptor_methods_ = InterceptorBatchMethodsImpl(); - return *this; - } - - void FillOps(Call* call) override { - done_intercepting_ = false; - g_core_codegen_interface->grpc_call_ref(call->call()); - call_ = - *call; // It's fine to create a copy of call since it's just pointers - - if (RunInterceptors()) { - ContinueFillOpsAfterInterception(); - } else { - // After the interceptors are run, ContinueFillOpsAfterInterception will - // be run - } - } - - bool FinalizeResult(void** tag, bool* status) override { - if (done_intercepting_) { - // Complete the avalanching since we are done with this batch of ops - call_.cq()->CompleteAvalanching(); - // We have already finished intercepting and filling in the results. This - // round trip from the core needed to be made because interceptors were - // run - *tag = return_tag_; - *status = saved_status_; - g_core_codegen_interface->grpc_call_unref(call_.call()); - return true; - } - - this->Op1::FinishOp(status); - this->Op2::FinishOp(status); - this->Op3::FinishOp(status); - this->Op4::FinishOp(status); - this->Op5::FinishOp(status); - this->Op6::FinishOp(status); - saved_status_ = *status; - if (RunInterceptorsPostRecv()) { - *tag = return_tag_; - g_core_codegen_interface->grpc_call_unref(call_.call()); - return true; - } - // Interceptors are going to be run, so we can't return the tag just yet. - // After the interceptors are run, ContinueFinalizeResultAfterInterception - return false; - } - - void set_output_tag(void* return_tag) { return_tag_ = return_tag; } - - void* core_cq_tag() override { return core_cq_tag_; } - - /// set_core_cq_tag is used to provide a different core CQ tag than "this". - /// This is used for callback-based tags, where the core tag is the core - /// callback function. It does not change the use or behavior of any other - /// function (such as FinalizeResult) - void set_core_cq_tag(void* core_cq_tag) { core_cq_tag_ = core_cq_tag; } - - // This will be called while interceptors are run if the RPC is a hijacked - // RPC. This should set hijacking state for each of the ops. - void SetHijackingState() override { - this->Op1::SetHijackingState(&interceptor_methods_); - this->Op2::SetHijackingState(&interceptor_methods_); - this->Op3::SetHijackingState(&interceptor_methods_); - this->Op4::SetHijackingState(&interceptor_methods_); - this->Op5::SetHijackingState(&interceptor_methods_); - this->Op6::SetHijackingState(&interceptor_methods_); - } - - // Should be called after interceptors are done running - void ContinueFillOpsAfterInterception() override { - static const size_t MAX_OPS = 6; - grpc_op ops[MAX_OPS]; - size_t nops = 0; - this->Op1::AddOp(ops, &nops); - this->Op2::AddOp(ops, &nops); - this->Op3::AddOp(ops, &nops); - this->Op4::AddOp(ops, &nops); - this->Op5::AddOp(ops, &nops); - this->Op6::AddOp(ops, &nops); +template <class Op1, class Op2, class Op3, class Op4, class Op5, class Op6> +class CallOpSet : public CallOpSetInterface, + public Op1, + public Op2, + public Op3, + public Op4, + public Op5, + public Op6 { + public: + CallOpSet() : core_cq_tag_(this), return_tag_(this) {} + // The copy constructor and assignment operator reset the value of + // core_cq_tag_, return_tag_, done_intercepting_ and interceptor_methods_ + // since those are only meaningful on a specific object, not across objects. + CallOpSet(const CallOpSet& other) + : core_cq_tag_(this), + return_tag_(this), + call_(other.call_), + done_intercepting_(false), + interceptor_methods_(InterceptorBatchMethodsImpl()) {} + + CallOpSet& operator=(const CallOpSet& other) { + core_cq_tag_ = this; + return_tag_ = this; + call_ = other.call_; + done_intercepting_ = false; + interceptor_methods_ = InterceptorBatchMethodsImpl(); + return *this; + } + + void FillOps(Call* call) override { + done_intercepting_ = false; + g_core_codegen_interface->grpc_call_ref(call->call()); + call_ = + *call; // It's fine to create a copy of call since it's just pointers + + if (RunInterceptors()) { + ContinueFillOpsAfterInterception(); + } else { + // After the interceptors are run, ContinueFillOpsAfterInterception will + // be run + } + } + + bool FinalizeResult(void** tag, bool* status) override { + if (done_intercepting_) { + // Complete the avalanching since we are done with this batch of ops + call_.cq()->CompleteAvalanching(); + // We have already finished intercepting and filling in the results. This + // round trip from the core needed to be made because interceptors were + // run + *tag = return_tag_; + *status = saved_status_; + g_core_codegen_interface->grpc_call_unref(call_.call()); + return true; + } + + this->Op1::FinishOp(status); + this->Op2::FinishOp(status); + this->Op3::FinishOp(status); + this->Op4::FinishOp(status); + this->Op5::FinishOp(status); + this->Op6::FinishOp(status); + saved_status_ = *status; + if (RunInterceptorsPostRecv()) { + *tag = return_tag_; + g_core_codegen_interface->grpc_call_unref(call_.call()); + return true; + } + // Interceptors are going to be run, so we can't return the tag just yet. + // After the interceptors are run, ContinueFinalizeResultAfterInterception + return false; + } + + void set_output_tag(void* return_tag) { return_tag_ = return_tag; } + + void* core_cq_tag() override { return core_cq_tag_; } + + /// set_core_cq_tag is used to provide a different core CQ tag than "this". + /// This is used for callback-based tags, where the core tag is the core + /// callback function. It does not change the use or behavior of any other + /// function (such as FinalizeResult) + void set_core_cq_tag(void* core_cq_tag) { core_cq_tag_ = core_cq_tag; } + + // This will be called while interceptors are run if the RPC is a hijacked + // RPC. This should set hijacking state for each of the ops. + void SetHijackingState() override { + this->Op1::SetHijackingState(&interceptor_methods_); + this->Op2::SetHijackingState(&interceptor_methods_); + this->Op3::SetHijackingState(&interceptor_methods_); + this->Op4::SetHijackingState(&interceptor_methods_); + this->Op5::SetHijackingState(&interceptor_methods_); + this->Op6::SetHijackingState(&interceptor_methods_); + } + + // Should be called after interceptors are done running + void ContinueFillOpsAfterInterception() override { + static const size_t MAX_OPS = 6; + grpc_op ops[MAX_OPS]; + size_t nops = 0; + this->Op1::AddOp(ops, &nops); + this->Op2::AddOp(ops, &nops); + this->Op3::AddOp(ops, &nops); + this->Op4::AddOp(ops, &nops); + this->Op5::AddOp(ops, &nops); + this->Op6::AddOp(ops, &nops); grpc_call_error err = g_core_codegen_interface->grpc_call_start_batch( call_.call(), ops, nops, core_cq_tag(), nullptr); @@ -976,62 +976,62 @@ class CallOpSet : public CallOpSetInterface, // g_core_codegen_interface->grpc_call_error_to_string(err)); GPR_CODEGEN_ASSERT(false); } - } - - // Should be called after interceptors are done running on the finalize result - // path - void ContinueFinalizeResultAfterInterception() override { - done_intercepting_ = true; + } + + // Should be called after interceptors are done running on the finalize result + // path + void ContinueFinalizeResultAfterInterception() override { + done_intercepting_ = true; // The following call_start_batch is internally-generated so no need for an // explanatory log on failure. GPR_CODEGEN_ASSERT(g_core_codegen_interface->grpc_call_start_batch( call_.call(), nullptr, 0, core_cq_tag(), nullptr) == GRPC_CALL_OK); - } - - private: - // Returns true if no interceptors need to be run - bool RunInterceptors() { - interceptor_methods_.ClearState(); - interceptor_methods_.SetCallOpSetInterface(this); - interceptor_methods_.SetCall(&call_); - this->Op1::SetInterceptionHookPoint(&interceptor_methods_); - this->Op2::SetInterceptionHookPoint(&interceptor_methods_); - this->Op3::SetInterceptionHookPoint(&interceptor_methods_); - this->Op4::SetInterceptionHookPoint(&interceptor_methods_); - this->Op5::SetInterceptionHookPoint(&interceptor_methods_); - this->Op6::SetInterceptionHookPoint(&interceptor_methods_); - if (interceptor_methods_.InterceptorsListEmpty()) { - return true; - } - // This call will go through interceptors and would need to - // schedule new batches, so delay completion queue shutdown - call_.cq()->RegisterAvalanching(); - return interceptor_methods_.RunInterceptors(); - } - // Returns true if no interceptors need to be run - bool RunInterceptorsPostRecv() { - // Call and OpSet had already been set on the set state. - // SetReverse also clears previously set hook points - interceptor_methods_.SetReverse(); - this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op2::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op3::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op4::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op5::SetFinishInterceptionHookPoint(&interceptor_methods_); - this->Op6::SetFinishInterceptionHookPoint(&interceptor_methods_); - return interceptor_methods_.RunInterceptors(); - } - - void* core_cq_tag_; - void* return_tag_; - Call call_; - bool done_intercepting_ = false; - InterceptorBatchMethodsImpl interceptor_methods_; - bool saved_status_; -}; - -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H + } + + private: + // Returns true if no interceptors need to be run + bool RunInterceptors() { + interceptor_methods_.ClearState(); + interceptor_methods_.SetCallOpSetInterface(this); + interceptor_methods_.SetCall(&call_); + this->Op1::SetInterceptionHookPoint(&interceptor_methods_); + this->Op2::SetInterceptionHookPoint(&interceptor_methods_); + this->Op3::SetInterceptionHookPoint(&interceptor_methods_); + this->Op4::SetInterceptionHookPoint(&interceptor_methods_); + this->Op5::SetInterceptionHookPoint(&interceptor_methods_); + this->Op6::SetInterceptionHookPoint(&interceptor_methods_); + if (interceptor_methods_.InterceptorsListEmpty()) { + return true; + } + // This call will go through interceptors and would need to + // schedule new batches, so delay completion queue shutdown + call_.cq()->RegisterAvalanching(); + return interceptor_methods_.RunInterceptors(); + } + // Returns true if no interceptors need to be run + bool RunInterceptorsPostRecv() { + // Call and OpSet had already been set on the set state. + // SetReverse also clears previously set hook points + interceptor_methods_.SetReverse(); + this->Op1::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op2::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op3::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op4::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op5::SetFinishInterceptionHookPoint(&interceptor_methods_); + this->Op6::SetFinishInterceptionHookPoint(&interceptor_methods_); + return interceptor_methods_.RunInterceptors(); + } + + void* core_cq_tag_; + void* return_tag_; + Call call_; + bool done_intercepting_ = false; + InterceptorBatchMethodsImpl interceptor_methods_; + bool saved_status_; +}; + +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set_interface.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set_interface.h index 3b74566a6d..664dae0e6a 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/call_op_set_interface.h @@ -1,59 +1,59 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H -#define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H - -#include <grpcpp/impl/codegen/completion_queue_tag.h> - -namespace grpc { -namespace internal { - -class Call; - -/// An abstract collection of call ops, used to generate the -/// grpc_call_op structure to pass down to the lower layers, -/// and as it is-a CompletionQueueTag, also massages the final -/// completion into the correct form for consumption in the C++ -/// API. -class CallOpSetInterface : public CompletionQueueTag { - public: - /// Fills in grpc_op, starting from ops[*nops] and moving - /// upwards. - virtual void FillOps(internal::Call* call) = 0; - - /// Get the tag to be used at the core completion queue. Generally, the - /// value of core_cq_tag will be "this". However, it can be overridden if we - /// want core to process the tag differently (e.g., as a core callback) - virtual void* core_cq_tag() = 0; - - // This will be called while interceptors are run if the RPC is a hijacked - // RPC. This should set hijacking state for each of the ops. - virtual void SetHijackingState() = 0; - - // Should be called after interceptors are done running - virtual void ContinueFillOpsAfterInterception() = 0; - - // Should be called after interceptors are done running on the finalize result - // path - virtual void ContinueFinalizeResultAfterInterception() = 0; -}; -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H +#define GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H + +#include <grpcpp/impl/codegen/completion_queue_tag.h> + +namespace grpc { +namespace internal { + +class Call; + +/// An abstract collection of call ops, used to generate the +/// grpc_call_op structure to pass down to the lower layers, +/// and as it is-a CompletionQueueTag, also massages the final +/// completion into the correct form for consumption in the C++ +/// API. +class CallOpSetInterface : public CompletionQueueTag { + public: + /// Fills in grpc_op, starting from ops[*nops] and moving + /// upwards. + virtual void FillOps(internal::Call* call) = 0; + + /// Get the tag to be used at the core completion queue. Generally, the + /// value of core_cq_tag will be "this". However, it can be overridden if we + /// want core to process the tag differently (e.g., as a core callback) + virtual void* core_cq_tag() = 0; + + // This will be called while interceptors are run if the RPC is a hijacked + // RPC. This should set hijacking state for each of the ops. + virtual void SetHijackingState() = 0; + + // Should be called after interceptors are done running + virtual void ContinueFillOpsAfterInterception() = 0; + + // Should be called after interceptors are done running on the finalize result + // path + virtual void ContinueFinalizeResultAfterInterception() = 0; +}; +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_CALL_OP_SET_INTERFACE_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h index 3c3bfd7e76..784ac3f835 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/callback_common.h @@ -1,226 +1,226 @@ -/* - * - * Copyright 2018 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. - * - */ - -#if defined(__GNUC__) -#pragma GCC system_header -#endif - -#ifndef GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H -#define GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H - -#include <functional> - -#include <grpc/impl/codegen/grpc_types.h> -#include <grpcpp/impl/codegen/call.h> -#include <grpcpp/impl/codegen/channel_interface.h> -#include <grpcpp/impl/codegen/config.h> -#include <grpcpp/impl/codegen/core_codegen_interface.h> -#include <grpcpp/impl/codegen/status.h> - -namespace grpc { -namespace internal { - -/// An exception-safe way of invoking a user-specified callback function -// TODO(vjpai): decide whether it is better for this to take a const lvalue -// parameter or an rvalue parameter, or if it even matters -template <class Func, class... Args> -void CatchingCallback(Func&& func, Args&&... args) { -#if GRPC_ALLOW_EXCEPTIONS - try { - func(std::forward<Args>(args)...); - } catch (...) { - // nothing to return or change here, just don't crash the library - } -#else // GRPC_ALLOW_EXCEPTIONS - func(std::forward<Args>(args)...); -#endif // GRPC_ALLOW_EXCEPTIONS -} - +/* + * + * Copyright 2018 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. + * + */ + +#if defined(__GNUC__) +#pragma GCC system_header +#endif + +#ifndef GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H +#define GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H + +#include <functional> + +#include <grpc/impl/codegen/grpc_types.h> +#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/channel_interface.h> +#include <grpcpp/impl/codegen/config.h> +#include <grpcpp/impl/codegen/core_codegen_interface.h> +#include <grpcpp/impl/codegen/status.h> + +namespace grpc { +namespace internal { + +/// An exception-safe way of invoking a user-specified callback function +// TODO(vjpai): decide whether it is better for this to take a const lvalue +// parameter or an rvalue parameter, or if it even matters +template <class Func, class... Args> +void CatchingCallback(Func&& func, Args&&... args) { +#if GRPC_ALLOW_EXCEPTIONS + try { + func(std::forward<Args>(args)...); + } catch (...) { + // nothing to return or change here, just don't crash the library + } +#else // GRPC_ALLOW_EXCEPTIONS + func(std::forward<Args>(args)...); +#endif // GRPC_ALLOW_EXCEPTIONS +} + template <class Reactor, class Func, class... Args> Reactor* CatchingReactorGetter(Func&& func, Args&&... args) { -#if GRPC_ALLOW_EXCEPTIONS - try { - return func(std::forward<Args>(args)...); - } catch (...) { - // fail the RPC, don't crash the library - return nullptr; - } -#else // GRPC_ALLOW_EXCEPTIONS - return func(std::forward<Args>(args)...); -#endif // GRPC_ALLOW_EXCEPTIONS -} - -// The contract on these tags is that they are single-shot. They must be -// constructed and then fired at exactly one point. There is no expectation -// that they can be reused without reconstruction. - -class CallbackWithStatusTag - : public grpc_experimental_completion_queue_functor { - public: - // always allocated against a call arena, no memory free required +#if GRPC_ALLOW_EXCEPTIONS + try { + return func(std::forward<Args>(args)...); + } catch (...) { + // fail the RPC, don't crash the library + return nullptr; + } +#else // GRPC_ALLOW_EXCEPTIONS + return func(std::forward<Args>(args)...); +#endif // GRPC_ALLOW_EXCEPTIONS +} + +// The contract on these tags is that they are single-shot. They must be +// constructed and then fired at exactly one point. There is no expectation +// that they can be reused without reconstruction. + +class CallbackWithStatusTag + : public grpc_experimental_completion_queue_functor { + public: + // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { GPR_CODEGEN_ASSERT(size == sizeof(CallbackWithStatusTag)); - } - - // This operator should never be called as the memory should be freed as part - // of the arena destruction. It only exists to provide a matching operator - // delete to the operator new so that some compilers will not complain (see - // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this - // there are no tests catching the compiler warning. + } + + // This operator should never be called as the memory should be freed as part + // of the arena destruction. It only exists to provide a matching operator + // delete to the operator new so that some compilers will not complain (see + // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this + // there are no tests catching the compiler warning. static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } - - CallbackWithStatusTag(grpc_call* call, std::function<void(Status)> f, - CompletionQueueTag* ops) - : call_(call), func_(std::move(f)), ops_(ops) { - g_core_codegen_interface->grpc_call_ref(call); - functor_run = &CallbackWithStatusTag::StaticRun; + + CallbackWithStatusTag(grpc_call* call, std::function<void(Status)> f, + CompletionQueueTag* ops) + : call_(call), func_(std::move(f)), ops_(ops) { + g_core_codegen_interface->grpc_call_ref(call); + functor_run = &CallbackWithStatusTag::StaticRun; // A client-side callback should never be run inline since they will always // have work to do from the user application. So, set the parent's // inlineable field to false inlineable = false; - } - ~CallbackWithStatusTag() {} - Status* status_ptr() { return &status_; } - - // force_run can not be performed on a tag if operations using this tag - // have been sent to PerformOpsOnCall. It is intended for error conditions - // that are detected before the operations are internally processed. - void force_run(Status s) { - status_ = std::move(s); - Run(true); - } - - private: - grpc_call* call_; - std::function<void(Status)> func_; - CompletionQueueTag* ops_; - Status status_; - - static void StaticRun(grpc_experimental_completion_queue_functor* cb, - int ok) { - static_cast<CallbackWithStatusTag*>(cb)->Run(static_cast<bool>(ok)); - } - void Run(bool ok) { - void* ignored = ops_; - - if (!ops_->FinalizeResult(&ignored, &ok)) { - // The tag was swallowed - return; - } - GPR_CODEGEN_ASSERT(ignored == ops_); - - // Last use of func_ or status_, so ok to move them out - auto func = std::move(func_); - auto status = std::move(status_); - func_ = nullptr; // reset to clear this out for sure - status_ = Status(); // reset to clear this out for sure - CatchingCallback(std::move(func), std::move(status)); - g_core_codegen_interface->grpc_call_unref(call_); - } -}; - -/// CallbackWithSuccessTag can be reused multiple times, and will be used in -/// this fashion for streaming operations. As a result, it shouldn't clear -/// anything up until its destructor -class CallbackWithSuccessTag - : public grpc_experimental_completion_queue_functor { - public: - // always allocated against a call arena, no memory free required + } + ~CallbackWithStatusTag() {} + Status* status_ptr() { return &status_; } + + // force_run can not be performed on a tag if operations using this tag + // have been sent to PerformOpsOnCall. It is intended for error conditions + // that are detected before the operations are internally processed. + void force_run(Status s) { + status_ = std::move(s); + Run(true); + } + + private: + grpc_call* call_; + std::function<void(Status)> func_; + CompletionQueueTag* ops_; + Status status_; + + static void StaticRun(grpc_experimental_completion_queue_functor* cb, + int ok) { + static_cast<CallbackWithStatusTag*>(cb)->Run(static_cast<bool>(ok)); + } + void Run(bool ok) { + void* ignored = ops_; + + if (!ops_->FinalizeResult(&ignored, &ok)) { + // The tag was swallowed + return; + } + GPR_CODEGEN_ASSERT(ignored == ops_); + + // Last use of func_ or status_, so ok to move them out + auto func = std::move(func_); + auto status = std::move(status_); + func_ = nullptr; // reset to clear this out for sure + status_ = Status(); // reset to clear this out for sure + CatchingCallback(std::move(func), std::move(status)); + g_core_codegen_interface->grpc_call_unref(call_); + } +}; + +/// CallbackWithSuccessTag can be reused multiple times, and will be used in +/// this fashion for streaming operations. As a result, it shouldn't clear +/// anything up until its destructor +class CallbackWithSuccessTag + : public grpc_experimental_completion_queue_functor { + public: + // always allocated against a call arena, no memory free required static void operator delete(void* /*ptr*/, std::size_t size) { GPR_CODEGEN_ASSERT(size == sizeof(CallbackWithSuccessTag)); - } - - // This operator should never be called as the memory should be freed as part - // of the arena destruction. It only exists to provide a matching operator - // delete to the operator new so that some compilers will not complain (see - // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this - // there are no tests catching the compiler warning. + } + + // This operator should never be called as the memory should be freed as part + // of the arena destruction. It only exists to provide a matching operator + // delete to the operator new so that some compilers will not complain (see + // https://github.com/grpc/grpc/issues/11301) Note at the time of adding this + // there are no tests catching the compiler warning. static void operator delete(void*, void*) { GPR_CODEGEN_ASSERT(false); } - - CallbackWithSuccessTag() : call_(nullptr) {} - - CallbackWithSuccessTag(const CallbackWithSuccessTag&) = delete; - CallbackWithSuccessTag& operator=(const CallbackWithSuccessTag&) = delete; - - ~CallbackWithSuccessTag() { Clear(); } - - // Set can only be called on a default-constructed or Clear'ed tag. - // It should never be called on a tag that was constructed with arguments - // or on a tag that has been Set before unless the tag has been cleared. + + CallbackWithSuccessTag() : call_(nullptr) {} + + CallbackWithSuccessTag(const CallbackWithSuccessTag&) = delete; + CallbackWithSuccessTag& operator=(const CallbackWithSuccessTag&) = delete; + + ~CallbackWithSuccessTag() { Clear(); } + + // Set can only be called on a default-constructed or Clear'ed tag. + // It should never be called on a tag that was constructed with arguments + // or on a tag that has been Set before unless the tag has been cleared. // can_inline indicates that this particular callback can be executed inline // (without needing a thread hop) and is only used for library-provided server // callbacks. - void Set(grpc_call* call, std::function<void(bool)> f, + void Set(grpc_call* call, std::function<void(bool)> f, CompletionQueueTag* ops, bool can_inline) { - GPR_CODEGEN_ASSERT(call_ == nullptr); - g_core_codegen_interface->grpc_call_ref(call); - call_ = call; - func_ = std::move(f); - ops_ = ops; - functor_run = &CallbackWithSuccessTag::StaticRun; + GPR_CODEGEN_ASSERT(call_ == nullptr); + g_core_codegen_interface->grpc_call_ref(call); + call_ = call; + func_ = std::move(f); + ops_ = ops; + functor_run = &CallbackWithSuccessTag::StaticRun; inlineable = can_inline; - } - - void Clear() { - if (call_ != nullptr) { - grpc_call* call = call_; - call_ = nullptr; - func_ = nullptr; - g_core_codegen_interface->grpc_call_unref(call); - } - } - - CompletionQueueTag* ops() { return ops_; } - - // force_run can not be performed on a tag if operations using this tag - // have been sent to PerformOpsOnCall. It is intended for error conditions - // that are detected before the operations are internally processed. - void force_run(bool ok) { Run(ok); } - - /// check if this tag is currently set - operator bool() const { return call_ != nullptr; } - - private: - grpc_call* call_; - std::function<void(bool)> func_; - CompletionQueueTag* ops_; - - static void StaticRun(grpc_experimental_completion_queue_functor* cb, - int ok) { - static_cast<CallbackWithSuccessTag*>(cb)->Run(static_cast<bool>(ok)); - } - void Run(bool ok) { - void* ignored = ops_; - // Allow a "false" return value from FinalizeResult to silence the - // callback, just as it silences a CQ tag in the async cases + } + + void Clear() { + if (call_ != nullptr) { + grpc_call* call = call_; + call_ = nullptr; + func_ = nullptr; + g_core_codegen_interface->grpc_call_unref(call); + } + } + + CompletionQueueTag* ops() { return ops_; } + + // force_run can not be performed on a tag if operations using this tag + // have been sent to PerformOpsOnCall. It is intended for error conditions + // that are detected before the operations are internally processed. + void force_run(bool ok) { Run(ok); } + + /// check if this tag is currently set + operator bool() const { return call_ != nullptr; } + + private: + grpc_call* call_; + std::function<void(bool)> func_; + CompletionQueueTag* ops_; + + static void StaticRun(grpc_experimental_completion_queue_functor* cb, + int ok) { + static_cast<CallbackWithSuccessTag*>(cb)->Run(static_cast<bool>(ok)); + } + void Run(bool ok) { + void* ignored = ops_; + // Allow a "false" return value from FinalizeResult to silence the + // callback, just as it silences a CQ tag in the async cases #ifndef NDEBUG - auto* ops = ops_; + auto* ops = ops_; #endif - bool do_callback = ops_->FinalizeResult(&ignored, &ok); + bool do_callback = ops_->FinalizeResult(&ignored, &ok); GPR_CODEGEN_DEBUG_ASSERT(ignored == ops); - - if (do_callback) { - CatchingCallback(func_, ok); - } - } -}; - -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H + + if (do_callback) { + CatchingCallback(func_, ok); + } + } +}; + +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_CALLBACK_COMMON_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h index ea0752d90e..da3b6726d3 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/channel_interface.h @@ -16,15 +16,15 @@ * */ -#if defined(__GNUC__) -#pragma GCC system_header -#endif - +#if defined(__GNUC__) +#pragma GCC system_header +#endif + #ifndef GRPCPP_IMPL_CODEGEN_CHANNEL_INTERFACE_H #define GRPCPP_IMPL_CODEGEN_CHANNEL_INTERFACE_H #include <grpc/impl/codegen/connectivity_state.h> -#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/call.h> #include <grpcpp/impl/codegen/status.h> #include <grpcpp/impl/codegen/time.h> @@ -37,7 +37,7 @@ template <class W, class R> class ClientReaderWriter; namespace internal { template <class InputMessage, class OutputMessage> -class CallbackUnaryCallImpl; +class CallbackUnaryCallImpl; template <class R> class ClientAsyncReaderFactory; template <class W> @@ -46,12 +46,12 @@ template <class W, class R> class ClientAsyncReaderWriterFactory; template <class R> class ClientAsyncResponseReaderFactory; -template <class W, class R> -class ClientCallbackReaderWriterFactory; -template <class R> -class ClientCallbackReaderFactory; -template <class W> -class ClientCallbackWriterFactory; +template <class W, class R> +class ClientCallbackReaderWriterFactory; +template <class R> +class ClientCallbackReaderFactory; +template <class W> +class ClientCallbackWriterFactory; class ClientCallbackUnaryFactory; } // namespace internal @@ -67,7 +67,7 @@ namespace internal { class Call; class CallOpSetInterface; class RpcMethod; -class InterceptedChannel; +class InterceptedChannel; template <class InputMessage, class OutputMessage> class BlockingUnaryCallImpl; } // namespace internal @@ -122,20 +122,20 @@ class ChannelInterface { friend class ::grpc::internal::ClientAsyncReaderWriterFactory; template <class R> friend class ::grpc::internal::ClientAsyncResponseReaderFactory; - template <class W, class R> + template <class W, class R> friend class ::grpc::internal::ClientCallbackReaderWriterFactory; - template <class R> + template <class R> friend class ::grpc::internal::ClientCallbackReaderFactory; - template <class W> + template <class W> friend class ::grpc::internal::ClientCallbackWriterFactory; friend class ::grpc::internal::ClientCallbackUnaryFactory; template <class InputMessage, class OutputMessage> friend class ::grpc::internal::BlockingUnaryCallImpl; - template <class InputMessage, class OutputMessage> + template <class InputMessage, class OutputMessage> friend class ::grpc::internal::CallbackUnaryCallImpl; friend class ::grpc::internal::RpcMethod; friend class ::grpc::experimental::DelegatingChannel; - friend class ::grpc::internal::InterceptedChannel; + friend class ::grpc::internal::InterceptedChannel; virtual internal::Call CreateCall(const internal::RpcMethod& method, ::grpc::ClientContext* context, ::grpc::CompletionQueue* cq) = 0; @@ -148,28 +148,28 @@ class ChannelInterface { void* tag) = 0; virtual bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, gpr_timespec deadline) = 0; - - // EXPERIMENTAL - // This is needed to keep codegen_test_minimal happy. InterceptedChannel needs - // to make use of this but can't directly call Channel's implementation - // because of the test. - // Returns an empty Call object (rather than being pure) since this is a new - // method and adding a new pure method to an interface would be a breaking - // change (even though this is private and non-API) + + // EXPERIMENTAL + // This is needed to keep codegen_test_minimal happy. InterceptedChannel needs + // to make use of this but can't directly call Channel's implementation + // because of the test. + // Returns an empty Call object (rather than being pure) since this is a new + // method and adding a new pure method to an interface would be a breaking + // change (even though this is private and non-API) virtual internal::Call CreateCallInternal( const internal::RpcMethod& /*method*/, ::grpc::ClientContext* /*context*/, ::grpc::CompletionQueue* /*cq*/, size_t /*interceptor_pos*/) { - return internal::Call(); - } - - // EXPERIMENTAL - // A method to get the callbackable completion queue associated with this - // channel. If the return value is nullptr, this channel doesn't support - // callback operations. - // TODO(vjpai): Consider a better default like using a global CQ - // Returns nullptr (rather than being pure) since this is a post-1.0 method - // and adding a new pure method to an interface would be a breaking change - // (even though this is private and non-API) + return internal::Call(); + } + + // EXPERIMENTAL + // A method to get the callbackable completion queue associated with this + // channel. If the return value is nullptr, this channel doesn't support + // callback operations. + // TODO(vjpai): Consider a better default like using a global CQ + // Returns nullptr (rather than being pure) since this is a post-1.0 method + // and adding a new pure method to an interface would be a breaking change + // (even though this is private and non-API) virtual ::grpc::CompletionQueue* CallbackCQ() { return nullptr; } }; } // namespace grpc diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_callback.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_callback.h index 90c817ceaa..560edf491d 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_callback.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_callback.h @@ -1,25 +1,25 @@ -/* - * +/* + * * Copyright 2019 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 GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H -#define GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H + * + * 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 GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H +#define GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H #include <atomic> #include <functional> - + #include <grpcpp/impl/codegen/call.h> #include <grpcpp/impl/codegen/call_op_set.h> #include <grpcpp/impl/codegen/callback_common.h> @@ -27,8 +27,8 @@ #include <grpcpp/impl/codegen/config.h> #include <grpcpp/impl/codegen/core_codegen_interface.h> #include <grpcpp/impl/codegen/status.h> - -namespace grpc { + +namespace grpc { class Channel; class ClientContext; @@ -1190,30 +1190,30 @@ class ClientCallbackUnaryFactory { } // namespace internal // TODO(vjpai): Remove namespace experimental when de-experimentalized fully. -namespace experimental { - -template <class Response> +namespace experimental { + +template <class Response> using ClientCallbackReader = ::grpc::ClientCallbackReader<Response>; -template <class Request> +template <class Request> using ClientCallbackWriter = ::grpc::ClientCallbackWriter<Request>; - -template <class Request, class Response> + +template <class Request, class Response> using ClientCallbackReaderWriter = ::grpc::ClientCallbackReaderWriter<Request, Response>; - -template <class Response> + +template <class Response> using ClientReadReactor = ::grpc::ClientReadReactor<Response>; - -template <class Request> + +template <class Request> using ClientWriteReactor = ::grpc::ClientWriteReactor<Request>; - -template <class Request, class Response> + +template <class Request, class Response> using ClientBidiReactor = ::grpc::ClientBidiReactor<Request, Response>; - + typedef ::grpc::ClientUnaryReactor ClientUnaryReactor; -} // namespace experimental +} // namespace experimental -} // namespace grpc -#endif // GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H +} // namespace grpc +#endif // GRPCPP_IMPL_CODEGEN_CLIENT_CALLBACK_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h index 78be1f7597..3d59da196b 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_interceptor.h @@ -1,190 +1,190 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H -#define GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H - -#include <memory> -#include <vector> - -#include <grpcpp/impl/codegen/interceptor.h> -#include <grpcpp/impl/codegen/rpc_method.h> -#include <grpcpp/impl/codegen/string_ref.h> - +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H +#define GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H + +#include <memory> +#include <vector> + +#include <grpcpp/impl/codegen/interceptor.h> +#include <grpcpp/impl/codegen/rpc_method.h> +#include <grpcpp/impl/codegen/string_ref.h> + namespace grpc { - + class Channel; -class ClientContext; - -namespace internal { -class InterceptorBatchMethodsImpl; -} - -namespace experimental { -class ClientRpcInfo; - -// A factory interface for creation of client interceptors. A vector of -// factories can be provided at channel creation which will be used to create a -// new vector of client interceptors per RPC. Client interceptor authors should -// create a subclass of ClientInterceptorFactorInterface which creates objects -// of their interceptors. -class ClientInterceptorFactoryInterface { - public: - virtual ~ClientInterceptorFactoryInterface() {} - // Returns a pointer to an Interceptor object on successful creation, nullptr - // otherwise. If nullptr is returned, this server interceptor factory is - // ignored for the purposes of that RPC. - virtual Interceptor* CreateClientInterceptor(ClientRpcInfo* info) = 0; -}; -} // namespace experimental - -namespace internal { -extern experimental::ClientInterceptorFactoryInterface* - g_global_client_interceptor_factory; -} - -/// ClientRpcInfo represents the state of a particular RPC as it -/// appears to an interceptor. It is created and owned by the library and -/// passed to the CreateClientInterceptor method of the application's -/// ClientInterceptorFactoryInterface implementation -namespace experimental { -class ClientRpcInfo { - public: - // TODO(yashykt): Stop default-constructing ClientRpcInfo and remove UNKNOWN - // from the list of possible Types. - /// Type categorizes RPCs by unary or streaming type - enum class Type { - UNARY, - CLIENT_STREAMING, - SERVER_STREAMING, - BIDI_STREAMING, - UNKNOWN // UNKNOWN is not API and will be removed later - }; - +class ClientContext; + +namespace internal { +class InterceptorBatchMethodsImpl; +} + +namespace experimental { +class ClientRpcInfo; + +// A factory interface for creation of client interceptors. A vector of +// factories can be provided at channel creation which will be used to create a +// new vector of client interceptors per RPC. Client interceptor authors should +// create a subclass of ClientInterceptorFactorInterface which creates objects +// of their interceptors. +class ClientInterceptorFactoryInterface { + public: + virtual ~ClientInterceptorFactoryInterface() {} + // Returns a pointer to an Interceptor object on successful creation, nullptr + // otherwise. If nullptr is returned, this server interceptor factory is + // ignored for the purposes of that RPC. + virtual Interceptor* CreateClientInterceptor(ClientRpcInfo* info) = 0; +}; +} // namespace experimental + +namespace internal { +extern experimental::ClientInterceptorFactoryInterface* + g_global_client_interceptor_factory; +} + +/// ClientRpcInfo represents the state of a particular RPC as it +/// appears to an interceptor. It is created and owned by the library and +/// passed to the CreateClientInterceptor method of the application's +/// ClientInterceptorFactoryInterface implementation +namespace experimental { +class ClientRpcInfo { + public: + // TODO(yashykt): Stop default-constructing ClientRpcInfo and remove UNKNOWN + // from the list of possible Types. + /// Type categorizes RPCs by unary or streaming type + enum class Type { + UNARY, + CLIENT_STREAMING, + SERVER_STREAMING, + BIDI_STREAMING, + UNKNOWN // UNKNOWN is not API and will be removed later + }; + ~ClientRpcInfo() {} - - // Delete copy constructor but allow default move constructor - ClientRpcInfo(const ClientRpcInfo&) = delete; - ClientRpcInfo(ClientRpcInfo&&) = default; - - // Getter methods - - /// Return the fully-specified method name - const char* method() const { return method_; } - - /// Return a pointer to the channel on which the RPC is being sent - ChannelInterface* channel() { return channel_; } - - /// Return a pointer to the underlying ClientContext structure associated - /// with the RPC to support features that apply to it + + // Delete copy constructor but allow default move constructor + ClientRpcInfo(const ClientRpcInfo&) = delete; + ClientRpcInfo(ClientRpcInfo&&) = default; + + // Getter methods + + /// Return the fully-specified method name + const char* method() const { return method_; } + + /// Return a pointer to the channel on which the RPC is being sent + ChannelInterface* channel() { return channel_; } + + /// Return a pointer to the underlying ClientContext structure associated + /// with the RPC to support features that apply to it grpc::ClientContext* client_context() { return ctx_; } - - /// Return the type of the RPC (unary or a streaming flavor) - Type type() const { return type_; } - - private: - static_assert(Type::UNARY == - static_cast<Type>(internal::RpcMethod::NORMAL_RPC), - "violated expectation about Type enum"); - static_assert(Type::CLIENT_STREAMING == - static_cast<Type>(internal::RpcMethod::CLIENT_STREAMING), - "violated expectation about Type enum"); - static_assert(Type::SERVER_STREAMING == - static_cast<Type>(internal::RpcMethod::SERVER_STREAMING), - "violated expectation about Type enum"); - static_assert(Type::BIDI_STREAMING == - static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), - "violated expectation about Type enum"); - - // Default constructor should only be used by ClientContext - ClientRpcInfo() = default; - - // Constructor will only be called from ClientContext + + /// Return the type of the RPC (unary or a streaming flavor) + Type type() const { return type_; } + + private: + static_assert(Type::UNARY == + static_cast<Type>(internal::RpcMethod::NORMAL_RPC), + "violated expectation about Type enum"); + static_assert(Type::CLIENT_STREAMING == + static_cast<Type>(internal::RpcMethod::CLIENT_STREAMING), + "violated expectation about Type enum"); + static_assert(Type::SERVER_STREAMING == + static_cast<Type>(internal::RpcMethod::SERVER_STREAMING), + "violated expectation about Type enum"); + static_assert(Type::BIDI_STREAMING == + static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), + "violated expectation about Type enum"); + + // Default constructor should only be used by ClientContext + ClientRpcInfo() = default; + + // Constructor will only be called from ClientContext ClientRpcInfo(grpc::ClientContext* ctx, internal::RpcMethod::RpcType type, const char* method, grpc::ChannelInterface* channel) - : ctx_(ctx), - type_(static_cast<Type>(type)), - method_(method), - channel_(channel) {} - - // Move assignment should only be used by ClientContext - // TODO(yashykt): Delete move assignment - ClientRpcInfo& operator=(ClientRpcInfo&&) = default; - - // Runs interceptor at pos \a pos. - void RunInterceptor( - experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { - GPR_CODEGEN_ASSERT(pos < interceptors_.size()); - interceptors_[pos]->Intercept(interceptor_methods); - } - - void RegisterInterceptors( - const std::vector<std::unique_ptr< - experimental::ClientInterceptorFactoryInterface>>& creators, - size_t interceptor_pos) { - if (interceptor_pos > creators.size()) { - // No interceptors to register - return; - } + : ctx_(ctx), + type_(static_cast<Type>(type)), + method_(method), + channel_(channel) {} + + // Move assignment should only be used by ClientContext + // TODO(yashykt): Delete move assignment + ClientRpcInfo& operator=(ClientRpcInfo&&) = default; + + // Runs interceptor at pos \a pos. + void RunInterceptor( + experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { + GPR_CODEGEN_ASSERT(pos < interceptors_.size()); + interceptors_[pos]->Intercept(interceptor_methods); + } + + void RegisterInterceptors( + const std::vector<std::unique_ptr< + experimental::ClientInterceptorFactoryInterface>>& creators, + size_t interceptor_pos) { + if (interceptor_pos > creators.size()) { + // No interceptors to register + return; + } // NOTE: The following is not a range-based for loop because it will only // iterate over a portion of the creators vector. - for (auto it = creators.begin() + interceptor_pos; it != creators.end(); - ++it) { - auto* interceptor = (*it)->CreateClientInterceptor(this); - if (interceptor != nullptr) { - interceptors_.push_back( - std::unique_ptr<experimental::Interceptor>(interceptor)); - } - } - if (internal::g_global_client_interceptor_factory != nullptr) { - interceptors_.push_back(std::unique_ptr<experimental::Interceptor>( - internal::g_global_client_interceptor_factory - ->CreateClientInterceptor(this))); - } - } - + for (auto it = creators.begin() + interceptor_pos; it != creators.end(); + ++it) { + auto* interceptor = (*it)->CreateClientInterceptor(this); + if (interceptor != nullptr) { + interceptors_.push_back( + std::unique_ptr<experimental::Interceptor>(interceptor)); + } + } + if (internal::g_global_client_interceptor_factory != nullptr) { + interceptors_.push_back(std::unique_ptr<experimental::Interceptor>( + internal::g_global_client_interceptor_factory + ->CreateClientInterceptor(this))); + } + } + grpc::ClientContext* ctx_ = nullptr; - // TODO(yashykt): make type_ const once move-assignment is deleted - Type type_{Type::UNKNOWN}; - const char* method_ = nullptr; - grpc::ChannelInterface* channel_ = nullptr; - std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; - bool hijacked_ = false; - size_t hijacked_interceptor_ = 0; - - friend class internal::InterceptorBatchMethodsImpl; + // TODO(yashykt): make type_ const once move-assignment is deleted + Type type_{Type::UNKNOWN}; + const char* method_ = nullptr; + grpc::ChannelInterface* channel_ = nullptr; + std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; + bool hijacked_ = false; + size_t hijacked_interceptor_ = 0; + + friend class internal::InterceptorBatchMethodsImpl; friend class grpc::ClientContext; -}; - -// PLEASE DO NOT USE THIS. ALWAYS PREFER PER CHANNEL INTERCEPTORS OVER A GLOBAL -// INTERCEPTOR. IF USAGE IS ABSOLUTELY NECESSARY, PLEASE READ THE SAFETY NOTES. -// Registers a global client interceptor factory object, which is used for all +}; + +// PLEASE DO NOT USE THIS. ALWAYS PREFER PER CHANNEL INTERCEPTORS OVER A GLOBAL +// INTERCEPTOR. IF USAGE IS ABSOLUTELY NECESSARY, PLEASE READ THE SAFETY NOTES. +// Registers a global client interceptor factory object, which is used for all // RPCs made in this process. The application is responsible for maintaining the // life of the object while gRPC operations are in progress. The global // interceptor factory should only be registered once at the start of the // process before any gRPC operations have begun. -void RegisterGlobalClientInterceptorFactory( - ClientInterceptorFactoryInterface* factory); - +void RegisterGlobalClientInterceptorFactory( + ClientInterceptorFactoryInterface* factory); + // For testing purposes only void TestOnlyResetGlobalClientInterceptorFactory(); -} // namespace experimental -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_CLIENT_INTERCEPTOR_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_unary_call.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_unary_call.h index 098bb50ee2..2c13cedf64 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/client_unary_call.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/client_unary_call.h @@ -47,18 +47,18 @@ class BlockingUnaryCallImpl { grpc::ClientContext* context, const InputMessage& request, OutputMessage* result) { ::grpc::CompletionQueue cq(grpc_completion_queue_attributes{ - GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING, - nullptr}); // Pluckable completion queue + GRPC_CQ_CURRENT_VERSION, GRPC_CQ_PLUCK, GRPC_CQ_DEFAULT_POLLING, + nullptr}); // Pluckable completion queue ::grpc::internal::Call call(channel->CreateCall(method, context, &cq)); CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage, CallOpRecvInitialMetadata, CallOpRecvMessage<OutputMessage>, CallOpClientSendClose, CallOpClientRecvStatus> ops; - status_ = ops.SendMessagePtr(&request); + status_ = ops.SendMessagePtr(&request); if (!status_.ok()) { return; } - ops.SendInitialMetadata(&context->send_initial_metadata_, + ops.SendInitialMetadata(&context->send_initial_metadata_, context->initial_metadata_flags()); ops.RecvInitialMetadata(context); ops.RecvMessage(result); @@ -66,17 +66,17 @@ class BlockingUnaryCallImpl { ops.ClientSendClose(); ops.ClientRecvStatus(context, &status_); call.PerformOps(&ops); - cq.Pluck(&ops); - // Some of the ops might fail. If the ops fail in the core layer, status - // would reflect the error. But, if the ops fail in the C++ layer, the - // status would still be the same as the one returned by gRPC Core. This can - // happen if deserialization of the message fails. - // TODO(yashykt): If deserialization fails, but the status received is OK, - // then it might be a good idea to change the status to something better - // than StatusCode::UNIMPLEMENTED to reflect this. - if (!ops.got_message && status_.ok()) { - status_ = Status(StatusCode::UNIMPLEMENTED, - "No message returned for unary request"); + cq.Pluck(&ops); + // Some of the ops might fail. If the ops fail in the core layer, status + // would reflect the error. But, if the ops fail in the C++ layer, the + // status would still be the same as the one returned by gRPC Core. This can + // happen if deserialization of the message fails. + // TODO(yashykt): If deserialization fails, but the status received is OK, + // then it might be a good idea to change the status to something better + // than StatusCode::UNIMPLEMENTED to reflect this. + if (!ops.got_message && status_.ok()) { + status_ = Status(StatusCode::UNIMPLEMENTED, + "No message returned for unary request"); } } Status status() { return status_; } diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/completion_queue_tag.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/completion_queue_tag.h index 304386a9ec..b97dde069c 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/completion_queue_tag.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/completion_queue_tag.h @@ -26,25 +26,25 @@ namespace internal { class CompletionQueueTag { public: virtual ~CompletionQueueTag() {} - - /// FinalizeResult must be called before informing user code that the - /// operation bound to the underlying core completion queue tag has - /// completed. In practice, this means: - /// - /// 1. For the sync API - before returning from Pluck - /// 2. For the CQ-based async API - before returning from Next - /// 3. For the callback-based API - before invoking the user callback - /// - /// This is the method that translates from core-side tag/status to - /// C++ API-observable tag/status. - /// - /// The return value is the status of the operation (returning status is the - /// general behavior of this function). If this function returns false, the - /// tag is dropped and not returned from the completion queue: this concept is - /// for events that are observed at core but not requested by the user - /// application (e.g., server shutdown, for server unimplemented method - /// responses, or for cases where a server-side RPC doesn't have a completion - /// notification registered using AsyncNotifyWhenDone) + + /// FinalizeResult must be called before informing user code that the + /// operation bound to the underlying core completion queue tag has + /// completed. In practice, this means: + /// + /// 1. For the sync API - before returning from Pluck + /// 2. For the CQ-based async API - before returning from Next + /// 3. For the callback-based API - before invoking the user callback + /// + /// This is the method that translates from core-side tag/status to + /// C++ API-observable tag/status. + /// + /// The return value is the status of the operation (returning status is the + /// general behavior of this function). If this function returns false, the + /// tag is dropped and not returned from the completion queue: this concept is + /// for events that are observed at core but not requested by the user + /// application (e.g., server shutdown, for server unimplemented method + /// responses, or for cases where a server-side RPC doesn't have a completion + /// notification registered using AsyncNotifyWhenDone) virtual bool FinalizeResult(void** tag, bool* status) = 0; }; } // namespace internal diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/config_protobuf.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/config_protobuf.h index c4012fb00c..cb3088f985 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/config_protobuf.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/config_protobuf.h @@ -63,12 +63,12 @@ #define GRPC_CUSTOM_CODEDINPUTSTREAM ::google::protobuf::io::CodedInputStream #endif -#ifndef GRPC_CUSTOM_JSONUTIL +#ifndef GRPC_CUSTOM_JSONUTIL #include <google/protobuf/util/json_util.h> -#define GRPC_CUSTOM_JSONUTIL ::google::protobuf::util -#define GRPC_CUSTOM_UTIL_STATUS ::google::protobuf::util::Status -#endif - +#define GRPC_CUSTOM_JSONUTIL ::google::protobuf::util +#define GRPC_CUSTOM_UTIL_STATUS ::google::protobuf::util::Status +#endif + namespace grpc { namespace protobuf { @@ -86,12 +86,12 @@ typedef GRPC_CUSTOM_SERVICEDESCRIPTOR ServiceDescriptor; typedef GRPC_CUSTOM_SIMPLEDESCRIPTORDATABASE SimpleDescriptorDatabase; typedef GRPC_CUSTOM_SOURCELOCATION SourceLocation; -namespace util { -typedef GRPC_CUSTOM_UTIL_STATUS Status; -} // namespace util - -namespace json = GRPC_CUSTOM_JSONUTIL; - +namespace util { +typedef GRPC_CUSTOM_UTIL_STATUS Status; +} // namespace util + +namespace json = GRPC_CUSTOM_JSONUTIL; + namespace io { typedef GRPC_CUSTOM_ZEROCOPYOUTPUTSTREAM ZeroCopyOutputStream; typedef GRPC_CUSTOM_ZEROCOPYINPUTSTREAM ZeroCopyInputStream; diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h index 50c8da4ffe..f050930be7 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen.h @@ -42,7 +42,7 @@ class CoreCodegen final : public CoreCodegenInterface { void* reserved) override; grpc_completion_queue* grpc_completion_queue_create_for_pluck( void* reserved) override; - void grpc_completion_queue_shutdown(grpc_completion_queue* cq) override; + void grpc_completion_queue_shutdown(grpc_completion_queue* cq) override; void grpc_completion_queue_destroy(grpc_completion_queue* cq) override; grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, @@ -64,9 +64,9 @@ class CoreCodegen final : public CoreCodegenInterface { void gpr_cv_signal(gpr_cv* cv) override; void gpr_cv_broadcast(gpr_cv* cv) override; - grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, - size_t nops, void* tag, - void* reserved) override; + grpc_call_error grpc_call_start_batch(grpc_call* call, const grpc_op* ops, + size_t nops, void* tag, + void* reserved) override; grpc_call_error grpc_call_cancel_with_status(grpc_call* call, grpc_status_code status, const char* description, diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen_interface.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen_interface.h index c08cf6c683..837948a583 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/core_codegen_interface.h @@ -53,7 +53,7 @@ class CoreCodegenInterface { void* reserved) = 0; virtual grpc_completion_queue* grpc_completion_queue_create_for_pluck( void* reserved) = 0; - virtual void grpc_completion_queue_shutdown(grpc_completion_queue* cq) = 0; + virtual void grpc_completion_queue_shutdown(grpc_completion_queue* cq) = 0; virtual void grpc_completion_queue_destroy(grpc_completion_queue* cq) = 0; virtual grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, @@ -104,9 +104,9 @@ class CoreCodegenInterface { virtual grpc_slice grpc_slice_new_with_len(void* p, size_t len, void (*destroy)(void*, size_t)) = 0; - virtual grpc_call_error grpc_call_start_batch(grpc_call* call, - const grpc_op* ops, size_t nops, - void* tag, void* reserved) = 0; + virtual grpc_call_error grpc_call_start_batch(grpc_call* call, + const grpc_op* ops, size_t nops, + void* tag, void* reserved) = 0; virtual grpc_call_error grpc_call_cancel_with_status(grpc_call* call, grpc_status_code status, const char* description, @@ -150,15 +150,15 @@ extern CoreCodegenInterface* g_core_codegen_interface; } \ } while (0) -/// Codegen specific version of \a GPR_DEBUG_ASSERT. -#ifndef NDEBUG -#define GPR_CODEGEN_DEBUG_ASSERT(x) GPR_CODEGEN_ASSERT(x) -#else -#define GPR_CODEGEN_DEBUG_ASSERT(x) \ - do { \ - } while (0) -#endif - +/// Codegen specific version of \a GPR_DEBUG_ASSERT. +#ifndef NDEBUG +#define GPR_CODEGEN_DEBUG_ASSERT(x) GPR_CODEGEN_ASSERT(x) +#else +#define GPR_CODEGEN_DEBUG_ASSERT(x) \ + do { \ + } while (0) +#endif + } // namespace grpc #endif // GRPCPP_IMPL_CODEGEN_CORE_CODEGEN_INTERFACE_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/intercepted_channel.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/intercepted_channel.h index c729970ca8..d3472737ba 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/intercepted_channel.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/intercepted_channel.h @@ -1,84 +1,84 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H -#define GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H - -#include <grpcpp/impl/codegen/channel_interface.h> - +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H +#define GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H + +#include <grpcpp/impl/codegen/channel_interface.h> + namespace grpc { class CompletionQueue; -namespace internal { - -class InterceptorBatchMethodsImpl; - -/// An InterceptedChannel is available to client Interceptors. An -/// InterceptedChannel is unique to an interceptor, and when an RPC is started -/// on this channel, only those interceptors that come after this interceptor -/// see the RPC. -class InterceptedChannel : public ChannelInterface { - public: - virtual ~InterceptedChannel() { channel_ = nullptr; } - - /// Get the current channel state. If the channel is in IDLE and - /// \a try_to_connect is set to true, try to connect. - grpc_connectivity_state GetState(bool try_to_connect) override { - return channel_->GetState(try_to_connect); - } - - private: - InterceptedChannel(ChannelInterface* channel, size_t pos) - : channel_(channel), interceptor_pos_(pos) {} - +namespace internal { + +class InterceptorBatchMethodsImpl; + +/// An InterceptedChannel is available to client Interceptors. An +/// InterceptedChannel is unique to an interceptor, and when an RPC is started +/// on this channel, only those interceptors that come after this interceptor +/// see the RPC. +class InterceptedChannel : public ChannelInterface { + public: + virtual ~InterceptedChannel() { channel_ = nullptr; } + + /// Get the current channel state. If the channel is in IDLE and + /// \a try_to_connect is set to true, try to connect. + grpc_connectivity_state GetState(bool try_to_connect) override { + return channel_->GetState(try_to_connect); + } + + private: + InterceptedChannel(ChannelInterface* channel, size_t pos) + : channel_(channel), interceptor_pos_(pos) {} + Call CreateCall(const RpcMethod& method, ::grpc::ClientContext* context, ::grpc::CompletionQueue* cq) override { - return channel_->CreateCallInternal(method, context, cq, interceptor_pos_); - } - - void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override { - return channel_->PerformOpsOnCall(ops, call); - } - void* RegisterMethod(const char* method) override { - return channel_->RegisterMethod(method); - } - - void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, + return channel_->CreateCallInternal(method, context, cq, interceptor_pos_); + } + + void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) override { + return channel_->PerformOpsOnCall(ops, call); + } + void* RegisterMethod(const char* method) override { + return channel_->RegisterMethod(method); + } + + void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed, gpr_timespec deadline, ::grpc::CompletionQueue* cq, - void* tag) override { - return channel_->NotifyOnStateChangeImpl(last_observed, deadline, cq, tag); - } - bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, - gpr_timespec deadline) override { - return channel_->WaitForStateChangeImpl(last_observed, deadline); - } - + void* tag) override { + return channel_->NotifyOnStateChangeImpl(last_observed, deadline, cq, tag); + } + bool WaitForStateChangeImpl(grpc_connectivity_state last_observed, + gpr_timespec deadline) override { + return channel_->WaitForStateChangeImpl(last_observed, deadline); + } + ::grpc::CompletionQueue* CallbackCQ() override { return channel_->CallbackCQ(); } - - ChannelInterface* channel_; - size_t interceptor_pos_; - - friend class InterceptorBatchMethodsImpl; -}; -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H + + ChannelInterface* channel_; + size_t interceptor_pos_; + + friend class InterceptorBatchMethodsImpl; +}; +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTED_CHANNEL_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h index d0afa03a17..5c9cb78db5 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor.h @@ -1,228 +1,228 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H -#define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H - +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H +#define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H + #include <memory> -#include <grpc/impl/codegen/grpc_types.h> -#include <grpcpp/impl/codegen/byte_buffer.h> -#include <grpcpp/impl/codegen/config.h> -#include <grpcpp/impl/codegen/core_codegen_interface.h> -#include <grpcpp/impl/codegen/metadata_map.h> - -namespace grpc { - -class ChannelInterface; -class Status; - -namespace experimental { - -/// An enumeration of different possible points at which the \a Intercept -/// method of the \a Interceptor interface may be called. Any given call -/// to \a Intercept will include one or more of these hook points, and -/// each hook point makes certain types of information available to the -/// interceptor. -/// In these enumeration names, PRE_SEND means that an interception has taken -/// place between the time the application provided a certain type of data -/// (e.g., initial metadata, status) and the time that that data goes to the -/// other side. POST_SEND means that the data has been committed for going to -/// the other side (even if it has not yet been received at the other side). -/// PRE_RECV means an interception between the time that a certain -/// operation has been requested and it is available. POST_RECV means that a -/// result is available but has not yet been passed back to the application. -/// A batch of interception points will only contain either PRE or POST hooks -/// but not both types. For example, a batch with PRE_SEND hook points will not -/// contain POST_RECV or POST_SEND ops. Likewise, a batch with POST_* ops can -/// not contain PRE_* ops. -enum class InterceptionHookPoints { - /// The first three in this list are for clients and servers - PRE_SEND_INITIAL_METADATA, - PRE_SEND_MESSAGE, - POST_SEND_MESSAGE, - PRE_SEND_STATUS, // server only - PRE_SEND_CLOSE, // client only: WritesDone for stream; after write in unary - /// The following three are for hijacked clients only. A batch with PRE_RECV_* - /// hook points will never contain hook points of other types. - PRE_RECV_INITIAL_METADATA, - PRE_RECV_MESSAGE, - PRE_RECV_STATUS, - /// The following two are for all clients and servers - POST_RECV_INITIAL_METADATA, - POST_RECV_MESSAGE, - POST_RECV_STATUS, // client only - POST_RECV_CLOSE, // server only - /// This is a special hook point available to both clients and servers when - /// TryCancel() is performed. - /// - No other hook points will be present along with this. - /// - It is illegal for an interceptor to block/delay this operation. - /// - ALL interceptors see this hook point irrespective of whether the - /// RPC was hijacked or not. - PRE_SEND_CANCEL, - NUM_INTERCEPTION_HOOKS -}; - -/// Class that is passed as an argument to the \a Intercept method -/// of the application's \a Interceptor interface implementation. It has five -/// purposes: -/// 1. Indicate which hook points are present at a specific interception -/// 2. Allow an interceptor to inform the library that an RPC should -/// continue to the next stage of its processing (which may be another -/// interceptor or the main path of the library) -/// 3. Allow an interceptor to hijack the processing of the RPC (only for -/// client-side RPCs with PRE_SEND_INITIAL_METADATA) so that it does not -/// proceed with normal processing beyond that stage -/// 4. Access the relevant fields of an RPC at each interception point -/// 5. Set some fields of an RPC at each interception point, when possible -class InterceptorBatchMethods { - public: +#include <grpc/impl/codegen/grpc_types.h> +#include <grpcpp/impl/codegen/byte_buffer.h> +#include <grpcpp/impl/codegen/config.h> +#include <grpcpp/impl/codegen/core_codegen_interface.h> +#include <grpcpp/impl/codegen/metadata_map.h> + +namespace grpc { + +class ChannelInterface; +class Status; + +namespace experimental { + +/// An enumeration of different possible points at which the \a Intercept +/// method of the \a Interceptor interface may be called. Any given call +/// to \a Intercept will include one or more of these hook points, and +/// each hook point makes certain types of information available to the +/// interceptor. +/// In these enumeration names, PRE_SEND means that an interception has taken +/// place between the time the application provided a certain type of data +/// (e.g., initial metadata, status) and the time that that data goes to the +/// other side. POST_SEND means that the data has been committed for going to +/// the other side (even if it has not yet been received at the other side). +/// PRE_RECV means an interception between the time that a certain +/// operation has been requested and it is available. POST_RECV means that a +/// result is available but has not yet been passed back to the application. +/// A batch of interception points will only contain either PRE or POST hooks +/// but not both types. For example, a batch with PRE_SEND hook points will not +/// contain POST_RECV or POST_SEND ops. Likewise, a batch with POST_* ops can +/// not contain PRE_* ops. +enum class InterceptionHookPoints { + /// The first three in this list are for clients and servers + PRE_SEND_INITIAL_METADATA, + PRE_SEND_MESSAGE, + POST_SEND_MESSAGE, + PRE_SEND_STATUS, // server only + PRE_SEND_CLOSE, // client only: WritesDone for stream; after write in unary + /// The following three are for hijacked clients only. A batch with PRE_RECV_* + /// hook points will never contain hook points of other types. + PRE_RECV_INITIAL_METADATA, + PRE_RECV_MESSAGE, + PRE_RECV_STATUS, + /// The following two are for all clients and servers + POST_RECV_INITIAL_METADATA, + POST_RECV_MESSAGE, + POST_RECV_STATUS, // client only + POST_RECV_CLOSE, // server only + /// This is a special hook point available to both clients and servers when + /// TryCancel() is performed. + /// - No other hook points will be present along with this. + /// - It is illegal for an interceptor to block/delay this operation. + /// - ALL interceptors see this hook point irrespective of whether the + /// RPC was hijacked or not. + PRE_SEND_CANCEL, + NUM_INTERCEPTION_HOOKS +}; + +/// Class that is passed as an argument to the \a Intercept method +/// of the application's \a Interceptor interface implementation. It has five +/// purposes: +/// 1. Indicate which hook points are present at a specific interception +/// 2. Allow an interceptor to inform the library that an RPC should +/// continue to the next stage of its processing (which may be another +/// interceptor or the main path of the library) +/// 3. Allow an interceptor to hijack the processing of the RPC (only for +/// client-side RPCs with PRE_SEND_INITIAL_METADATA) so that it does not +/// proceed with normal processing beyond that stage +/// 4. Access the relevant fields of an RPC at each interception point +/// 5. Set some fields of an RPC at each interception point, when possible +class InterceptorBatchMethods { + public: virtual ~InterceptorBatchMethods() {} - /// Determine whether the current batch has an interception hook point - /// of type \a type - virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type) = 0; - /// Signal that the interceptor is done intercepting the current batch of the - /// RPC. Every interceptor must either call Proceed or Hijack on each - /// interception. In most cases, only Proceed will be used. Explicit use of - /// Proceed is what enables interceptors to delay the processing of RPCs - /// while they perform other work. - /// Proceed is a no-op if the batch contains PRE_SEND_CANCEL. Simply returning - /// from the Intercept method does the job of continuing the RPC in this case. - /// This is because PRE_SEND_CANCEL is always in a separate batch and is not - /// allowed to be delayed. - virtual void Proceed() = 0; - /// Indicate that the interceptor has hijacked the RPC (only valid if the - /// batch contains send_initial_metadata on the client side). Later - /// interceptors in the interceptor list will not be called. Later batches - /// on the same RPC will go through interception, but only up to the point - /// of the hijacking interceptor. - virtual void Hijack() = 0; - - /// Send Message Methods - /// GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the - /// available methods to view and modify the request payload. An interceptor - /// can access the payload in either serialized form or non-serialized form - /// but not both at the same time. - /// gRPC performs serialization in a lazy manner, which means - /// that a call to GetSerializedSendMessage will result in a serialization - /// operation if the payload stored is not in the serialized form already; the - /// non-serialized form will be lost and GetSendMessage will no longer return - /// a valid pointer, and this will remain true for later interceptors too. - /// This can change however if ModifySendMessage is used to replace the - /// current payload. Note that ModifySendMessage requires a new payload - /// message in the non-serialized form. This will overwrite the existing - /// payload irrespective of whether it had been serialized earlier. Also note - /// that gRPC Async API requires early serialization of the payload which - /// means that the payload would be available in the serialized form only - /// unless an interceptor replaces the payload with ModifySendMessage. - - /// Returns a modifable ByteBuffer holding the serialized form of the message - /// that is going to be sent. Valid for PRE_SEND_MESSAGE interceptions. - /// A return value of nullptr indicates that this ByteBuffer is not valid. - virtual ByteBuffer* GetSerializedSendMessage() = 0; - - /// Returns a non-modifiable pointer to the non-serialized form of the message - /// to be sent. Valid for PRE_SEND_MESSAGE interceptions. A return value of - /// nullptr indicates that this field is not valid. - virtual const void* GetSendMessage() = 0; - - /// Overwrites the message to be sent with \a message. \a message should be in - /// the non-serialized form expected by the method. Valid for PRE_SEND_MESSAGE - /// interceptions. Note that the interceptor is responsible for maintaining - /// the life of the message till it is serialized or it receives the - /// POST_SEND_MESSAGE interception point, whichever happens earlier. The - /// modifying interceptor may itself force early serialization by calling - /// GetSerializedSendMessage. - virtual void ModifySendMessage(const void* message) = 0; - - /// Checks whether the SEND MESSAGE op succeeded. Valid for POST_SEND_MESSAGE - /// interceptions. - virtual bool GetSendMessageStatus() = 0; - - /// Returns a modifiable multimap of the initial metadata to be sent. Valid - /// for PRE_SEND_INITIAL_METADATA interceptions. A value of nullptr indicates - /// that this field is not valid. + /// Determine whether the current batch has an interception hook point + /// of type \a type + virtual bool QueryInterceptionHookPoint(InterceptionHookPoints type) = 0; + /// Signal that the interceptor is done intercepting the current batch of the + /// RPC. Every interceptor must either call Proceed or Hijack on each + /// interception. In most cases, only Proceed will be used. Explicit use of + /// Proceed is what enables interceptors to delay the processing of RPCs + /// while they perform other work. + /// Proceed is a no-op if the batch contains PRE_SEND_CANCEL. Simply returning + /// from the Intercept method does the job of continuing the RPC in this case. + /// This is because PRE_SEND_CANCEL is always in a separate batch and is not + /// allowed to be delayed. + virtual void Proceed() = 0; + /// Indicate that the interceptor has hijacked the RPC (only valid if the + /// batch contains send_initial_metadata on the client side). Later + /// interceptors in the interceptor list will not be called. Later batches + /// on the same RPC will go through interception, but only up to the point + /// of the hijacking interceptor. + virtual void Hijack() = 0; + + /// Send Message Methods + /// GetSerializedSendMessage and GetSendMessage/ModifySendMessage are the + /// available methods to view and modify the request payload. An interceptor + /// can access the payload in either serialized form or non-serialized form + /// but not both at the same time. + /// gRPC performs serialization in a lazy manner, which means + /// that a call to GetSerializedSendMessage will result in a serialization + /// operation if the payload stored is not in the serialized form already; the + /// non-serialized form will be lost and GetSendMessage will no longer return + /// a valid pointer, and this will remain true for later interceptors too. + /// This can change however if ModifySendMessage is used to replace the + /// current payload. Note that ModifySendMessage requires a new payload + /// message in the non-serialized form. This will overwrite the existing + /// payload irrespective of whether it had been serialized earlier. Also note + /// that gRPC Async API requires early serialization of the payload which + /// means that the payload would be available in the serialized form only + /// unless an interceptor replaces the payload with ModifySendMessage. + + /// Returns a modifable ByteBuffer holding the serialized form of the message + /// that is going to be sent. Valid for PRE_SEND_MESSAGE interceptions. + /// A return value of nullptr indicates that this ByteBuffer is not valid. + virtual ByteBuffer* GetSerializedSendMessage() = 0; + + /// Returns a non-modifiable pointer to the non-serialized form of the message + /// to be sent. Valid for PRE_SEND_MESSAGE interceptions. A return value of + /// nullptr indicates that this field is not valid. + virtual const void* GetSendMessage() = 0; + + /// Overwrites the message to be sent with \a message. \a message should be in + /// the non-serialized form expected by the method. Valid for PRE_SEND_MESSAGE + /// interceptions. Note that the interceptor is responsible for maintaining + /// the life of the message till it is serialized or it receives the + /// POST_SEND_MESSAGE interception point, whichever happens earlier. The + /// modifying interceptor may itself force early serialization by calling + /// GetSerializedSendMessage. + virtual void ModifySendMessage(const void* message) = 0; + + /// Checks whether the SEND MESSAGE op succeeded. Valid for POST_SEND_MESSAGE + /// interceptions. + virtual bool GetSendMessageStatus() = 0; + + /// Returns a modifiable multimap of the initial metadata to be sent. Valid + /// for PRE_SEND_INITIAL_METADATA interceptions. A value of nullptr indicates + /// that this field is not valid. virtual std::multimap<TString, TString>* GetSendInitialMetadata() = 0; - - /// Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions. - virtual Status GetSendStatus() = 0; - - /// Overwrites the status with \a status. Valid for PRE_SEND_STATUS - /// interceptions. - virtual void ModifySendStatus(const Status& status) = 0; - - /// Returns a modifiable multimap of the trailing metadata to be sent. Valid - /// for PRE_SEND_STATUS interceptions. A value of nullptr indicates - /// that this field is not valid. + + /// Returns the status to be sent. Valid for PRE_SEND_STATUS interceptions. + virtual Status GetSendStatus() = 0; + + /// Overwrites the status with \a status. Valid for PRE_SEND_STATUS + /// interceptions. + virtual void ModifySendStatus(const Status& status) = 0; + + /// Returns a modifiable multimap of the trailing metadata to be sent. Valid + /// for PRE_SEND_STATUS interceptions. A value of nullptr indicates + /// that this field is not valid. virtual std::multimap<TString, TString>* - GetSendTrailingMetadata() = 0; - - /// Returns a pointer to the modifiable received message. Note that the - /// message is already deserialized but the type is not set; the interceptor - /// should static_cast to the appropriate type before using it. This is valid + GetSendTrailingMetadata() = 0; + + /// Returns a pointer to the modifiable received message. Note that the + /// message is already deserialized but the type is not set; the interceptor + /// should static_cast to the appropriate type before using it. This is valid /// for PRE_RECV_MESSAGE and POST_RECV_MESSAGE interceptions; nullptr for not /// valid - virtual void* GetRecvMessage() = 0; - - /// Returns a modifiable multimap of the received initial metadata. + virtual void* GetRecvMessage() = 0; + + /// Returns a modifiable multimap of the received initial metadata. /// Valid for PRE_RECV_INITIAL_METADATA and POST_RECV_INITIAL_METADATA /// interceptions; nullptr if not valid - virtual std::multimap<grpc::string_ref, grpc::string_ref>* - GetRecvInitialMetadata() = 0; - + virtual std::multimap<grpc::string_ref, grpc::string_ref>* + GetRecvInitialMetadata() = 0; + /// Returns a modifiable view of the received status on PRE_RECV_STATUS and /// POST_RECV_STATUS interceptions; nullptr if not valid. - virtual Status* GetRecvStatus() = 0; - - /// Returns a modifiable multimap of the received trailing metadata on + virtual Status* GetRecvStatus() = 0; + + /// Returns a modifiable multimap of the received trailing metadata on /// PRE_RECV_STATUS and POST_RECV_STATUS interceptions; nullptr if not valid - virtual std::multimap<grpc::string_ref, grpc::string_ref>* - GetRecvTrailingMetadata() = 0; - - /// Gets an intercepted channel. When a call is started on this interceptor, - /// only interceptors after the current interceptor are created from the - /// factory objects registered with the channel. This allows calls to be - /// started from interceptors without infinite regress through the interceptor - /// list. - virtual std::unique_ptr<ChannelInterface> GetInterceptedChannel() = 0; - - /// On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE - /// op. This would be a signal to the reader that there will be no more - /// messages, or the stream has failed or been cancelled. - virtual void FailHijackedRecvMessage() = 0; - - /// On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND - /// MESSAGE op - virtual void FailHijackedSendMessage() = 0; -}; - -/// Interface for an interceptor. Interceptor authors must create a class -/// that derives from this parent class. -class Interceptor { - public: - virtual ~Interceptor() {} - - /// The one public method of an Interceptor interface. Override this to - /// trigger the desired actions at the hook points described above. - virtual void Intercept(InterceptorBatchMethods* methods) = 0; -}; - -} // namespace experimental -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H + virtual std::multimap<grpc::string_ref, grpc::string_ref>* + GetRecvTrailingMetadata() = 0; + + /// Gets an intercepted channel. When a call is started on this interceptor, + /// only interceptors after the current interceptor are created from the + /// factory objects registered with the channel. This allows calls to be + /// started from interceptors without infinite regress through the interceptor + /// list. + virtual std::unique_ptr<ChannelInterface> GetInterceptedChannel() = 0; + + /// On a hijacked RPC, an interceptor can decide to fail a PRE_RECV_MESSAGE + /// op. This would be a signal to the reader that there will be no more + /// messages, or the stream has failed or been cancelled. + virtual void FailHijackedRecvMessage() = 0; + + /// On a hijacked RPC/ to-be hijacked RPC, this can be called to fail a SEND + /// MESSAGE op + virtual void FailHijackedSendMessage() = 0; +}; + +/// Interface for an interceptor. Interceptor authors must create a class +/// that derives from this parent class. +class Interceptor { + public: + virtual ~Interceptor() {} + + /// The one public method of an Interceptor interface. Override this to + /// trigger the desired actions at the hook points described above. + virtual void Intercept(InterceptorBatchMethods* methods) = 0; +}; + +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h index 714351f543..62c879fdec 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/interceptor_common.h @@ -1,558 +1,558 @@ -/* - * - * Copyright 2018 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. - * - */ - -#if defined(__GNUC__) -#pragma GCC system_header -#endif - -#ifndef GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H -#define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H - -#include <array> -#include <functional> - -#include <grpcpp/impl/codegen/call.h> -#include <grpcpp/impl/codegen/call_op_set_interface.h> -#include <grpcpp/impl/codegen/client_interceptor.h> -#include <grpcpp/impl/codegen/intercepted_channel.h> -#include <grpcpp/impl/codegen/server_interceptor.h> - -#include <grpc/impl/codegen/grpc_types.h> - -namespace grpc { -namespace internal { - -class InterceptorBatchMethodsImpl - : public experimental::InterceptorBatchMethods { - public: - InterceptorBatchMethodsImpl() { - for (auto i = static_cast<experimental::InterceptionHookPoints>(0); - i < experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS; - i = static_cast<experimental::InterceptionHookPoints>( - static_cast<size_t>(i) + 1)) { - hooks_[static_cast<size_t>(i)] = false; - } - } - - ~InterceptorBatchMethodsImpl() {} - - bool QueryInterceptionHookPoint( - experimental::InterceptionHookPoints type) override { - return hooks_[static_cast<size_t>(type)]; - } - - void Proceed() override { - if (call_->client_rpc_info() != nullptr) { - return ProceedClient(); - } - GPR_CODEGEN_ASSERT(call_->server_rpc_info() != nullptr); - ProceedServer(); - } - - void Hijack() override { - // Only the client can hijack when sending down initial metadata - GPR_CODEGEN_ASSERT(!reverse_ && ops_ != nullptr && - call_->client_rpc_info() != nullptr); - // It is illegal to call Hijack twice - GPR_CODEGEN_ASSERT(!ran_hijacking_interceptor_); - auto* rpc_info = call_->client_rpc_info(); - rpc_info->hijacked_ = true; - rpc_info->hijacked_interceptor_ = current_interceptor_index_; - ClearHookPoints(); - ops_->SetHijackingState(); - ran_hijacking_interceptor_ = true; - rpc_info->RunInterceptor(this, current_interceptor_index_); - } - - void AddInterceptionHookPoint(experimental::InterceptionHookPoints type) { - hooks_[static_cast<size_t>(type)] = true; - } - - ByteBuffer* GetSerializedSendMessage() override { - GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); - if (*orig_send_message_ != nullptr) { - GPR_CODEGEN_ASSERT(serializer_(*orig_send_message_).ok()); - *orig_send_message_ = nullptr; - } - return send_message_; - } - - const void* GetSendMessage() override { - GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); - return *orig_send_message_; - } - - void ModifySendMessage(const void* message) override { - GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); - *orig_send_message_ = message; - } - - bool GetSendMessageStatus() override { return !*fail_send_message_; } - +/* + * + * Copyright 2018 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. + * + */ + +#if defined(__GNUC__) +#pragma GCC system_header +#endif + +#ifndef GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H +#define GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H + +#include <array> +#include <functional> + +#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/call_op_set_interface.h> +#include <grpcpp/impl/codegen/client_interceptor.h> +#include <grpcpp/impl/codegen/intercepted_channel.h> +#include <grpcpp/impl/codegen/server_interceptor.h> + +#include <grpc/impl/codegen/grpc_types.h> + +namespace grpc { +namespace internal { + +class InterceptorBatchMethodsImpl + : public experimental::InterceptorBatchMethods { + public: + InterceptorBatchMethodsImpl() { + for (auto i = static_cast<experimental::InterceptionHookPoints>(0); + i < experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS; + i = static_cast<experimental::InterceptionHookPoints>( + static_cast<size_t>(i) + 1)) { + hooks_[static_cast<size_t>(i)] = false; + } + } + + ~InterceptorBatchMethodsImpl() {} + + bool QueryInterceptionHookPoint( + experimental::InterceptionHookPoints type) override { + return hooks_[static_cast<size_t>(type)]; + } + + void Proceed() override { + if (call_->client_rpc_info() != nullptr) { + return ProceedClient(); + } + GPR_CODEGEN_ASSERT(call_->server_rpc_info() != nullptr); + ProceedServer(); + } + + void Hijack() override { + // Only the client can hijack when sending down initial metadata + GPR_CODEGEN_ASSERT(!reverse_ && ops_ != nullptr && + call_->client_rpc_info() != nullptr); + // It is illegal to call Hijack twice + GPR_CODEGEN_ASSERT(!ran_hijacking_interceptor_); + auto* rpc_info = call_->client_rpc_info(); + rpc_info->hijacked_ = true; + rpc_info->hijacked_interceptor_ = current_interceptor_index_; + ClearHookPoints(); + ops_->SetHijackingState(); + ran_hijacking_interceptor_ = true; + rpc_info->RunInterceptor(this, current_interceptor_index_); + } + + void AddInterceptionHookPoint(experimental::InterceptionHookPoints type) { + hooks_[static_cast<size_t>(type)] = true; + } + + ByteBuffer* GetSerializedSendMessage() override { + GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); + if (*orig_send_message_ != nullptr) { + GPR_CODEGEN_ASSERT(serializer_(*orig_send_message_).ok()); + *orig_send_message_ = nullptr; + } + return send_message_; + } + + const void* GetSendMessage() override { + GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); + return *orig_send_message_; + } + + void ModifySendMessage(const void* message) override { + GPR_CODEGEN_ASSERT(orig_send_message_ != nullptr); + *orig_send_message_ = message; + } + + bool GetSendMessageStatus() override { return !*fail_send_message_; } + std::multimap<TString, TString>* GetSendInitialMetadata() override { - return send_initial_metadata_; - } - - Status GetSendStatus() override { - return Status(static_cast<StatusCode>(*code_), *error_message_, - *error_details_); - } - - void ModifySendStatus(const Status& status) override { - *code_ = static_cast<grpc_status_code>(status.error_code()); - *error_details_ = status.error_details(); - *error_message_ = status.error_message(); - } - + return send_initial_metadata_; + } + + Status GetSendStatus() override { + return Status(static_cast<StatusCode>(*code_), *error_message_, + *error_details_); + } + + void ModifySendStatus(const Status& status) override { + *code_ = static_cast<grpc_status_code>(status.error_code()); + *error_details_ = status.error_details(); + *error_message_ = status.error_message(); + } + std::multimap<TString, TString>* GetSendTrailingMetadata() override { - return send_trailing_metadata_; - } - - void* GetRecvMessage() override { return recv_message_; } - - std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() - override { - return recv_initial_metadata_->map(); - } - - Status* GetRecvStatus() override { return recv_status_; } - - void FailHijackedSendMessage() override { - GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( - experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)]); - *fail_send_message_ = true; - } - - std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() - override { - return recv_trailing_metadata_->map(); - } - - void SetSendMessage(ByteBuffer* buf, const void** msg, - bool* fail_send_message, - std::function<Status(const void*)> serializer) { - send_message_ = buf; - orig_send_message_ = msg; - fail_send_message_ = fail_send_message; - serializer_ = serializer; - } - - void SetSendInitialMetadata( + return send_trailing_metadata_; + } + + void* GetRecvMessage() override { return recv_message_; } + + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() + override { + return recv_initial_metadata_->map(); + } + + Status* GetRecvStatus() override { return recv_status_; } + + void FailHijackedSendMessage() override { + GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( + experimental::InterceptionHookPoints::PRE_SEND_MESSAGE)]); + *fail_send_message_ = true; + } + + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() + override { + return recv_trailing_metadata_->map(); + } + + void SetSendMessage(ByteBuffer* buf, const void** msg, + bool* fail_send_message, + std::function<Status(const void*)> serializer) { + send_message_ = buf; + orig_send_message_ = msg; + fail_send_message_ = fail_send_message; + serializer_ = serializer; + } + + void SetSendInitialMetadata( std::multimap<TString, TString>* metadata) { - send_initial_metadata_ = metadata; - } - + send_initial_metadata_ = metadata; + } + void SetSendStatus(grpc_status_code* code, TString* error_details, TString* error_message) { - code_ = code; - error_details_ = error_details; - error_message_ = error_message; - } - - void SetSendTrailingMetadata( + code_ = code; + error_details_ = error_details; + error_message_ = error_message; + } + + void SetSendTrailingMetadata( std::multimap<TString, TString>* metadata) { - send_trailing_metadata_ = metadata; - } - + send_trailing_metadata_ = metadata; + } + void SetRecvMessage(void* message, bool* hijacked_recv_message_failed) { - recv_message_ = message; + recv_message_ = message; hijacked_recv_message_failed_ = hijacked_recv_message_failed; - } - - void SetRecvInitialMetadata(MetadataMap* map) { - recv_initial_metadata_ = map; - } - - void SetRecvStatus(Status* status) { recv_status_ = status; } - - void SetRecvTrailingMetadata(MetadataMap* map) { - recv_trailing_metadata_ = map; - } - - std::unique_ptr<ChannelInterface> GetInterceptedChannel() override { - auto* info = call_->client_rpc_info(); - if (info == nullptr) { - return std::unique_ptr<ChannelInterface>(nullptr); - } - // The intercepted channel starts from the interceptor just after the - // current interceptor - return std::unique_ptr<ChannelInterface>(new InterceptedChannel( - info->channel(), current_interceptor_index_ + 1)); - } - - void FailHijackedRecvMessage() override { - GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( - experimental::InterceptionHookPoints::PRE_RECV_MESSAGE)]); + } + + void SetRecvInitialMetadata(MetadataMap* map) { + recv_initial_metadata_ = map; + } + + void SetRecvStatus(Status* status) { recv_status_ = status; } + + void SetRecvTrailingMetadata(MetadataMap* map) { + recv_trailing_metadata_ = map; + } + + std::unique_ptr<ChannelInterface> GetInterceptedChannel() override { + auto* info = call_->client_rpc_info(); + if (info == nullptr) { + return std::unique_ptr<ChannelInterface>(nullptr); + } + // The intercepted channel starts from the interceptor just after the + // current interceptor + return std::unique_ptr<ChannelInterface>(new InterceptedChannel( + info->channel(), current_interceptor_index_ + 1)); + } + + void FailHijackedRecvMessage() override { + GPR_CODEGEN_ASSERT(hooks_[static_cast<size_t>( + experimental::InterceptionHookPoints::PRE_RECV_MESSAGE)]); *hijacked_recv_message_failed_ = true; - } - - // Clears all state - void ClearState() { - reverse_ = false; - ran_hijacking_interceptor_ = false; - ClearHookPoints(); - } - - // Prepares for Post_recv operations - void SetReverse() { - reverse_ = true; - ran_hijacking_interceptor_ = false; - ClearHookPoints(); - } - - // This needs to be set before interceptors are run - void SetCall(Call* call) { call_ = call; } - - // This needs to be set before interceptors are run using RunInterceptors(). - // Alternatively, RunInterceptors(std::function<void(void)> f) can be used. - void SetCallOpSetInterface(CallOpSetInterface* ops) { ops_ = ops; } - - // SetCall should have been called before this. - // Returns true if the interceptors list is empty - bool InterceptorsListEmpty() { - auto* client_rpc_info = call_->client_rpc_info(); - if (client_rpc_info != nullptr) { - if (client_rpc_info->interceptors_.size() == 0) { - return true; - } else { - return false; - } - } - - auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { - return true; - } - return false; - } - - // This should be used only by subclasses of CallOpSetInterface. SetCall and - // SetCallOpSetInterface should have been called before this. After all the - // interceptors are done running, either ContinueFillOpsAfterInterception or - // ContinueFinalizeOpsAfterInterception will be called. Note that neither of - // them is invoked if there were no interceptors registered. - bool RunInterceptors() { - GPR_CODEGEN_ASSERT(ops_); - auto* client_rpc_info = call_->client_rpc_info(); - if (client_rpc_info != nullptr) { - if (client_rpc_info->interceptors_.size() == 0) { - return true; - } else { - RunClientInterceptors(); - return false; - } - } - - auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { - return true; - } - RunServerInterceptors(); - return false; - } - - // Returns true if no interceptors are run. Returns false otherwise if there - // are interceptors registered. After the interceptors are done running \a f - // will be invoked. This is to be used only by BaseAsyncRequest and - // SyncRequest. - bool RunInterceptors(std::function<void(void)> f) { - // This is used only by the server for initial call request - GPR_CODEGEN_ASSERT(reverse_ == true); - GPR_CODEGEN_ASSERT(call_->client_rpc_info() == nullptr); - auto* server_rpc_info = call_->server_rpc_info(); - if (server_rpc_info == nullptr || - server_rpc_info->interceptors_.size() == 0) { - return true; - } - callback_ = std::move(f); - RunServerInterceptors(); - return false; - } - - private: - void RunClientInterceptors() { - auto* rpc_info = call_->client_rpc_info(); - if (!reverse_) { - current_interceptor_index_ = 0; - } else { - if (rpc_info->hijacked_) { - current_interceptor_index_ = rpc_info->hijacked_interceptor_; - } else { - current_interceptor_index_ = rpc_info->interceptors_.size() - 1; - } - } - rpc_info->RunInterceptor(this, current_interceptor_index_); - } - - void RunServerInterceptors() { - auto* rpc_info = call_->server_rpc_info(); - if (!reverse_) { - current_interceptor_index_ = 0; - } else { - current_interceptor_index_ = rpc_info->interceptors_.size() - 1; - } - rpc_info->RunInterceptor(this, current_interceptor_index_); - } - - void ProceedClient() { - auto* rpc_info = call_->client_rpc_info(); - if (rpc_info->hijacked_ && !reverse_ && - current_interceptor_index_ == rpc_info->hijacked_interceptor_ && - !ran_hijacking_interceptor_) { - // We now need to provide hijacked recv ops to this interceptor - ClearHookPoints(); - ops_->SetHijackingState(); - ran_hijacking_interceptor_ = true; - rpc_info->RunInterceptor(this, current_interceptor_index_); - return; - } - if (!reverse_) { - current_interceptor_index_++; - // We are going down the stack of interceptors - if (current_interceptor_index_ < rpc_info->interceptors_.size()) { - if (rpc_info->hijacked_ && - current_interceptor_index_ > rpc_info->hijacked_interceptor_) { - // This is a hijacked RPC and we are done with hijacking - ops_->ContinueFillOpsAfterInterception(); - } else { - rpc_info->RunInterceptor(this, current_interceptor_index_); - } - } else { - // we are done running all the interceptors without any hijacking - ops_->ContinueFillOpsAfterInterception(); - } - } else { - // We are going up the stack of interceptors - if (current_interceptor_index_ > 0) { - // Continue running interceptors - current_interceptor_index_--; - rpc_info->RunInterceptor(this, current_interceptor_index_); - } else { - // we are done running all the interceptors without any hijacking - ops_->ContinueFinalizeResultAfterInterception(); - } - } - } - - void ProceedServer() { - auto* rpc_info = call_->server_rpc_info(); - if (!reverse_) { - current_interceptor_index_++; - if (current_interceptor_index_ < rpc_info->interceptors_.size()) { - return rpc_info->RunInterceptor(this, current_interceptor_index_); - } else if (ops_) { - return ops_->ContinueFillOpsAfterInterception(); - } - } else { - // We are going up the stack of interceptors - if (current_interceptor_index_ > 0) { - // Continue running interceptors - current_interceptor_index_--; - return rpc_info->RunInterceptor(this, current_interceptor_index_); - } else if (ops_) { - return ops_->ContinueFinalizeResultAfterInterception(); - } - } - GPR_CODEGEN_ASSERT(callback_); - callback_(); - } - - void ClearHookPoints() { - for (auto i = static_cast<experimental::InterceptionHookPoints>(0); - i < experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS; - i = static_cast<experimental::InterceptionHookPoints>( - static_cast<size_t>(i) + 1)) { - hooks_[static_cast<size_t>(i)] = false; - } - } - - std::array<bool, - static_cast<size_t>( - experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS)> - hooks_; - - size_t current_interceptor_index_ = 0; // Current iterator - bool reverse_ = false; - bool ran_hijacking_interceptor_ = false; - Call* call_ = nullptr; // The Call object is present along with CallOpSet - // object/callback - CallOpSetInterface* ops_ = nullptr; - std::function<void(void)> callback_; - - ByteBuffer* send_message_ = nullptr; - bool* fail_send_message_ = nullptr; - const void** orig_send_message_ = nullptr; - std::function<Status(const void*)> serializer_; - + } + + // Clears all state + void ClearState() { + reverse_ = false; + ran_hijacking_interceptor_ = false; + ClearHookPoints(); + } + + // Prepares for Post_recv operations + void SetReverse() { + reverse_ = true; + ran_hijacking_interceptor_ = false; + ClearHookPoints(); + } + + // This needs to be set before interceptors are run + void SetCall(Call* call) { call_ = call; } + + // This needs to be set before interceptors are run using RunInterceptors(). + // Alternatively, RunInterceptors(std::function<void(void)> f) can be used. + void SetCallOpSetInterface(CallOpSetInterface* ops) { ops_ = ops; } + + // SetCall should have been called before this. + // Returns true if the interceptors list is empty + bool InterceptorsListEmpty() { + auto* client_rpc_info = call_->client_rpc_info(); + if (client_rpc_info != nullptr) { + if (client_rpc_info->interceptors_.size() == 0) { + return true; + } else { + return false; + } + } + + auto* server_rpc_info = call_->server_rpc_info(); + if (server_rpc_info == nullptr || + server_rpc_info->interceptors_.size() == 0) { + return true; + } + return false; + } + + // This should be used only by subclasses of CallOpSetInterface. SetCall and + // SetCallOpSetInterface should have been called before this. After all the + // interceptors are done running, either ContinueFillOpsAfterInterception or + // ContinueFinalizeOpsAfterInterception will be called. Note that neither of + // them is invoked if there were no interceptors registered. + bool RunInterceptors() { + GPR_CODEGEN_ASSERT(ops_); + auto* client_rpc_info = call_->client_rpc_info(); + if (client_rpc_info != nullptr) { + if (client_rpc_info->interceptors_.size() == 0) { + return true; + } else { + RunClientInterceptors(); + return false; + } + } + + auto* server_rpc_info = call_->server_rpc_info(); + if (server_rpc_info == nullptr || + server_rpc_info->interceptors_.size() == 0) { + return true; + } + RunServerInterceptors(); + return false; + } + + // Returns true if no interceptors are run. Returns false otherwise if there + // are interceptors registered. After the interceptors are done running \a f + // will be invoked. This is to be used only by BaseAsyncRequest and + // SyncRequest. + bool RunInterceptors(std::function<void(void)> f) { + // This is used only by the server for initial call request + GPR_CODEGEN_ASSERT(reverse_ == true); + GPR_CODEGEN_ASSERT(call_->client_rpc_info() == nullptr); + auto* server_rpc_info = call_->server_rpc_info(); + if (server_rpc_info == nullptr || + server_rpc_info->interceptors_.size() == 0) { + return true; + } + callback_ = std::move(f); + RunServerInterceptors(); + return false; + } + + private: + void RunClientInterceptors() { + auto* rpc_info = call_->client_rpc_info(); + if (!reverse_) { + current_interceptor_index_ = 0; + } else { + if (rpc_info->hijacked_) { + current_interceptor_index_ = rpc_info->hijacked_interceptor_; + } else { + current_interceptor_index_ = rpc_info->interceptors_.size() - 1; + } + } + rpc_info->RunInterceptor(this, current_interceptor_index_); + } + + void RunServerInterceptors() { + auto* rpc_info = call_->server_rpc_info(); + if (!reverse_) { + current_interceptor_index_ = 0; + } else { + current_interceptor_index_ = rpc_info->interceptors_.size() - 1; + } + rpc_info->RunInterceptor(this, current_interceptor_index_); + } + + void ProceedClient() { + auto* rpc_info = call_->client_rpc_info(); + if (rpc_info->hijacked_ && !reverse_ && + current_interceptor_index_ == rpc_info->hijacked_interceptor_ && + !ran_hijacking_interceptor_) { + // We now need to provide hijacked recv ops to this interceptor + ClearHookPoints(); + ops_->SetHijackingState(); + ran_hijacking_interceptor_ = true; + rpc_info->RunInterceptor(this, current_interceptor_index_); + return; + } + if (!reverse_) { + current_interceptor_index_++; + // We are going down the stack of interceptors + if (current_interceptor_index_ < rpc_info->interceptors_.size()) { + if (rpc_info->hijacked_ && + current_interceptor_index_ > rpc_info->hijacked_interceptor_) { + // This is a hijacked RPC and we are done with hijacking + ops_->ContinueFillOpsAfterInterception(); + } else { + rpc_info->RunInterceptor(this, current_interceptor_index_); + } + } else { + // we are done running all the interceptors without any hijacking + ops_->ContinueFillOpsAfterInterception(); + } + } else { + // We are going up the stack of interceptors + if (current_interceptor_index_ > 0) { + // Continue running interceptors + current_interceptor_index_--; + rpc_info->RunInterceptor(this, current_interceptor_index_); + } else { + // we are done running all the interceptors without any hijacking + ops_->ContinueFinalizeResultAfterInterception(); + } + } + } + + void ProceedServer() { + auto* rpc_info = call_->server_rpc_info(); + if (!reverse_) { + current_interceptor_index_++; + if (current_interceptor_index_ < rpc_info->interceptors_.size()) { + return rpc_info->RunInterceptor(this, current_interceptor_index_); + } else if (ops_) { + return ops_->ContinueFillOpsAfterInterception(); + } + } else { + // We are going up the stack of interceptors + if (current_interceptor_index_ > 0) { + // Continue running interceptors + current_interceptor_index_--; + return rpc_info->RunInterceptor(this, current_interceptor_index_); + } else if (ops_) { + return ops_->ContinueFinalizeResultAfterInterception(); + } + } + GPR_CODEGEN_ASSERT(callback_); + callback_(); + } + + void ClearHookPoints() { + for (auto i = static_cast<experimental::InterceptionHookPoints>(0); + i < experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS; + i = static_cast<experimental::InterceptionHookPoints>( + static_cast<size_t>(i) + 1)) { + hooks_[static_cast<size_t>(i)] = false; + } + } + + std::array<bool, + static_cast<size_t>( + experimental::InterceptionHookPoints::NUM_INTERCEPTION_HOOKS)> + hooks_; + + size_t current_interceptor_index_ = 0; // Current iterator + bool reverse_ = false; + bool ran_hijacking_interceptor_ = false; + Call* call_ = nullptr; // The Call object is present along with CallOpSet + // object/callback + CallOpSetInterface* ops_ = nullptr; + std::function<void(void)> callback_; + + ByteBuffer* send_message_ = nullptr; + bool* fail_send_message_ = nullptr; + const void** orig_send_message_ = nullptr; + std::function<Status(const void*)> serializer_; + std::multimap<TString, TString>* send_initial_metadata_; - - grpc_status_code* code_ = nullptr; + + grpc_status_code* code_ = nullptr; TString* error_details_ = nullptr; TString* error_message_ = nullptr; - + std::multimap<TString, TString>* send_trailing_metadata_ = nullptr; - - void* recv_message_ = nullptr; + + void* recv_message_ = nullptr; bool* hijacked_recv_message_failed_ = nullptr; - - MetadataMap* recv_initial_metadata_ = nullptr; - - Status* recv_status_ = nullptr; - - MetadataMap* recv_trailing_metadata_ = nullptr; -}; - -// A special implementation of InterceptorBatchMethods to send a Cancel -// notification down the interceptor stack -class CancelInterceptorBatchMethods - : public experimental::InterceptorBatchMethods { - public: - bool QueryInterceptionHookPoint( - experimental::InterceptionHookPoints type) override { - if (type == experimental::InterceptionHookPoints::PRE_SEND_CANCEL) { - return true; - } else { - return false; - } - } - - void Proceed() override { - // This is a no-op. For actual continuation of the RPC simply needs to - // return from the Intercept method - } - - void Hijack() override { - // Only the client can hijack when sending down initial metadata - GPR_CODEGEN_ASSERT(false && - "It is illegal to call Hijack on a method which has a " - "Cancel notification"); - } - - ByteBuffer* GetSerializedSendMessage() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetSendMessage on a method which " - "has a Cancel notification"); - return nullptr; - } - - bool GetSendMessageStatus() override { - GPR_CODEGEN_ASSERT( - false && - "It is illegal to call GetSendMessageStatus on a method which " - "has a Cancel notification"); - return false; - } - - const void* GetSendMessage() override { - GPR_CODEGEN_ASSERT( - false && - "It is illegal to call GetOriginalSendMessage on a method which " - "has a Cancel notification"); - return nullptr; - } - + + MetadataMap* recv_initial_metadata_ = nullptr; + + Status* recv_status_ = nullptr; + + MetadataMap* recv_trailing_metadata_ = nullptr; +}; + +// A special implementation of InterceptorBatchMethods to send a Cancel +// notification down the interceptor stack +class CancelInterceptorBatchMethods + : public experimental::InterceptorBatchMethods { + public: + bool QueryInterceptionHookPoint( + experimental::InterceptionHookPoints type) override { + if (type == experimental::InterceptionHookPoints::PRE_SEND_CANCEL) { + return true; + } else { + return false; + } + } + + void Proceed() override { + // This is a no-op. For actual continuation of the RPC simply needs to + // return from the Intercept method + } + + void Hijack() override { + // Only the client can hijack when sending down initial metadata + GPR_CODEGEN_ASSERT(false && + "It is illegal to call Hijack on a method which has a " + "Cancel notification"); + } + + ByteBuffer* GetSerializedSendMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetSendMessage on a method which " + "has a Cancel notification"); + return nullptr; + } + + bool GetSendMessageStatus() override { + GPR_CODEGEN_ASSERT( + false && + "It is illegal to call GetSendMessageStatus on a method which " + "has a Cancel notification"); + return false; + } + + const void* GetSendMessage() override { + GPR_CODEGEN_ASSERT( + false && + "It is illegal to call GetOriginalSendMessage on a method which " + "has a Cancel notification"); + return nullptr; + } + void ModifySendMessage(const void* /*message*/) override { - GPR_CODEGEN_ASSERT( - false && - "It is illegal to call ModifySendMessage on a method which " - "has a Cancel notification"); - } - + GPR_CODEGEN_ASSERT( + false && + "It is illegal to call ModifySendMessage on a method which " + "has a Cancel notification"); + } + std::multimap<TString, TString>* GetSendInitialMetadata() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetSendInitialMetadata on a " - "method which has a Cancel notification"); - return nullptr; - } - - Status GetSendStatus() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetSendStatus on a method which " - "has a Cancel notification"); - return Status(); - } - + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetSendInitialMetadata on a " + "method which has a Cancel notification"); + return nullptr; + } + + Status GetSendStatus() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetSendStatus on a method which " + "has a Cancel notification"); + return Status(); + } + void ModifySendStatus(const Status& /*status*/) override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call ModifySendStatus on a method " - "which has a Cancel notification"); - return; - } - + GPR_CODEGEN_ASSERT(false && + "It is illegal to call ModifySendStatus on a method " + "which has a Cancel notification"); + return; + } + std::multimap<TString, TString>* GetSendTrailingMetadata() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetSendTrailingMetadata on a " - "method which has a Cancel notification"); - return nullptr; - } - - void* GetRecvMessage() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetRecvMessage on a method which " - "has a Cancel notification"); - return nullptr; - } - - std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() - override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetRecvInitialMetadata on a " - "method which has a Cancel notification"); - return nullptr; - } - - Status* GetRecvStatus() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetRecvStatus on a method which " - "has a Cancel notification"); - return nullptr; - } - - std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() - override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetRecvTrailingMetadata on a " - "method which has a Cancel notification"); - return nullptr; - } - - std::unique_ptr<ChannelInterface> GetInterceptedChannel() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call GetInterceptedChannel on a " - "method which has a Cancel notification"); - return std::unique_ptr<ChannelInterface>(nullptr); - } - - void FailHijackedRecvMessage() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call FailHijackedRecvMessage on a " - "method which has a Cancel notification"); - } - - void FailHijackedSendMessage() override { - GPR_CODEGEN_ASSERT(false && - "It is illegal to call FailHijackedSendMessage on a " - "method which has a Cancel notification"); - } -}; -} // namespace internal -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetSendTrailingMetadata on a " + "method which has a Cancel notification"); + return nullptr; + } + + void* GetRecvMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetRecvMessage on a method which " + "has a Cancel notification"); + return nullptr; + } + + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvInitialMetadata() + override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetRecvInitialMetadata on a " + "method which has a Cancel notification"); + return nullptr; + } + + Status* GetRecvStatus() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetRecvStatus on a method which " + "has a Cancel notification"); + return nullptr; + } + + std::multimap<grpc::string_ref, grpc::string_ref>* GetRecvTrailingMetadata() + override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetRecvTrailingMetadata on a " + "method which has a Cancel notification"); + return nullptr; + } + + std::unique_ptr<ChannelInterface> GetInterceptedChannel() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call GetInterceptedChannel on a " + "method which has a Cancel notification"); + return std::unique_ptr<ChannelInterface>(nullptr); + } + + void FailHijackedRecvMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call FailHijackedRecvMessage on a " + "method which has a Cancel notification"); + } + + void FailHijackedSendMessage() override { + GPR_CODEGEN_ASSERT(false && + "It is illegal to call FailHijackedSendMessage on a " + "method which has a Cancel notification"); + } +}; +} // namespace internal +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_INTERCEPTOR_COMMON_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/metadata_map.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/metadata_map.h index 03afc0781a..4ad0727ef8 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/metadata_map.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/metadata_map.h @@ -19,77 +19,77 @@ #ifndef GRPCPP_IMPL_CODEGEN_METADATA_MAP_H #define GRPCPP_IMPL_CODEGEN_METADATA_MAP_H -#include <map> - -#include <grpc/impl/codegen/log.h> +#include <map> + +#include <grpc/impl/codegen/log.h> #include <grpcpp/impl/codegen/slice.h> namespace grpc { namespace internal { - -const char kBinaryErrorDetailsKey[] = "grpc-status-details-bin"; - + +const char kBinaryErrorDetailsKey[] = "grpc-status-details-bin"; + class MetadataMap { public: - MetadataMap() { Setup(); } - - ~MetadataMap() { Destroy(); } + MetadataMap() { Setup(); } + ~MetadataMap() { Destroy(); } + TString GetBinaryErrorDetails() { - // if filled_, extract from the multimap for O(log(n)) - if (filled_) { - auto iter = map_.find(kBinaryErrorDetailsKey); - if (iter != map_.end()) { + // if filled_, extract from the multimap for O(log(n)) + if (filled_) { + auto iter = map_.find(kBinaryErrorDetailsKey); + if (iter != map_.end()) { return TString(iter->second.begin(), iter->second.length()); - } - } - // if not yet filled, take the O(n) lookup to avoid allocating the - // multimap until it is requested. - // TODO(ncteisen): plumb this through core as a first class object, just - // like code and message. - else { - for (size_t i = 0; i < arr_.count; i++) { - if (strncmp(reinterpret_cast<const char*>( - GRPC_SLICE_START_PTR(arr_.metadata[i].key)), - kBinaryErrorDetailsKey, - GRPC_SLICE_LENGTH(arr_.metadata[i].key)) == 0) { + } + } + // if not yet filled, take the O(n) lookup to avoid allocating the + // multimap until it is requested. + // TODO(ncteisen): plumb this through core as a first class object, just + // like code and message. + else { + for (size_t i = 0; i < arr_.count; i++) { + if (strncmp(reinterpret_cast<const char*>( + GRPC_SLICE_START_PTR(arr_.metadata[i].key)), + kBinaryErrorDetailsKey, + GRPC_SLICE_LENGTH(arr_.metadata[i].key)) == 0) { return TString(reinterpret_cast<const char*>( GRPC_SLICE_START_PTR(arr_.metadata[i].value)), GRPC_SLICE_LENGTH(arr_.metadata[i].value)); - } - } - } + } + } + } return TString(); - } - - std::multimap<grpc::string_ref, grpc::string_ref>* map() { - FillMap(); - return &map_; - } - grpc_metadata_array* arr() { return &arr_; } - - void Reset() { - filled_ = false; - map_.clear(); - Destroy(); - Setup(); - } - - private: - bool filled_ = false; - grpc_metadata_array arr_; - std::multimap<grpc::string_ref, grpc::string_ref> map_; - - void Destroy() { + } + + std::multimap<grpc::string_ref, grpc::string_ref>* map() { + FillMap(); + return &map_; + } + grpc_metadata_array* arr() { return &arr_; } + + void Reset() { + filled_ = false; + map_.clear(); + Destroy(); + Setup(); + } + + private: + bool filled_ = false; + grpc_metadata_array arr_; + std::multimap<grpc::string_ref, grpc::string_ref> map_; + + void Destroy() { g_core_codegen_interface->grpc_metadata_array_destroy(&arr_); } - void Setup() { memset(&arr_, 0, sizeof(arr_)); } - + void Setup() { memset(&arr_, 0, sizeof(arr_)); } + void FillMap() { - if (filled_) return; - filled_ = true; + if (filled_) return; + filled_ = true; for (size_t i = 0; i < arr_.count; i++) { // TODO(yangg) handle duplicates? map_.insert(std::pair<grpc::string_ref, grpc::string_ref>( diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/rpc_service_method.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/rpc_service_method.h index 4fcc211243..e0f65fccf1 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/rpc_service_method.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/rpc_service_method.h @@ -25,7 +25,7 @@ #include <memory> #include <vector> -#include <grpc/impl/codegen/log.h> +#include <grpc/impl/codegen/log.h> #include <grpcpp/impl/codegen/byte_buffer.h> #include <grpcpp/impl/codegen/config.h> #include <grpcpp/impl/codegen/rpc_method.h> @@ -39,26 +39,26 @@ class MethodHandler { public: virtual ~MethodHandler() {} struct HandlerParameter { - /// Constructor for HandlerParameter - /// - /// \param c : the gRPC Call structure for this server call - /// \param context : the ServerContext structure for this server call - /// \param req : the request payload, if appropriate for this RPC - /// \param req_status : the request status after any interceptors have run + /// Constructor for HandlerParameter + /// + /// \param c : the gRPC Call structure for this server call + /// \param context : the ServerContext structure for this server call + /// \param req : the request payload, if appropriate for this RPC + /// \param req_status : the request status after any interceptors have run /// \param handler_data: internal data for the handler. /// \param requester : used only by the callback API. It is a function - /// called by the RPC Controller to request another RPC (and also - /// to set up the state required to make that request possible) + /// called by the RPC Controller to request another RPC (and also + /// to set up the state required to make that request possible) HandlerParameter(Call* c, ::grpc::ServerContextBase* context, void* req, Status req_status, void* handler_data, std::function<void()> requester) - : call(c), - server_context(context), - request(req), - status(req_status), + : call(c), + server_context(context), + request(req), + status(req_status), internal_data(handler_data), - call_requester(std::move(requester)) {} - ~HandlerParameter() {} + call_requester(std::move(requester)) {} + ~HandlerParameter() {} Call* const call; ::grpc::ServerContextBase* const server_context; void* const request; @@ -67,17 +67,17 @@ class MethodHandler { const std::function<void()> call_requester; }; virtual void RunHandler(const HandlerParameter& param) = 0; - - /* Returns a pointer to the deserialized request. \a status reflects the - result of deserialization. This pointer and the status should be filled in - a HandlerParameter and passed to RunHandler. It is illegal to access the - pointer after calling RunHandler. Ownership of the deserialized request is - retained by the handler. Returns nullptr if deserialization failed. */ + + /* Returns a pointer to the deserialized request. \a status reflects the + result of deserialization. This pointer and the status should be filled in + a HandlerParameter and passed to RunHandler. It is illegal to access the + pointer after calling RunHandler. Ownership of the deserialized request is + retained by the handler. Returns nullptr if deserialization failed. */ virtual void* Deserialize(grpc_call* /*call*/, grpc_byte_buffer* req, Status* /*status*/, void** /*handler_data*/) { - GPR_CODEGEN_ASSERT(req == nullptr); - return nullptr; - } + GPR_CODEGEN_ASSERT(req == nullptr); + return nullptr; + } }; /// Server side rpc method class @@ -86,65 +86,65 @@ class RpcServiceMethod : public RpcMethod { /// Takes ownership of the handler RpcServiceMethod(const char* name, RpcMethod::RpcType type, MethodHandler* handler) - : RpcMethod(name, type), - server_tag_(nullptr), - api_type_(ApiType::SYNC), - handler_(handler) {} - - enum class ApiType { - SYNC, - ASYNC, - RAW, - CALL_BACK, // not CALLBACK because that is reserved in Windows - RAW_CALL_BACK, - }; + : RpcMethod(name, type), + server_tag_(nullptr), + api_type_(ApiType::SYNC), + handler_(handler) {} + enum class ApiType { + SYNC, + ASYNC, + RAW, + CALL_BACK, // not CALLBACK because that is reserved in Windows + RAW_CALL_BACK, + }; + void set_server_tag(void* tag) { server_tag_ = tag; } void* server_tag() const { return server_tag_; } /// if MethodHandler is nullptr, then this is an async method MethodHandler* handler() const { return handler_.get(); } - ApiType api_type() const { return api_type_; } + ApiType api_type() const { return api_type_; } void SetHandler(MethodHandler* handler) { handler_.reset(handler); } - void SetServerApiType(RpcServiceMethod::ApiType type) { - if ((api_type_ == ApiType::SYNC) && - (type == ApiType::ASYNC || type == ApiType::RAW)) { - // this marks this method as async - handler_.reset(); - } else if (api_type_ != ApiType::SYNC) { - // this is not an error condition, as it allows users to declare a server - // like WithRawMethod_foo<AsyncService>. However since it - // overwrites behavior, it should be logged. - gpr_log( - GPR_INFO, - "You are marking method %s as '%s', even though it was " - "previously marked '%s'. This behavior will overwrite the original " - "behavior. If you expected this then ignore this message.", - name(), TypeToString(api_type_), TypeToString(type)); - } - api_type_ = type; - } + void SetServerApiType(RpcServiceMethod::ApiType type) { + if ((api_type_ == ApiType::SYNC) && + (type == ApiType::ASYNC || type == ApiType::RAW)) { + // this marks this method as async + handler_.reset(); + } else if (api_type_ != ApiType::SYNC) { + // this is not an error condition, as it allows users to declare a server + // like WithRawMethod_foo<AsyncService>. However since it + // overwrites behavior, it should be logged. + gpr_log( + GPR_INFO, + "You are marking method %s as '%s', even though it was " + "previously marked '%s'. This behavior will overwrite the original " + "behavior. If you expected this then ignore this message.", + name(), TypeToString(api_type_), TypeToString(type)); + } + api_type_ = type; + } private: void* server_tag_; - ApiType api_type_; + ApiType api_type_; std::unique_ptr<MethodHandler> handler_; - - const char* TypeToString(RpcServiceMethod::ApiType type) { - switch (type) { - case ApiType::SYNC: - return "sync"; - case ApiType::ASYNC: - return "async"; - case ApiType::RAW: - return "raw"; - case ApiType::CALL_BACK: - return "callback"; - case ApiType::RAW_CALL_BACK: - return "raw_callback"; - default: - GPR_UNREACHABLE_CODE(return "unknown"); - } - } + + const char* TypeToString(RpcServiceMethod::ApiType type) { + switch (type) { + case ApiType::SYNC: + return "sync"; + case ApiType::ASYNC: + return "async"; + case ApiType::RAW: + return "raw"; + case ApiType::CALL_BACK: + return "callback"; + case ApiType::RAW_CALL_BACK: + return "raw_callback"; + default: + GPR_UNREACHABLE_CODE(return "unknown"); + } + } }; } // namespace internal diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_callback.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_callback.h index 3794a9ffa7..cb46e4dec7 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_callback.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_callback.h @@ -1,27 +1,27 @@ -/* - * +/* + * * Copyright 2019 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 GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H -#define GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H - + * + * 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 GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H +#define GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H + #include <atomic> #include <functional> #include <type_traits> - + #include <grpcpp/impl/codegen/call.h> #include <grpcpp/impl/codegen/call_op_set.h> #include <grpcpp/impl/codegen/callback_common.h> @@ -30,7 +30,7 @@ #include <grpcpp/impl/codegen/message_allocator.h> #include <grpcpp/impl/codegen/status.h> -namespace grpc { +namespace grpc { // Declare base class of all reactors as internal namespace internal { @@ -774,21 +774,21 @@ using UnimplementedBidiReactor = } // namespace internal // TODO(vjpai): Remove namespace experimental when de-experimentalized fully. -namespace experimental { +namespace experimental { -template <class Request> +template <class Request> using ServerReadReactor = ::grpc::ServerReadReactor<Request>; - -template <class Response> + +template <class Response> using ServerWriteReactor = ::grpc::ServerWriteReactor<Response>; - -template <class Request, class Response> + +template <class Request, class Response> using ServerBidiReactor = ::grpc::ServerBidiReactor<Request, Response>; - + using ServerUnaryReactor = ::grpc::ServerUnaryReactor; + +} // namespace experimental -} // namespace experimental - -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_SERVER_CALLBACK_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interceptor.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interceptor.h index 7598e72a40..0f176f8132 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interceptor.h @@ -1,139 +1,139 @@ -/* - * - * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H -#define GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H - -#include <atomic> -#include <vector> - -#include <grpcpp/impl/codegen/interceptor.h> -#include <grpcpp/impl/codegen/rpc_method.h> -#include <grpcpp/impl/codegen/string_ref.h> - +/* + * + * Copyright 2018 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 GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H +#define GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H + +#include <atomic> +#include <vector> + +#include <grpcpp/impl/codegen/interceptor.h> +#include <grpcpp/impl/codegen/rpc_method.h> +#include <grpcpp/impl/codegen/string_ref.h> + namespace grpc { class ServerContextBase; -namespace internal { -class InterceptorBatchMethodsImpl; -} - -namespace experimental { -class ServerRpcInfo; - -// A factory interface for creation of server interceptors. A vector of -// factories can be provided to ServerBuilder which will be used to create a new -// vector of server interceptors per RPC. Server interceptor authors should -// create a subclass of ServerInterceptorFactorInterface which creates objects -// of their interceptors. -class ServerInterceptorFactoryInterface { - public: - virtual ~ServerInterceptorFactoryInterface() {} - // Returns a pointer to an Interceptor object on successful creation, nullptr - // otherwise. If nullptr is returned, this server interceptor factory is - // ignored for the purposes of that RPC. - virtual Interceptor* CreateServerInterceptor(ServerRpcInfo* info) = 0; -}; - -/// ServerRpcInfo represents the state of a particular RPC as it -/// appears to an interceptor. It is created and owned by the library and -/// passed to the CreateServerInterceptor method of the application's -/// ServerInterceptorFactoryInterface implementation -class ServerRpcInfo { - public: - /// Type categorizes RPCs by unary or streaming type - enum class Type { UNARY, CLIENT_STREAMING, SERVER_STREAMING, BIDI_STREAMING }; - +namespace internal { +class InterceptorBatchMethodsImpl; +} + +namespace experimental { +class ServerRpcInfo; + +// A factory interface for creation of server interceptors. A vector of +// factories can be provided to ServerBuilder which will be used to create a new +// vector of server interceptors per RPC. Server interceptor authors should +// create a subclass of ServerInterceptorFactorInterface which creates objects +// of their interceptors. +class ServerInterceptorFactoryInterface { + public: + virtual ~ServerInterceptorFactoryInterface() {} + // Returns a pointer to an Interceptor object on successful creation, nullptr + // otherwise. If nullptr is returned, this server interceptor factory is + // ignored for the purposes of that RPC. + virtual Interceptor* CreateServerInterceptor(ServerRpcInfo* info) = 0; +}; + +/// ServerRpcInfo represents the state of a particular RPC as it +/// appears to an interceptor. It is created and owned by the library and +/// passed to the CreateServerInterceptor method of the application's +/// ServerInterceptorFactoryInterface implementation +class ServerRpcInfo { + public: + /// Type categorizes RPCs by unary or streaming type + enum class Type { UNARY, CLIENT_STREAMING, SERVER_STREAMING, BIDI_STREAMING }; + ~ServerRpcInfo() {} - - // Delete all copy and move constructors and assignments - ServerRpcInfo(const ServerRpcInfo&) = delete; - ServerRpcInfo& operator=(const ServerRpcInfo&) = delete; - ServerRpcInfo(ServerRpcInfo&&) = delete; - ServerRpcInfo& operator=(ServerRpcInfo&&) = delete; - - // Getter methods - - /// Return the fully-specified method name - const char* method() const { return method_; } - - /// Return the type of the RPC (unary or a streaming flavor) - Type type() const { return type_; } - - /// Return a pointer to the underlying ServerContext structure associated - /// with the RPC to support features that apply to it + + // Delete all copy and move constructors and assignments + ServerRpcInfo(const ServerRpcInfo&) = delete; + ServerRpcInfo& operator=(const ServerRpcInfo&) = delete; + ServerRpcInfo(ServerRpcInfo&&) = delete; + ServerRpcInfo& operator=(ServerRpcInfo&&) = delete; + + // Getter methods + + /// Return the fully-specified method name + const char* method() const { return method_; } + + /// Return the type of the RPC (unary or a streaming flavor) + Type type() const { return type_; } + + /// Return a pointer to the underlying ServerContext structure associated + /// with the RPC to support features that apply to it ServerContextBase* server_context() { return ctx_; } - - private: - static_assert(Type::UNARY == - static_cast<Type>(internal::RpcMethod::NORMAL_RPC), - "violated expectation about Type enum"); - static_assert(Type::CLIENT_STREAMING == - static_cast<Type>(internal::RpcMethod::CLIENT_STREAMING), - "violated expectation about Type enum"); - static_assert(Type::SERVER_STREAMING == - static_cast<Type>(internal::RpcMethod::SERVER_STREAMING), - "violated expectation about Type enum"); - static_assert(Type::BIDI_STREAMING == - static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), - "violated expectation about Type enum"); - + + private: + static_assert(Type::UNARY == + static_cast<Type>(internal::RpcMethod::NORMAL_RPC), + "violated expectation about Type enum"); + static_assert(Type::CLIENT_STREAMING == + static_cast<Type>(internal::RpcMethod::CLIENT_STREAMING), + "violated expectation about Type enum"); + static_assert(Type::SERVER_STREAMING == + static_cast<Type>(internal::RpcMethod::SERVER_STREAMING), + "violated expectation about Type enum"); + static_assert(Type::BIDI_STREAMING == + static_cast<Type>(internal::RpcMethod::BIDI_STREAMING), + "violated expectation about Type enum"); + ServerRpcInfo(ServerContextBase* ctx, const char* method, - internal::RpcMethod::RpcType type) + internal::RpcMethod::RpcType type) : ctx_(ctx), method_(method), type_(static_cast<Type>(type)) {} - - // Runs interceptor at pos \a pos. - void RunInterceptor( - experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { - GPR_CODEGEN_ASSERT(pos < interceptors_.size()); - interceptors_[pos]->Intercept(interceptor_methods); - } - - void RegisterInterceptors( - const std::vector< - std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>& - creators) { - for (const auto& creator : creators) { - auto* interceptor = creator->CreateServerInterceptor(this); - if (interceptor != nullptr) { - interceptors_.push_back( - std::unique_ptr<experimental::Interceptor>(interceptor)); - } - } - } - + + // Runs interceptor at pos \a pos. + void RunInterceptor( + experimental::InterceptorBatchMethods* interceptor_methods, size_t pos) { + GPR_CODEGEN_ASSERT(pos < interceptors_.size()); + interceptors_[pos]->Intercept(interceptor_methods); + } + + void RegisterInterceptors( + const std::vector< + std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>& + creators) { + for (const auto& creator : creators) { + auto* interceptor = creator->CreateServerInterceptor(this); + if (interceptor != nullptr) { + interceptors_.push_back( + std::unique_ptr<experimental::Interceptor>(interceptor)); + } + } + } + void Ref() { ref_.fetch_add(1, std::memory_order_relaxed); } - void Unref() { + void Unref() { if (GPR_UNLIKELY(ref_.fetch_sub(1, std::memory_order_acq_rel) == 1)) { - delete this; - } - } - + delete this; + } + } + ServerContextBase* ctx_ = nullptr; - const char* method_ = nullptr; - const Type type_; + const char* method_ = nullptr; + const Type type_; std::atomic<intptr_t> ref_{1}; - std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; - - friend class internal::InterceptorBatchMethodsImpl; + std::vector<std::unique_ptr<experimental::Interceptor>> interceptors_; + + friend class internal::InterceptorBatchMethodsImpl; friend class grpc::ServerContextBase; -}; - -} // namespace experimental -} // namespace grpc - -#endif // GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H +}; + +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_SERVER_INTERCEPTOR_H diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h index d97b725025..6b538812ed 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/server_interface.h @@ -23,7 +23,7 @@ #include <grpc/impl/codegen/grpc_types.h> #include <grpcpp/impl/codegen/byte_buffer.h> -#include <grpcpp/impl/codegen/call.h> +#include <grpcpp/impl/codegen/call.h> #include <grpcpp/impl/codegen/call_hook.h> #include <grpcpp/impl/codegen/completion_queue_tag.h> #include <grpcpp/impl/codegen/core_codegen_interface.h> @@ -66,35 +66,35 @@ class ServerInterface : public internal::CallHook { public: virtual ~ServerInterface() {} - /// \a Shutdown does the following things: - /// - /// 1. Shutdown the server: deactivate all listening ports, mark it in - /// "shutdown mode" so that further call Request's or incoming RPC matches - /// are no longer allowed. Also return all Request'ed-but-not-yet-active - /// calls as failed (!ok). This refers to calls that have been requested - /// at the server by the server-side library or application code but that - /// have not yet been matched to incoming RPCs from the client. Note that - /// this would even include default calls added automatically by the gRPC - /// C++ API without the user's input (e.g., "Unimplemented RPC method") - /// - /// 2. Block until all rpc method handlers invoked automatically by the sync - /// API finish. - /// - /// 3. If all pending calls complete (and all their operations are - /// retrieved by Next) before \a deadline expires, this finishes - /// gracefully. Otherwise, forcefully cancel all pending calls associated - /// with the server after \a deadline expires. In the case of the sync API, - /// if the RPC function for a streaming call has already been started and - /// takes a week to complete, the RPC function won't be forcefully - /// terminated (since that would leave state corrupt and incomplete) and - /// the method handler will just keep running (which will prevent the - /// server from completing the "join" operation that it needs to do at - /// shutdown time). + /// \a Shutdown does the following things: /// + /// 1. Shutdown the server: deactivate all listening ports, mark it in + /// "shutdown mode" so that further call Request's or incoming RPC matches + /// are no longer allowed. Also return all Request'ed-but-not-yet-active + /// calls as failed (!ok). This refers to calls that have been requested + /// at the server by the server-side library or application code but that + /// have not yet been matched to incoming RPCs from the client. Note that + /// this would even include default calls added automatically by the gRPC + /// C++ API without the user's input (e.g., "Unimplemented RPC method") + /// + /// 2. Block until all rpc method handlers invoked automatically by the sync + /// API finish. + /// + /// 3. If all pending calls complete (and all their operations are + /// retrieved by Next) before \a deadline expires, this finishes + /// gracefully. Otherwise, forcefully cancel all pending calls associated + /// with the server after \a deadline expires. In the case of the sync API, + /// if the RPC function for a streaming call has already been started and + /// takes a week to complete, the RPC function won't be forcefully + /// terminated (since that would leave state corrupt and incomplete) and + /// the method handler will just keep running (which will prevent the + /// server from completing the "join" operation that it needs to do at + /// shutdown time). + /// /// All completion queue associated with the server (for example, for async /// serving) must be shutdown *after* this method has returned: /// See \a ServerBuilder::AddCompletionQueue for details. - /// They must also be drained (by repeated Next) after being shutdown. + /// They must also be drained (by repeated Next) after being shutdown. /// /// \param deadline How long to wait until pending rpcs are forcefully /// terminated. @@ -103,7 +103,7 @@ class ServerInterface : public internal::CallHook { ShutdownInternal(TimePoint<T>(deadline).raw_time()); } - /// Shutdown the server without a deadline and forced cancellation. + /// Shutdown the server without a deadline and forced cancellation. /// /// All completion queue associated with the server (for example, for async /// serving) must be shutdown *after* this method has returned: @@ -200,9 +200,9 @@ class ServerInterface : public internal::CallHook { bool FinalizeResult(void** tag, bool* status) override; - private: - void ContinueFinalizeResultAfterInterception(); - + private: + void ContinueFinalizeResultAfterInterception(); + protected: ServerInterface* const server_; ::grpc::ServerContext* const context_; @@ -212,12 +212,12 @@ class ServerInterface : public internal::CallHook { void* const tag_; const bool delete_on_finalize_; grpc_call* call_; - internal::Call call_wrapper_; - internal::InterceptorBatchMethodsImpl interceptor_methods_; - bool done_intercepting_; + internal::Call call_wrapper_; + internal::InterceptorBatchMethodsImpl interceptor_methods_; + bool done_intercepting_; }; - /// RegisteredAsyncRequest is not part of the C++ API + /// RegisteredAsyncRequest is not part of the C++ API class RegisteredAsyncRequest : public BaseAsyncRequest { public: RegisteredAsyncRequest(ServerInterface* server, @@ -228,38 +228,38 @@ class ServerInterface : public internal::CallHook { void* tag, const char* name, internal::RpcMethod::RpcType type); - virtual bool FinalizeResult(void** tag, bool* status) override { - /* If we are done intercepting, then there is nothing more for us to do */ - if (done_intercepting_) { - return BaseAsyncRequest::FinalizeResult(tag, status); - } + virtual bool FinalizeResult(void** tag, bool* status) override { + /* If we are done intercepting, then there is nothing more for us to do */ + if (done_intercepting_) { + return BaseAsyncRequest::FinalizeResult(tag, status); + } call_wrapper_ = ::grpc::internal::Call( - call_, server_, call_cq_, server_->max_receive_message_size(), - context_->set_server_rpc_info(name_, type_, - *server_->interceptor_creators())); - return BaseAsyncRequest::FinalizeResult(tag, status); - } + call_, server_, call_cq_, server_->max_receive_message_size(), + context_->set_server_rpc_info(name_, type_, + *server_->interceptor_creators())); + return BaseAsyncRequest::FinalizeResult(tag, status); + } protected: void IssueRequest(void* registered_method, grpc_byte_buffer** payload, ::grpc::ServerCompletionQueue* notification_cq); - const char* name_; - const internal::RpcMethod::RpcType type_; + const char* name_; + const internal::RpcMethod::RpcType type_; }; class NoPayloadAsyncRequest final : public RegisteredAsyncRequest { public: - NoPayloadAsyncRequest(internal::RpcServiceMethod* registered_method, + NoPayloadAsyncRequest(internal::RpcServiceMethod* registered_method, ServerInterface* server, ::grpc::ServerContext* context, internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) - : RegisteredAsyncRequest( - server, context, stream, call_cq, notification_cq, tag, - registered_method->name(), registered_method->method_type()) { - IssueRequest(registered_method->server_tag(), nullptr, notification_cq); + : RegisteredAsyncRequest( + server, context, stream, call_cq, notification_cq, tag, + registered_method->name(), registered_method->method_type()) { + IssueRequest(registered_method->server_tag(), nullptr, notification_cq); } // uses RegisteredAsyncRequest::FinalizeResult @@ -268,19 +268,19 @@ class ServerInterface : public internal::CallHook { template <class Message> class PayloadAsyncRequest final : public RegisteredAsyncRequest { public: - PayloadAsyncRequest(internal::RpcServiceMethod* registered_method, + PayloadAsyncRequest(internal::RpcServiceMethod* registered_method, ServerInterface* server, ::grpc::ServerContext* context, internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag, Message* request) - : RegisteredAsyncRequest( - server, context, stream, call_cq, notification_cq, tag, - registered_method->name(), registered_method->method_type()), + : RegisteredAsyncRequest( + server, context, stream, call_cq, notification_cq, tag, + registered_method->name(), registered_method->method_type()), registered_method_(registered_method), request_(request) { - IssueRequest(registered_method->server_tag(), payload_.bbuf_ptr(), - notification_cq); + IssueRequest(registered_method->server_tag(), payload_.bbuf_ptr(), + notification_cq); } ~PayloadAsyncRequest() { @@ -288,10 +288,10 @@ class ServerInterface : public internal::CallHook { } bool FinalizeResult(void** tag, bool* status) override { - /* If we are done intercepting, then there is nothing more for us to do */ - if (done_intercepting_) { - return RegisteredAsyncRequest::FinalizeResult(tag, status); - } + /* If we are done intercepting, then there is nothing more for us to do */ + if (done_intercepting_) { + return RegisteredAsyncRequest::FinalizeResult(tag, status); + } if (*status) { if (!payload_.Valid() || !SerializationTraits<Message>::Deserialize( payload_.bbuf_ptr(), request_) @@ -310,15 +310,15 @@ class ServerInterface : public internal::CallHook { return false; } } - /* Set interception point for recv message */ - interceptor_methods_.AddInterceptionHookPoint( - experimental::InterceptionHookPoints::POST_RECV_MESSAGE); - interceptor_methods_.SetRecvMessage(request_, nullptr); + /* Set interception point for recv message */ + interceptor_methods_.AddInterceptionHookPoint( + experimental::InterceptionHookPoints::POST_RECV_MESSAGE); + interceptor_methods_.SetRecvMessage(request_, nullptr); return RegisteredAsyncRequest::FinalizeResult(tag, status); } private: - internal::RpcServiceMethod* const registered_method_; + internal::RpcServiceMethod* const registered_method_; Message* const request_; ByteBuffer payload_; }; @@ -345,8 +345,8 @@ class ServerInterface : public internal::CallHook { ::grpc::ServerCompletionQueue* notification_cq, void* tag, Message* message) { GPR_CODEGEN_ASSERT(method); - new PayloadAsyncRequest<Message>(method, this, context, stream, call_cq, - notification_cq, tag, message); + new PayloadAsyncRequest<Message>(method, this, context, stream, call_cq, + notification_cq, tag, message); } void RequestAsyncCall(internal::RpcServiceMethod* method, @@ -356,8 +356,8 @@ class ServerInterface : public internal::CallHook { ::grpc::ServerCompletionQueue* notification_cq, void* tag) { GPR_CODEGEN_ASSERT(method); - new NoPayloadAsyncRequest(method, this, context, stream, call_cq, - notification_cq, tag); + new NoPayloadAsyncRequest(method, this, context, stream, call_cq, + notification_cq, tag); } void RequestAsyncGenericCall(GenericServerContext* context, @@ -368,27 +368,27 @@ class ServerInterface : public internal::CallHook { new GenericAsyncRequest(this, context, stream, call_cq, notification_cq, tag, true); } - - private: - // EXPERIMENTAL - // Getter method for the vector of interceptor factory objects. - // Returns a nullptr (rather than being pure) since this is a post-1.0 method - // and adding a new pure method to an interface would be a breaking change - // (even though this is private and non-API) - virtual std::vector< - std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>* - interceptor_creators() { - return nullptr; - } - - // EXPERIMENTAL - // A method to get the callbackable completion queue associated with this - // server. If the return value is nullptr, this server doesn't support - // callback operations. - // TODO(vjpai): Consider a better default like using a global CQ - // Returns nullptr (rather than being pure) since this is a post-1.0 method - // and adding a new pure method to an interface would be a breaking change - // (even though this is private and non-API) + + private: + // EXPERIMENTAL + // Getter method for the vector of interceptor factory objects. + // Returns a nullptr (rather than being pure) since this is a post-1.0 method + // and adding a new pure method to an interface would be a breaking change + // (even though this is private and non-API) + virtual std::vector< + std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>* + interceptor_creators() { + return nullptr; + } + + // EXPERIMENTAL + // A method to get the callbackable completion queue associated with this + // server. If the return value is nullptr, this server doesn't support + // callback operations. + // TODO(vjpai): Consider a better default like using a global CQ + // Returns nullptr (rather than being pure) since this is a post-1.0 method + // and adding a new pure method to an interface would be a breaking change + // (even though this is private and non-API) virtual ::grpc::CompletionQueue* CallbackCQ() { return nullptr; } }; diff --git a/contrib/libs/grpc/include/grpcpp/impl/codegen/service_type.h b/contrib/libs/grpc/include/grpcpp/impl/codegen/service_type.h index 30be904a3c..5875fa5294 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/codegen/service_type.h +++ b/contrib/libs/grpc/include/grpcpp/impl/codegen/service_type.h @@ -77,18 +77,18 @@ class Service { return false; } - bool has_callback_methods() const { + bool has_callback_methods() const { for (const auto& method : methods_) { if (method && (method->api_type() == internal::RpcServiceMethod::ApiType::CALL_BACK || method->api_type() == internal::RpcServiceMethod::ApiType::RAW_CALL_BACK)) { - return true; - } - } - return false; - } - + return true; + } + } + return false; + } + bool has_generic_methods() const { for (const auto& method : methods_) { if (method.get() == nullptr) { @@ -99,29 +99,29 @@ class Service { } protected: - // TODO(vjpai): Promote experimental contents once callback API is accepted - class experimental_type { - public: - explicit experimental_type(Service* service) : service_(service) {} - - void MarkMethodCallback(int index, internal::MethodHandler* handler) { + // TODO(vjpai): Promote experimental contents once callback API is accepted + class experimental_type { + public: + explicit experimental_type(Service* service) : service_(service) {} + + void MarkMethodCallback(int index, internal::MethodHandler* handler) { service_->MarkMethodCallbackInternal(index, handler); - } - - void MarkMethodRawCallback(int index, internal::MethodHandler* handler) { + } + + void MarkMethodRawCallback(int index, internal::MethodHandler* handler) { service_->MarkMethodRawCallbackInternal(index, handler); - } - + } + internal::MethodHandler* GetHandler(int index) { return service_->GetHandlerInternal(index); } - private: - Service* service_; - }; - - experimental_type experimental() { return experimental_type(this); } - + private: + Service* service_; + }; + + experimental_type experimental() { return experimental_type(this); } + template <class Message> void RequestAsyncUnary(int index, ::grpc::ServerContext* context, Message* request, @@ -129,11 +129,11 @@ class Service { ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { - // Typecast the index to size_t for indexing into a vector - // while preserving the API that existed before a compiler - // warning was first seen (grpc/grpc#11664) - size_t idx = static_cast<size_t>(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + // Typecast the index to size_t for indexing into a vector + // while preserving the API that existed before a compiler + // warning was first seen (grpc/grpc#11664) + size_t idx = static_cast<size_t>(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, notification_cq, tag, request); } void RequestAsyncClientStreaming( @@ -141,8 +141,8 @@ class Service { internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast<size_t>(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + size_t idx = static_cast<size_t>(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, notification_cq, tag); } template <class Message> @@ -151,8 +151,8 @@ class Service { internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast<size_t>(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + size_t idx = static_cast<size_t>(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, notification_cq, tag, request); } void RequestAsyncBidiStreaming( @@ -160,8 +160,8 @@ class Service { internal::ServerAsyncStreamingInterface* stream, ::grpc::CompletionQueue* call_cq, ::grpc::ServerCompletionQueue* notification_cq, void* tag) { - size_t idx = static_cast<size_t>(index); - server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, + size_t idx = static_cast<size_t>(index); + server_->RequestAsyncCall(methods_[idx].get(), context, stream, call_cq, notification_cq, tag); } @@ -170,50 +170,50 @@ class Service { } void MarkMethodAsync(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast<size_t>(index); + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast<size_t>(index); GPR_CODEGEN_ASSERT( - methods_[idx].get() != nullptr && + methods_[idx].get() != nullptr && "Cannot mark the method as 'async' because it has already been " "marked as 'generic'."); - methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC); - } - - void MarkMethodRaw(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast<size_t>(index); - GPR_CODEGEN_ASSERT(methods_[idx].get() != nullptr && - "Cannot mark the method as 'raw' because it has already " - "been marked as 'generic'."); - methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW); + methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::ASYNC); } + void MarkMethodRaw(int index) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast<size_t>(index); + GPR_CODEGEN_ASSERT(methods_[idx].get() != nullptr && + "Cannot mark the method as 'raw' because it has already " + "been marked as 'generic'."); + methods_[idx]->SetServerApiType(internal::RpcServiceMethod::ApiType::RAW); + } + void MarkMethodGeneric(int index) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast<size_t>(index); + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast<size_t>(index); GPR_CODEGEN_ASSERT( - methods_[idx]->handler() != nullptr && + methods_[idx]->handler() != nullptr && "Cannot mark the method as 'generic' because it has already been " - "marked as 'async' or 'raw'."); - methods_[idx].reset(); + "marked as 'async' or 'raw'."); + methods_[idx].reset(); } void MarkMethodStreamed(int index, internal::MethodHandler* streamed_method) { - // This does not have to be a hard error, however no one has approached us - // with a use case yet. Please file an issue if you believe you have one. - size_t idx = static_cast<size_t>(index); - GPR_CODEGEN_ASSERT(methods_[idx] && methods_[idx]->handler() && + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + size_t idx = static_cast<size_t>(index); + GPR_CODEGEN_ASSERT(methods_[idx] && methods_[idx]->handler() && "Cannot mark an async or generic method Streamed"); - methods_[idx]->SetHandler(streamed_method); + methods_[idx]->SetHandler(streamed_method); // From the server's point of view, streamed unary is a special // case of BIDI_STREAMING that has 1 read and 1 write, in that order, // and split server-side streaming is BIDI_STREAMING with 1 read and // any number of writes, in that order. - methods_[idx]->SetMethodType(internal::RpcMethod::BIDI_STREAMING); + methods_[idx]->SetMethodType(internal::RpcMethod::BIDI_STREAMING); } #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL diff --git a/contrib/libs/grpc/include/grpcpp/impl/grpc_library.h b/contrib/libs/grpc/include/grpcpp/impl/grpc_library.h index 3711c09879..eb6fc56c44 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/grpc_library.h +++ b/contrib/libs/grpc/include/grpcpp/impl/grpc_library.h @@ -40,12 +40,12 @@ class GrpcLibraryInitializer final { public: GrpcLibraryInitializer() { if (grpc::g_glip == nullptr) { - static auto* const g_gli = new GrpcLibrary(); - grpc::g_glip = g_gli; + static auto* const g_gli = new GrpcLibrary(); + grpc::g_glip = g_gli; } if (grpc::g_core_codegen_interface == nullptr) { - static auto* const g_core_codegen = new CoreCodegen(); - grpc::g_core_codegen_interface = g_core_codegen; + static auto* const g_core_codegen = new CoreCodegen(); + grpc::g_core_codegen_interface = g_core_codegen; } } diff --git a/contrib/libs/grpc/include/grpcpp/impl/server_builder_plugin.h b/contrib/libs/grpc/include/grpcpp/impl/server_builder_plugin.h index 8fedca2b14..8703e9d75b 100644 --- a/contrib/libs/grpc/include/grpcpp/impl/server_builder_plugin.h +++ b/contrib/libs/grpc/include/grpcpp/impl/server_builder_plugin.h @@ -41,9 +41,9 @@ class ServerBuilderPlugin { virtual ~ServerBuilderPlugin() {} virtual TString name() = 0; - /// UpdateServerBuilder will be called at an early stage in - /// ServerBuilder::BuildAndStart(), right after the ServerBuilderOptions have - /// done their updates. + /// UpdateServerBuilder will be called at an early stage in + /// ServerBuilder::BuildAndStart(), right after the ServerBuilderOptions have + /// done their updates. virtual void UpdateServerBuilder(ServerBuilder* /*builder*/) {} /// InitServer will be called in ServerBuilder::BuildAndStart(), after the diff --git a/contrib/libs/grpc/include/grpcpp/opencensus.h b/contrib/libs/grpc/include/grpcpp/opencensus.h index 0da949ab73..262b82de26 100644 --- a/contrib/libs/grpc/include/grpcpp/opencensus.h +++ b/contrib/libs/grpc/include/grpcpp/opencensus.h @@ -1,36 +1,36 @@ -/* - * +/* + * * Copyright 2019 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 GRPCPP_OPENCENSUS_H -#define GRPCPP_OPENCENSUS_H - + * + * 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 GRPCPP_OPENCENSUS_H +#define GRPCPP_OPENCENSUS_H + #include "opencensus/trace/span.h" - + namespace grpc { class ServerContext; // These symbols in this file will not be included in the binary unless // grpc_opencensus_plugin build target was added as a dependency. At the moment // it is only setup to be built with Bazel. - + // Registers the OpenCensus plugin with gRPC, so that it will be used for future // RPCs. This must be called before any views are created. void RegisterOpenCensusPlugin(); - + // RPC stats definitions, defined by // https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/gRPC.md @@ -42,6 +42,6 @@ void RegisterOpenCensusViewsForExport(); // Returns the tracing Span for the current RPC. ::opencensus::trace::Span GetSpanFromServerContext(ServerContext* context); -} // namespace grpc - -#endif // GRPCPP_OPENCENSUS_H +} // namespace grpc + +#endif // GRPCPP_OPENCENSUS_H diff --git a/contrib/libs/grpc/include/grpcpp/security/credentials.h b/contrib/libs/grpc/include/grpcpp/security/credentials.h index 339e9d4c27..ebaafc6b32 100644 --- a/contrib/libs/grpc/include/grpcpp/security/credentials.h +++ b/contrib/libs/grpc/include/grpcpp/security/credentials.h @@ -19,10 +19,10 @@ #ifndef GRPCPP_SECURITY_CREDENTIALS_H #define GRPCPP_SECURITY_CREDENTIALS_H -#if defined(__GNUC__) -#pragma GCC system_header -#endif - +#if defined(__GNUC__) +#pragma GCC system_header +#endif + #include <map> #include <memory> #include <vector> @@ -49,7 +49,7 @@ std::shared_ptr<Channel> CreateCustomChannel( const grpc::string& target, const std::shared_ptr<grpc::ChannelCredentials>& creds, const grpc::ChannelArguments& args); - + namespace experimental { std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors( const grpc::string& target, @@ -59,7 +59,7 @@ std::shared_ptr<grpc::Channel> CreateCustomChannelWithInterceptors( std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>> interceptor_creators); } - + /// A channel credentials object encapsulates all the state needed by a client /// to authenticate with a server for a given channel. /// It can make various assertions, e.g., about the client’s identity, role @@ -310,7 +310,7 @@ struct AltsCredentialsOptions { /// Builds ALTS Credentials given ALTS specific options std::shared_ptr<ChannelCredentials> AltsCredentials( const AltsCredentialsOptions& options); - + /// Builds Local Credentials. std::shared_ptr<ChannelCredentials> LocalCredentials( grpc_local_connect_type type); diff --git a/contrib/libs/grpc/include/grpcpp/security/server_credentials.h b/contrib/libs/grpc/include/grpcpp/security/server_credentials.h index d0a532360a..5199bb5bff 100644 --- a/contrib/libs/grpc/include/grpcpp/security/server_credentials.h +++ b/contrib/libs/grpc/include/grpcpp/security/server_credentials.h @@ -99,7 +99,7 @@ std::shared_ptr<ServerCredentials> AltsServerCredentials( /// Builds Local ServerCredentials. std::shared_ptr<ServerCredentials> AltsServerCredentials( const AltsServerCredentialsOptions& options); - + std::shared_ptr<ServerCredentials> LocalServerCredentials( grpc_local_connect_type type); diff --git a/contrib/libs/grpc/include/grpcpp/support/client_callback.h b/contrib/libs/grpc/include/grpcpp/support/client_callback.h index 063fdc4f85..1c22caca7f 100644 --- a/contrib/libs/grpc/include/grpcpp/support/client_callback.h +++ b/contrib/libs/grpc/include/grpcpp/support/client_callback.h @@ -1,24 +1,24 @@ -/* - * - * Copyright 2018 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 GRPCPP_SUPPORT_CLIENT_CALLBACK_H -#define GRPCPP_SUPPORT_CLIENT_CALLBACK_H - -#include <grpcpp/impl/codegen/client_callback.h> - -#endif // GRPCPP_SUPPORT_CLIENT_CALLBACK_H +/* + * + * Copyright 2018 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 GRPCPP_SUPPORT_CLIENT_CALLBACK_H +#define GRPCPP_SUPPORT_CLIENT_CALLBACK_H + +#include <grpcpp/impl/codegen/client_callback.h> + +#endif // GRPCPP_SUPPORT_CLIENT_CALLBACK_H diff --git a/contrib/libs/grpc/include/grpcpp/support/client_interceptor.h b/contrib/libs/grpc/include/grpcpp/support/client_interceptor.h index 50810e3fe3..063c663219 100644 --- a/contrib/libs/grpc/include/grpcpp/support/client_interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/support/client_interceptor.h @@ -1,24 +1,24 @@ -/* - * - * Copyright 2015 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 GRPCPP_SUPPORT_CLIENT_INTERCEPTOR_H -#define GRPCPP_SUPPORT_CLIENT_INTERCEPTOR_H - -#include <grpcpp/impl/codegen/client_interceptor.h> - -#endif // GRPCPP_SUPPORT_CLIENT_INTERCEPTOR_H +/* + * + * Copyright 2015 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 GRPCPP_SUPPORT_CLIENT_INTERCEPTOR_H +#define GRPCPP_SUPPORT_CLIENT_INTERCEPTOR_H + +#include <grpcpp/impl/codegen/client_interceptor.h> + +#endif // GRPCPP_SUPPORT_CLIENT_INTERCEPTOR_H diff --git a/contrib/libs/grpc/include/grpcpp/support/interceptor.h b/contrib/libs/grpc/include/grpcpp/support/interceptor.h index 7ff79516ba..0f51a84521 100644 --- a/contrib/libs/grpc/include/grpcpp/support/interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/support/interceptor.h @@ -1,24 +1,24 @@ -/* - * - * Copyright 2015 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 GRPCPP_SUPPORT_INTERCEPTOR_H -#define GRPCPP_SUPPORT_INTERCEPTOR_H - -#include <grpcpp/impl/codegen/interceptor.h> - -#endif // GRPCPP_SUPPORT_INTERCEPTOR_H +/* + * + * Copyright 2015 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 GRPCPP_SUPPORT_INTERCEPTOR_H +#define GRPCPP_SUPPORT_INTERCEPTOR_H + +#include <grpcpp/impl/codegen/interceptor.h> + +#endif // GRPCPP_SUPPORT_INTERCEPTOR_H diff --git a/contrib/libs/grpc/include/grpcpp/support/server_callback.h b/contrib/libs/grpc/include/grpcpp/support/server_callback.h index b0aeeb53c5..d91dc9be3d 100644 --- a/contrib/libs/grpc/include/grpcpp/support/server_callback.h +++ b/contrib/libs/grpc/include/grpcpp/support/server_callback.h @@ -1,24 +1,24 @@ -/* - * - * Copyright 2018 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 GRPCPP_SUPPORT_SERVER_CALLBACK_H -#define GRPCPP_SUPPORT_SERVER_CALLBACK_H - -#include <grpcpp/impl/codegen/server_callback.h> - -#endif // GRPCPP_SUPPORT_SERVER_CALLBACK_H +/* + * + * Copyright 2018 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 GRPCPP_SUPPORT_SERVER_CALLBACK_H +#define GRPCPP_SUPPORT_SERVER_CALLBACK_H + +#include <grpcpp/impl/codegen/server_callback.h> + +#endif // GRPCPP_SUPPORT_SERVER_CALLBACK_H diff --git a/contrib/libs/grpc/include/grpcpp/support/server_interceptor.h b/contrib/libs/grpc/include/grpcpp/support/server_interceptor.h index b0a6229b66..180b41b376 100644 --- a/contrib/libs/grpc/include/grpcpp/support/server_interceptor.h +++ b/contrib/libs/grpc/include/grpcpp/support/server_interceptor.h @@ -1,24 +1,24 @@ -/* - * - * Copyright 2015 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 GRPCPP_SUPPORT_SERVER_INTERCEPTOR_H -#define GRPCPP_SUPPORT_SERVER_INTERCEPTOR_H - -#include <grpcpp/impl/codegen/server_interceptor.h> - -#endif // GRPCPP_SUPPORT_SERVER_INTERCEPTOR_H +/* + * + * Copyright 2015 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 GRPCPP_SUPPORT_SERVER_INTERCEPTOR_H +#define GRPCPP_SUPPORT_SERVER_INTERCEPTOR_H + +#include <grpcpp/impl/codegen/server_interceptor.h> + +#endif // GRPCPP_SUPPORT_SERVER_INTERCEPTOR_H |