mirror of https://github.com/grpc/grpc.git
commit
9979b026ab
365 changed files with 11654 additions and 5429 deletions
@ -1,15 +1 @@ |
||||
gRPC Fail Fast Semantics |
||||
======================== |
||||
|
||||
Fail fast requests allow terminating requests (with status UNAVAILABLE) prior |
||||
to the deadline of the request being met. |
||||
|
||||
gRPC implementations of fail fast can terminate requests whenever a channel is |
||||
in the TRANSIENT_FAILURE or SHUTDOWN states. If the channel is in any other |
||||
state (CONNECTING, READY, or IDLE) the request should not be terminated. |
||||
|
||||
Fail fast SHOULD be the default for gRPC implementations, with an option to |
||||
switch to non fail fast. |
||||
|
||||
The opposite of fail fast is 'ignore connectivity'. |
||||
|
||||
Moved to wait-for-ready.md |
||||
|
@ -0,0 +1,14 @@ |
||||
gRPC Wait for Ready Semantics |
||||
============================= |
||||
|
||||
If an RPC is issued but the channel is in `TRANSIENT_FAILURE` or `SHUTDOWN` |
||||
states, the RPC is unable to be transmited promptly. By default, gRPC |
||||
implementations SHOULD fail such RPCs immediately. This is known as "fail fast," |
||||
but usage of the term is historical. RPCs SHOULD NOT fail as a result of the |
||||
channel being in other states (`CONNECTING`, `READY`, or `IDLE`). |
||||
|
||||
gRPC implementations MAY provide a per-RPC option to not fail RPCs as a result |
||||
of the channel being in `TRANSIENT_FAILURE` state. Instead, the implementation |
||||
queues the RPCs until the channel is `READY`. This is known as "wait for ready." |
||||
The RPCs SHOULD still fail before `READY` if there are unrelated reasons, such |
||||
as the channel is `SHUTDOWN` or the RPC's deadline is reached. |
@ -1,56 +1 @@ |
||||
gRPC in 3 minutes (Python) |
||||
======================== |
||||
|
||||
Background |
||||
------------- |
||||
For this sample, we've already generated the server and client stubs from |
||||
[helloworld.proto][] and we'll be using a specific reference platform. |
||||
|
||||
|
||||
Install gRPC: |
||||
```sh |
||||
$ pip install grpcio |
||||
``` |
||||
Or, to install it system wide: |
||||
```sh |
||||
$ sudo pip install grpcio |
||||
``` |
||||
|
||||
If you're on Windows, make sure you installed the `pip.exe` component when you |
||||
installed Python. Invoke as above but with `pip.exe` instead of `pip` (you may |
||||
also need to invoke from a `cmd.exe` ran as administrator): |
||||
```sh |
||||
$ pip.exe install grpcio |
||||
``` |
||||
|
||||
Download the example |
||||
```sh |
||||
$ # Clone the repository to get the example code: |
||||
$ git clone https://github.com/grpc/grpc |
||||
$ # Navigate to the "hello, world" Python example: |
||||
$ cd grpc/examples/python/helloworld |
||||
``` |
||||
|
||||
Try it! |
||||
------- |
||||
|
||||
- Run the server |
||||
|
||||
```sh |
||||
$ python2.7 greeter_server.py & |
||||
``` |
||||
|
||||
- Run the client |
||||
|
||||
```sh |
||||
$ python2.7 greeter_client.py |
||||
``` |
||||
|
||||
Tutorial |
||||
-------- |
||||
|
||||
You can find a more detailed tutorial in [gRPC Basics: Python][] |
||||
|
||||
[helloworld.proto]:../protos/helloworld.proto |
||||
[Install gRPC Python]:../../src/python#installation |
||||
[gRPC Basics: Python]:http://www.grpc.io/docs/tutorials/basic/python.html |
||||
[This code's documentation lives on the grpc.io site.](http://www.grpc.io/docs/quickstart/python.html) |
||||
|
@ -1 +1 @@ |
||||
[This code's documentation lives on the grpc.io site.](http://www.grpc.io/docs) |
||||
[This code's documentation lives on the grpc.io site.](http://www.grpc.io/docs/quickstart/python.html) |
||||
|
@ -1 +1,3 @@ |
||||
An example showing two stubs sharing a channel and two servicers sharing a server. |
||||
|
||||
More complete documentation lives at [grpc.io](http://www.grpc.io/docs/tutorials/basic/python.html). |
||||
|
@ -0,0 +1,81 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
/* Automatically generated nanopb constant definitions */ |
||||
/* Generated by nanopb-0.3.5-dev */ |
||||
|
||||
#include "src/core/ext/census/gen/trace_context.pb.h" |
||||
|
||||
#if PB_PROTO_HEADER_VERSION != 30 |
||||
#error Regenerate this file with the current version of nanopb generator. |
||||
#endif |
||||
|
||||
|
||||
|
||||
const pb_field_t google_trace_TraceId_fields[3] = { |
||||
PB_FIELD( 1, FIXED64 , OPTIONAL, STATIC , FIRST, google_trace_TraceId, hi, hi, 0), |
||||
PB_FIELD( 2, FIXED64 , OPTIONAL, STATIC , OTHER, google_trace_TraceId, lo, hi, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
const pb_field_t google_trace_TraceContext_fields[4] = { |
||||
PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, google_trace_TraceContext, trace_id, trace_id, &google_trace_TraceId_fields), |
||||
PB_FIELD( 2, FIXED64 , OPTIONAL, STATIC , OTHER, google_trace_TraceContext, span_id, trace_id, 0), |
||||
PB_FIELD( 3, BOOL , OPTIONAL, STATIC , OTHER, google_trace_TraceContext, is_sampled, span_id, 0), |
||||
PB_LAST_FIELD |
||||
}; |
||||
|
||||
|
||||
/* Check that field information fits in pb_field_t */ |
||||
#if !defined(PB_FIELD_32BIT) |
||||
/* If you get an error here, it means that you need to define PB_FIELD_32BIT
|
||||
* compile-time option. You can do that in pb.h or on compiler command line. |
||||
*
|
||||
* The reason you need to do this is that some of your messages contain tag |
||||
* numbers or field sizes that are larger than what can fit in 8 or 16 bit |
||||
* field descriptors. |
||||
*/ |
||||
PB_STATIC_ASSERT((pb_membersize(google_trace_TraceContext, trace_id) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_google_trace_TraceId_google_trace_TraceContext) |
||||
#endif |
||||
|
||||
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT) |
||||
/* If you get an error here, it means that you need to define PB_FIELD_16BIT
|
||||
* compile-time option. You can do that in pb.h or on compiler command line. |
||||
*
|
||||
* The reason you need to do this is that some of your messages contain tag |
||||
* numbers or field sizes that are larger than what can fit in the default |
||||
* 8 bit descriptors. |
||||
*/ |
||||
PB_STATIC_ASSERT((pb_membersize(google_trace_TraceContext, trace_id) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_google_trace_TraceId_google_trace_TraceContext) |
||||
#endif |
||||
|
||||
|
@ -0,0 +1,99 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
/* Automatically generated nanopb header */ |
||||
/* Generated by nanopb-0.3.5-dev */ |
||||
|
||||
#ifndef GRPC_CORE_EXT_CENSUS_GEN_TRACE_CONTEXT_PB_H |
||||
#define GRPC_CORE_EXT_CENSUS_GEN_TRACE_CONTEXT_PB_H |
||||
#include "third_party/nanopb/pb.h" |
||||
#if PB_PROTO_HEADER_VERSION != 30 |
||||
#error Regenerate this file with the current version of nanopb generator. |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* Struct definitions */ |
||||
typedef struct _google_trace_TraceId { |
||||
bool has_hi; |
||||
uint64_t hi; |
||||
bool has_lo; |
||||
uint64_t lo; |
||||
} google_trace_TraceId; |
||||
|
||||
typedef struct _google_trace_TraceContext { |
||||
bool has_trace_id; |
||||
google_trace_TraceId trace_id; |
||||
bool has_span_id; |
||||
uint64_t span_id; |
||||
bool has_is_sampled; |
||||
bool is_sampled; |
||||
} google_trace_TraceContext; |
||||
|
||||
/* Default values for struct fields */ |
||||
|
||||
/* Initializer values for message structs */ |
||||
#define google_trace_TraceId_init_default {false, 0, false, 0} |
||||
#define google_trace_TraceContext_init_default {false, google_trace_TraceId_init_default, false, 0, false, 0} |
||||
#define google_trace_TraceId_init_zero {false, 0, false, 0} |
||||
#define google_trace_TraceContext_init_zero {false, google_trace_TraceId_init_zero, false, 0, false, 0} |
||||
|
||||
/* Field tags (for use in manual encoding/decoding) */ |
||||
#define google_trace_TraceId_hi_tag 1 |
||||
#define google_trace_TraceId_lo_tag 2 |
||||
#define google_trace_TraceContext_trace_id_tag 1 |
||||
#define google_trace_TraceContext_span_id_tag 2 |
||||
#define google_trace_TraceContext_is_sampled_tag 3 |
||||
|
||||
/* Struct field encoding specification for nanopb */ |
||||
extern const pb_field_t google_trace_TraceId_fields[3]; |
||||
extern const pb_field_t google_trace_TraceContext_fields[4]; |
||||
|
||||
/* Maximum encoded size of messages (where known) */ |
||||
#define google_trace_TraceId_size 18 |
||||
#define google_trace_TraceContext_size 31 |
||||
|
||||
/* Message IDs (where set with "msgid" option) */ |
||||
#ifdef PB_MSGID |
||||
|
||||
#define TRACE_CONTEXT_MESSAGES \ |
||||
|
||||
|
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
} /* extern "C" */ |
||||
#endif |
||||
|
||||
#endif |
@ -1,292 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/ext/client_config/subchannel_call_holder.h" |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
|
||||
#include "src/core/lib/profiling/timers.h" |
||||
|
||||
#define GET_CALL(holder) \ |
||||
((grpc_subchannel_call *)(gpr_atm_acq_load(&(holder)->subchannel_call))) |
||||
|
||||
#define CANCELLED_CALL ((grpc_subchannel_call *)1) |
||||
|
||||
static void subchannel_ready(grpc_exec_ctx *exec_ctx, void *holder, |
||||
grpc_error *error); |
||||
static void retry_ops(grpc_exec_ctx *exec_ctx, void *retry_ops_args, |
||||
grpc_error *error); |
||||
|
||||
static void add_waiting_locked(grpc_subchannel_call_holder *holder, |
||||
grpc_transport_stream_op *op); |
||||
static void fail_locked(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder, grpc_error *error); |
||||
static void retry_waiting_locked(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder); |
||||
|
||||
void grpc_subchannel_call_holder_init( |
||||
grpc_subchannel_call_holder *holder, |
||||
grpc_subchannel_call_holder_pick_subchannel pick_subchannel, |
||||
void *pick_subchannel_arg, grpc_call_stack *owning_call) { |
||||
gpr_atm_rel_store(&holder->subchannel_call, 0); |
||||
holder->pick_subchannel = pick_subchannel; |
||||
holder->pick_subchannel_arg = pick_subchannel_arg; |
||||
gpr_mu_init(&holder->mu); |
||||
holder->connected_subchannel = NULL; |
||||
holder->waiting_ops = NULL; |
||||
holder->waiting_ops_count = 0; |
||||
holder->waiting_ops_capacity = 0; |
||||
holder->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; |
||||
holder->owning_call = owning_call; |
||||
holder->pollent = NULL; |
||||
} |
||||
|
||||
void grpc_subchannel_call_holder_destroy(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder) { |
||||
grpc_subchannel_call *call = GET_CALL(holder); |
||||
if (call != NULL && call != CANCELLED_CALL) { |
||||
GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, call, "holder"); |
||||
} |
||||
GPR_ASSERT(holder->creation_phase == |
||||
GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING); |
||||
gpr_mu_destroy(&holder->mu); |
||||
GPR_ASSERT(holder->waiting_ops_count == 0); |
||||
gpr_free(holder->waiting_ops); |
||||
} |
||||
|
||||
// The logic here is fairly complicated, due to (a) the fact that we
|
||||
// need to handle the case where we receive the send op before the
|
||||
// initial metadata op, and (b) the need for efficiency, especially in
|
||||
// the streaming case.
|
||||
// TODO(ctiller): Explain this more thoroughly.
|
||||
void grpc_subchannel_call_holder_perform_op(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder, |
||||
grpc_transport_stream_op *op) { |
||||
/* try to (atomically) get the call */ |
||||
grpc_subchannel_call *call = GET_CALL(holder); |
||||
GPR_TIMER_BEGIN("grpc_subchannel_call_holder_perform_op", 0); |
||||
if (call == CANCELLED_CALL) { |
||||
grpc_transport_stream_op_finish_with_failure(exec_ctx, op, |
||||
GRPC_ERROR_CANCELLED); |
||||
GPR_TIMER_END("grpc_subchannel_call_holder_perform_op", 0); |
||||
return; |
||||
} |
||||
if (call != NULL) { |
||||
grpc_subchannel_call_process_op(exec_ctx, call, op); |
||||
GPR_TIMER_END("grpc_subchannel_call_holder_perform_op", 0); |
||||
return; |
||||
} |
||||
/* we failed; lock and figure out what to do */ |
||||
gpr_mu_lock(&holder->mu); |
||||
retry: |
||||
/* need to recheck that another thread hasn't set the call */ |
||||
call = GET_CALL(holder); |
||||
if (call == CANCELLED_CALL) { |
||||
gpr_mu_unlock(&holder->mu); |
||||
grpc_transport_stream_op_finish_with_failure(exec_ctx, op, |
||||
GRPC_ERROR_CANCELLED); |
||||
GPR_TIMER_END("grpc_subchannel_call_holder_perform_op", 0); |
||||
return; |
||||
} |
||||
if (call != NULL) { |
||||
gpr_mu_unlock(&holder->mu); |
||||
grpc_subchannel_call_process_op(exec_ctx, call, op); |
||||
GPR_TIMER_END("grpc_subchannel_call_holder_perform_op", 0); |
||||
return; |
||||
} |
||||
/* if this is a cancellation, then we can raise our cancelled flag */ |
||||
if (op->cancel_error != GRPC_ERROR_NONE) { |
||||
if (!gpr_atm_rel_cas(&holder->subchannel_call, 0, |
||||
(gpr_atm)(uintptr_t)CANCELLED_CALL)) { |
||||
goto retry; |
||||
} else { |
||||
switch (holder->creation_phase) { |
||||
case GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING: |
||||
fail_locked(exec_ctx, holder, GRPC_ERROR_REF(op->cancel_error)); |
||||
break; |
||||
case GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL: |
||||
holder->pick_subchannel(exec_ctx, holder->pick_subchannel_arg, NULL, |
||||
0, &holder->connected_subchannel, NULL); |
||||
break; |
||||
} |
||||
gpr_mu_unlock(&holder->mu); |
||||
grpc_transport_stream_op_finish_with_failure(exec_ctx, op, |
||||
GRPC_ERROR_CANCELLED); |
||||
GPR_TIMER_END("grpc_subchannel_call_holder_perform_op", 0); |
||||
return; |
||||
} |
||||
} |
||||
/* if we don't have a subchannel, try to get one */ |
||||
if (holder->creation_phase == GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING && |
||||
holder->connected_subchannel == NULL && |
||||
op->send_initial_metadata != NULL) { |
||||
holder->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL; |
||||
grpc_closure_init(&holder->next_step, subchannel_ready, holder); |
||||
GRPC_CALL_STACK_REF(holder->owning_call, "pick_subchannel"); |
||||
if (holder->pick_subchannel( |
||||
exec_ctx, holder->pick_subchannel_arg, op->send_initial_metadata, |
||||
op->send_initial_metadata_flags, &holder->connected_subchannel, |
||||
&holder->next_step)) { |
||||
holder->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; |
||||
GRPC_CALL_STACK_UNREF(exec_ctx, holder->owning_call, "pick_subchannel"); |
||||
} |
||||
} |
||||
/* if we've got a subchannel, then let's ask it to create a call */ |
||||
if (holder->creation_phase == GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING && |
||||
holder->connected_subchannel != NULL) { |
||||
grpc_subchannel_call *subchannel_call = NULL; |
||||
grpc_error *error = grpc_connected_subchannel_create_call( |
||||
exec_ctx, holder->connected_subchannel, holder->pollent, |
||||
&subchannel_call); |
||||
if (error != GRPC_ERROR_NONE) { |
||||
subchannel_call = CANCELLED_CALL; |
||||
fail_locked(exec_ctx, holder, GRPC_ERROR_REF(error)); |
||||
grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); |
||||
} |
||||
gpr_atm_rel_store(&holder->subchannel_call, |
||||
(gpr_atm)(uintptr_t)subchannel_call); |
||||
retry_waiting_locked(exec_ctx, holder); |
||||
goto retry; |
||||
} |
||||
/* nothing to be done but wait */ |
||||
add_waiting_locked(holder, op); |
||||
gpr_mu_unlock(&holder->mu); |
||||
GPR_TIMER_END("grpc_subchannel_call_holder_perform_op", 0); |
||||
} |
||||
|
||||
static void subchannel_ready(grpc_exec_ctx *exec_ctx, void *arg, |
||||
grpc_error *error) { |
||||
grpc_subchannel_call_holder *holder = arg; |
||||
gpr_mu_lock(&holder->mu); |
||||
GPR_ASSERT(holder->creation_phase == |
||||
GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL); |
||||
holder->creation_phase = GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING; |
||||
if (holder->connected_subchannel == NULL) { |
||||
gpr_atm_no_barrier_store(&holder->subchannel_call, 1); |
||||
fail_locked(exec_ctx, holder, |
||||
GRPC_ERROR_CREATE_REFERENCING("Failed to create subchannel", |
||||
&error, 1)); |
||||
} else if (1 == gpr_atm_acq_load(&holder->subchannel_call)) { |
||||
/* already cancelled before subchannel became ready */ |
||||
fail_locked(exec_ctx, holder, |
||||
GRPC_ERROR_CREATE_REFERENCING( |
||||
"Cancelled before creating subchannel", &error, 1)); |
||||
} else { |
||||
grpc_subchannel_call *subchannel_call = NULL; |
||||
grpc_error *new_error = grpc_connected_subchannel_create_call( |
||||
exec_ctx, holder->connected_subchannel, holder->pollent, |
||||
&subchannel_call); |
||||
if (new_error != GRPC_ERROR_NONE) { |
||||
new_error = grpc_error_add_child(new_error, error); |
||||
subchannel_call = CANCELLED_CALL; |
||||
fail_locked(exec_ctx, holder, new_error); |
||||
} |
||||
gpr_atm_rel_store(&holder->subchannel_call, |
||||
(gpr_atm)(uintptr_t)subchannel_call); |
||||
retry_waiting_locked(exec_ctx, holder); |
||||
} |
||||
gpr_mu_unlock(&holder->mu); |
||||
GRPC_CALL_STACK_UNREF(exec_ctx, holder->owning_call, "pick_subchannel"); |
||||
} |
||||
|
||||
typedef struct { |
||||
grpc_transport_stream_op *ops; |
||||
size_t nops; |
||||
grpc_subchannel_call *call; |
||||
} retry_ops_args; |
||||
|
||||
static void retry_waiting_locked(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder) { |
||||
retry_ops_args *a = gpr_malloc(sizeof(*a)); |
||||
a->ops = holder->waiting_ops; |
||||
a->nops = holder->waiting_ops_count; |
||||
a->call = GET_CALL(holder); |
||||
if (a->call == CANCELLED_CALL) { |
||||
gpr_free(a); |
||||
fail_locked(exec_ctx, holder, GRPC_ERROR_CANCELLED); |
||||
return; |
||||
} |
||||
holder->waiting_ops = NULL; |
||||
holder->waiting_ops_count = 0; |
||||
holder->waiting_ops_capacity = 0; |
||||
GRPC_SUBCHANNEL_CALL_REF(a->call, "retry_ops"); |
||||
grpc_exec_ctx_sched(exec_ctx, grpc_closure_create(retry_ops, a), |
||||
GRPC_ERROR_NONE, NULL); |
||||
} |
||||
|
||||
static void retry_ops(grpc_exec_ctx *exec_ctx, void *args, grpc_error *error) { |
||||
retry_ops_args *a = args; |
||||
size_t i; |
||||
for (i = 0; i < a->nops; i++) { |
||||
grpc_subchannel_call_process_op(exec_ctx, a->call, &a->ops[i]); |
||||
} |
||||
GRPC_SUBCHANNEL_CALL_UNREF(exec_ctx, a->call, "retry_ops"); |
||||
gpr_free(a->ops); |
||||
gpr_free(a); |
||||
} |
||||
|
||||
static void add_waiting_locked(grpc_subchannel_call_holder *holder, |
||||
grpc_transport_stream_op *op) { |
||||
GPR_TIMER_BEGIN("add_waiting_locked", 0); |
||||
if (holder->waiting_ops_count == holder->waiting_ops_capacity) { |
||||
holder->waiting_ops_capacity = GPR_MAX(3, 2 * holder->waiting_ops_capacity); |
||||
holder->waiting_ops = |
||||
gpr_realloc(holder->waiting_ops, holder->waiting_ops_capacity * |
||||
sizeof(*holder->waiting_ops)); |
||||
} |
||||
holder->waiting_ops[holder->waiting_ops_count++] = *op; |
||||
GPR_TIMER_END("add_waiting_locked", 0); |
||||
} |
||||
|
||||
static void fail_locked(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder, |
||||
grpc_error *error) { |
||||
size_t i; |
||||
for (i = 0; i < holder->waiting_ops_count; i++) { |
||||
grpc_transport_stream_op_finish_with_failure( |
||||
exec_ctx, &holder->waiting_ops[i], GRPC_ERROR_REF(error)); |
||||
} |
||||
holder->waiting_ops_count = 0; |
||||
GRPC_ERROR_UNREF(error); |
||||
} |
||||
|
||||
char *grpc_subchannel_call_holder_get_peer( |
||||
grpc_exec_ctx *exec_ctx, grpc_subchannel_call_holder *holder) { |
||||
grpc_subchannel_call *subchannel_call = GET_CALL(holder); |
||||
|
||||
if (subchannel_call == NULL || subchannel_call == CANCELLED_CALL) { |
||||
return NULL; |
||||
} else { |
||||
return grpc_subchannel_call_get_peer(exec_ctx, subchannel_call); |
||||
} |
||||
} |
@ -1,99 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_CALL_HOLDER_H |
||||
#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_CALL_HOLDER_H |
||||
|
||||
#include "src/core/ext/client_config/subchannel.h" |
||||
#include "src/core/lib/iomgr/polling_entity.h" |
||||
|
||||
/** Pick a subchannel for grpc_subchannel_call_holder;
|
||||
Return 1 if subchannel is available immediately (in which case on_ready |
||||
should not be called), or 0 otherwise (in which case on_ready should be |
||||
called when the subchannel is available) */ |
||||
typedef int (*grpc_subchannel_call_holder_pick_subchannel)( |
||||
grpc_exec_ctx *exec_ctx, void *arg, grpc_metadata_batch *initial_metadata, |
||||
uint32_t initial_metadata_flags, |
||||
grpc_connected_subchannel **connected_subchannel, grpc_closure *on_ready); |
||||
|
||||
typedef enum { |
||||
GRPC_SUBCHANNEL_CALL_HOLDER_NOT_CREATING, |
||||
GRPC_SUBCHANNEL_CALL_HOLDER_PICKING_SUBCHANNEL |
||||
} grpc_subchannel_call_holder_creation_phase; |
||||
|
||||
/** Wrapper for holding a pointer to grpc_subchannel_call, and the
|
||||
associated machinery to create such a pointer. |
||||
Handles queueing of stream ops until a call object is ready, waiting |
||||
for initial metadata before trying to create a call object, |
||||
and handling cancellation gracefully. |
||||
|
||||
The channel filter uses this as their call_data. */ |
||||
typedef struct grpc_subchannel_call_holder { |
||||
/** either 0 for no call, 1 for cancelled, or a pointer to a
|
||||
grpc_subchannel_call */ |
||||
gpr_atm subchannel_call; |
||||
/** Helper function to choose the subchannel on which to create
|
||||
the call object. Channel filter delegates to the load |
||||
balancing policy (once it's ready). */ |
||||
grpc_subchannel_call_holder_pick_subchannel pick_subchannel; |
||||
void *pick_subchannel_arg; |
||||
|
||||
gpr_mu mu; |
||||
|
||||
grpc_subchannel_call_holder_creation_phase creation_phase; |
||||
grpc_connected_subchannel *connected_subchannel; |
||||
grpc_polling_entity *pollent; |
||||
|
||||
grpc_transport_stream_op *waiting_ops; |
||||
size_t waiting_ops_count; |
||||
size_t waiting_ops_capacity; |
||||
|
||||
grpc_closure next_step; |
||||
|
||||
grpc_call_stack *owning_call; |
||||
} grpc_subchannel_call_holder; |
||||
|
||||
void grpc_subchannel_call_holder_init( |
||||
grpc_subchannel_call_holder *holder, |
||||
grpc_subchannel_call_holder_pick_subchannel pick_subchannel, |
||||
void *pick_subchannel_arg, grpc_call_stack *owning_call); |
||||
void grpc_subchannel_call_holder_destroy(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder); |
||||
|
||||
void grpc_subchannel_call_holder_perform_op(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder, |
||||
grpc_transport_stream_op *op); |
||||
char *grpc_subchannel_call_holder_get_peer(grpc_exec_ctx *exec_ctx, |
||||
grpc_subchannel_call_holder *holder); |
||||
|
||||
#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_CALL_HOLDER_H */ |
@ -0,0 +1,180 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/lib/support/percent_encoding.h" |
||||
|
||||
#include <grpc/support/log.h> |
||||
|
||||
const uint8_t gpr_url_percent_encoding_unreserved_bytes[256 / 8] = { |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03, 0xfe, 0xff, 0xff, |
||||
0x87, 0xfe, 0xff, 0xff, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
||||
const uint8_t gpr_compatible_percent_encoding_unreserved_bytes[256 / 8] = { |
||||
0x00, 0x00, 0x00, 0x00, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
||||
0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
||||
|
||||
static bool is_unreserved_character(uint8_t c, |
||||
const uint8_t *unreserved_bytes) { |
||||
return ((unreserved_bytes[c / 8] >> (c % 8)) & 1) != 0; |
||||
} |
||||
|
||||
gpr_slice gpr_percent_encode_slice(gpr_slice slice, |
||||
const uint8_t *unreserved_bytes) { |
||||
static const uint8_t hex[] = "0123456789ABCDEF"; |
||||
|
||||
// first pass: count the number of bytes needed to output this string
|
||||
size_t output_length = 0; |
||||
const uint8_t *slice_start = GPR_SLICE_START_PTR(slice); |
||||
const uint8_t *slice_end = GPR_SLICE_END_PTR(slice); |
||||
const uint8_t *p; |
||||
bool any_reserved_bytes = false; |
||||
for (p = slice_start; p < slice_end; p++) { |
||||
bool unres = is_unreserved_character(*p, unreserved_bytes); |
||||
output_length += unres ? 1 : 3; |
||||
any_reserved_bytes |= !unres; |
||||
} |
||||
// no unreserved bytes: return the string unmodified
|
||||
if (!any_reserved_bytes) { |
||||
return gpr_slice_ref(slice); |
||||
} |
||||
// second pass: actually encode
|
||||
gpr_slice out = gpr_slice_malloc(output_length); |
||||
uint8_t *q = GPR_SLICE_START_PTR(out); |
||||
for (p = slice_start; p < slice_end; p++) { |
||||
if (is_unreserved_character(*p, unreserved_bytes)) { |
||||
*q++ = *p; |
||||
} else { |
||||
*q++ = '%'; |
||||
*q++ = hex[*p >> 4]; |
||||
*q++ = hex[*p & 15]; |
||||
} |
||||
} |
||||
GPR_ASSERT(q == GPR_SLICE_END_PTR(out)); |
||||
return out; |
||||
} |
||||
|
||||
static bool valid_hex(const uint8_t *p, const uint8_t *end) { |
||||
if (p >= end) return false; |
||||
return (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || |
||||
(*p >= 'A' && *p <= 'F'); |
||||
} |
||||
|
||||
static uint8_t dehex(uint8_t c) { |
||||
if (c >= '0' && c <= '9') return (uint8_t)(c - '0'); |
||||
if (c >= 'A' && c <= 'F') return (uint8_t)(c - 'A' + 10); |
||||
if (c >= 'a' && c <= 'f') return (uint8_t)(c - 'a' + 10); |
||||
GPR_UNREACHABLE_CODE(return 255); |
||||
} |
||||
|
||||
bool gpr_strict_percent_decode_slice(gpr_slice slice_in, |
||||
const uint8_t *unreserved_bytes, |
||||
gpr_slice *slice_out) { |
||||
const uint8_t *p = GPR_SLICE_START_PTR(slice_in); |
||||
const uint8_t *in_end = GPR_SLICE_END_PTR(slice_in); |
||||
size_t out_length = 0; |
||||
bool any_percent_encoded_stuff = false; |
||||
while (p != in_end) { |
||||
if (*p == '%') { |
||||
if (!valid_hex(++p, in_end)) return false; |
||||
if (!valid_hex(++p, in_end)) return false; |
||||
p++; |
||||
out_length++; |
||||
any_percent_encoded_stuff = true; |
||||
} else if (is_unreserved_character(*p, unreserved_bytes)) { |
||||
p++; |
||||
out_length++; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
if (!any_percent_encoded_stuff) { |
||||
*slice_out = gpr_slice_ref(slice_in); |
||||
return true; |
||||
} |
||||
p = GPR_SLICE_START_PTR(slice_in); |
||||
*slice_out = gpr_slice_malloc(out_length); |
||||
uint8_t *q = GPR_SLICE_START_PTR(*slice_out); |
||||
while (p != in_end) { |
||||
if (*p == '%') { |
||||
*q++ = (uint8_t)(dehex(p[1]) << 4) | (dehex(p[2])); |
||||
p += 3; |
||||
} else { |
||||
*q++ = *p++; |
||||
} |
||||
} |
||||
GPR_ASSERT(q == GPR_SLICE_END_PTR(*slice_out)); |
||||
return true; |
||||
} |
||||
|
||||
gpr_slice gpr_permissive_percent_decode_slice(gpr_slice slice_in) { |
||||
const uint8_t *p = GPR_SLICE_START_PTR(slice_in); |
||||
const uint8_t *in_end = GPR_SLICE_END_PTR(slice_in); |
||||
size_t out_length = 0; |
||||
bool any_percent_encoded_stuff = false; |
||||
while (p != in_end) { |
||||
if (*p == '%') { |
||||
if (!valid_hex(p + 1, in_end) || !valid_hex(p + 2, in_end)) { |
||||
p++; |
||||
out_length++; |
||||
} else { |
||||
p += 3; |
||||
out_length++; |
||||
any_percent_encoded_stuff = true; |
||||
} |
||||
} else { |
||||
p++; |
||||
out_length++; |
||||
} |
||||
} |
||||
if (!any_percent_encoded_stuff) { |
||||
return gpr_slice_ref(slice_in); |
||||
} |
||||
p = GPR_SLICE_START_PTR(slice_in); |
||||
gpr_slice out = gpr_slice_malloc(out_length); |
||||
uint8_t *q = GPR_SLICE_START_PTR(out); |
||||
while (p != in_end) { |
||||
if (*p == '%') { |
||||
if (!valid_hex(p + 1, in_end) || !valid_hex(p + 2, in_end)) { |
||||
*q++ = *p++; |
||||
} else { |
||||
*q++ = (uint8_t)(dehex(p[1]) << 4) | (dehex(p[2])); |
||||
p += 3; |
||||
} |
||||
} else { |
||||
*q++ = *p++; |
||||
} |
||||
} |
||||
GPR_ASSERT(q == GPR_SLICE_END_PTR(out)); |
||||
return out; |
||||
} |
@ -0,0 +1,78 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_CORE_LIB_SUPPORT_PERCENT_ENCODING_H |
||||
#define GRPC_CORE_LIB_SUPPORT_PERCENT_ENCODING_H |
||||
|
||||
/* Percent encoding and decoding of slices.
|
||||
Transforms arbitrary strings into safe-for-transmission strings by using |
||||
variants of percent encoding (RFC 3986). |
||||
Two major variants are supplied: one that strictly matches URL encoding, |
||||
and another which applies percent encoding only to non-http2 header |
||||
bytes (the 'compatible' variant) */ |
||||
|
||||
#include <stdbool.h> |
||||
|
||||
#include <grpc/support/slice.h> |
||||
|
||||
/* URL percent encoding spec bitfield (usabel as 'unreserved_bytes' in
|
||||
gpr_percent_encode_slice, gpr_strict_percent_decode_slice). |
||||
Flags [A-Za-z0-9-_.~] as unreserved bytes for the percent encoding routines |
||||
*/ |
||||
extern const uint8_t gpr_url_percent_encoding_unreserved_bytes[256 / 8]; |
||||
/* URL percent encoding spec bitfield (usabel as 'unreserved_bytes' in
|
||||
gpr_percent_encode_slice, gpr_strict_percent_decode_slice). |
||||
Flags ascii7 non-control characters excluding '%' as unreserved bytes for the |
||||
percent encoding routines */ |
||||
extern const uint8_t gpr_compatible_percent_encoding_unreserved_bytes[256 / 8]; |
||||
|
||||
/* Percent-encode a slice, returning the new slice (this cannot fail):
|
||||
unreserved_bytes is a bitfield indicating which bytes are considered |
||||
unreserved and thus do not need percent encoding */ |
||||
gpr_slice gpr_percent_encode_slice(gpr_slice slice, |
||||
const uint8_t *unreserved_bytes); |
||||
/* Percent-decode a slice, strictly.
|
||||
If the input is legal (contains no unreserved bytes, and legal % encodings), |
||||
returns true and sets *slice_out to the decoded slice. |
||||
If the input is not legal, returns false and leaves *slice_out untouched. |
||||
unreserved_bytes is a bitfield indicating which bytes are considered |
||||
unreserved and thus do not need percent encoding */ |
||||
bool gpr_strict_percent_decode_slice(gpr_slice slice_in, |
||||
const uint8_t *unreserved_bytes, |
||||
gpr_slice *slice_out); |
||||
/* Percent-decode a slice, permissively.
|
||||
If a % triplet can not be decoded, pass it through verbatim. |
||||
This cannot fail. */ |
||||
gpr_slice gpr_permissive_percent_decode_slice(gpr_slice slice_in); |
||||
|
||||
#endif /* GRPC_CORE_LIB_SUPPORT_PERCENT_ENCODING_H */ |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue