mirror of https://github.com/grpc/grpc.git
commit
a964cbafba
535 changed files with 20207 additions and 9124 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,8 @@ |
||||
Each version of gRPC gets a new description of what the 'g' stands for, since |
||||
we've never really been able to figure it out. |
||||
|
||||
Below is a list of already-used definitions (that should not be repeated in the |
||||
future), and the corresponding version numbers that used them: |
||||
|
||||
- 1.0 'g' stands for 'gRPC' |
||||
- 1.1 'g' stands for 'good' |
@ -0,0 +1,30 @@ |
||||
# HTTP to gRPC Status Code Mapping |
||||
|
||||
Since intermediaries are a common part of HTTP infrastructure some responses to |
||||
gRPC requests may be received that do not include the grpc-status header. In |
||||
some cases mapping error codes from an intermediary allows the gRPC client to |
||||
behave more appropriately to the error situation without overloading the |
||||
semantics of either error code. |
||||
|
||||
This table is to be used _only_ for clients that received a response that did |
||||
not include grpc-status. If grpc-status was provided, it _must_ be used. Servers |
||||
_must not_ use this table to determine an HTTP status code to use; the mappings |
||||
are neither symmetric nor 1-to-1. |
||||
|
||||
| HTTP Status Code | gRPC Status Code | |
||||
|----------------------------|--------------------| |
||||
| 400 Bad Request | INTERNAL | |
||||
| 401 Unauthorized | UNAUTHENTICATED | |
||||
| 403 Forbidden | PERMISSION\_DENIED | |
||||
| 404 Not Found | UNIMPLEMENTED | |
||||
| 429 Too Many Requests | UNAVAILABLE | |
||||
| 502 Bad Gateway | UNAVAILABLE | |
||||
| 503 Service Unavailable | UNAVAILABLE | |
||||
| 504 Gateway Timeout | UNAVAILABLE | |
||||
| _All other codes_ | UNKNOWN | |
||||
|
||||
Technically, 1xx should have the entire header skipped and a subsequent header |
||||
be read. See RFC 7540 §8.1. |
||||
|
||||
200 is UNKNOWN because there should be a grpc-status in case of truly OK |
||||
response. |
@ -0,0 +1,192 @@ |
||||
# gRPC Server Reflection Tutorial |
||||
|
||||
gRPC Server Reflection provides information about publicly-accessible gRPC |
||||
services on a server, and assists clients at runtime to construct RPC |
||||
requests and responses without precompiled service information. It is used by |
||||
gRPC CLI, which can be used to introspect server protos and send/receive test |
||||
RPCs. |
||||
|
||||
## Enable Server Reflection |
||||
|
||||
### Enable server reflection in C++ servers |
||||
|
||||
C++ Server Reflection is an add-on library, `libgrpc++_reflction`. To enable C++ |
||||
server reflection, you can link this library to your server binary. |
||||
|
||||
Some platforms (e.g. Ubuntu 11.10 onwards) only link in libraries that directly |
||||
contain symbols used by the application. On these platforms, LD flag |
||||
`--no-as-needed` is needed for for dynamic linking and `--whole-archive` is |
||||
needed for for static linking. |
||||
|
||||
This [Makefile](../examples/cpp/helloworld/Makefile#L37#L45) demonstrates |
||||
enabling c++ server reflection on Linux and MacOS. |
||||
|
||||
## Test services using Server Reflection |
||||
|
||||
After enabling Server Reflection in a server application, you can use gRPC CLI |
||||
to test its services. |
||||
|
||||
Instructions on how to use gRPC CLI can be found at |
||||
[command_line_tool.md](command_line_tool.md), or using `grpc_cli help` command. |
||||
|
||||
Here we use `examples/cpp/helloworld` as an example to show the use of gRPC |
||||
Server Reflection and gRPC CLI. First, we need to build gRPC CLI and setup an |
||||
example server with Server Reflection enabled. |
||||
|
||||
- Setup an example server |
||||
|
||||
Server Reflection has already been enabled in the |
||||
[Makefile](../examples/cpp/helloworld/Makefile) of the helloworld example. We |
||||
can simply make it and run the greeter_server. |
||||
|
||||
```sh |
||||
$ make -C examples/cpp/helloworld |
||||
$ examples/cpp/helloworld/greeter_server & |
||||
``` |
||||
|
||||
- Build gRPC CLI |
||||
|
||||
```sh |
||||
make grpc_cli |
||||
cd bins/opt |
||||
``` |
||||
|
||||
gRPC CLI binary `grpc_cli` can be found at `bins/opt/` folder. This tool is |
||||
still new and does not have a `make install` target yet. |
||||
|
||||
### List services |
||||
|
||||
`grpc_cli ls` command lists services and methods exposed at a given port |
||||
|
||||
- List all the services exposed at a given port |
||||
|
||||
```sh |
||||
$ grpc_cli ls localhost:50051 |
||||
``` |
||||
|
||||
output: |
||||
```sh |
||||
helloworld.Greeter |
||||
grpc.reflection.v1alpha.ServerReflection |
||||
``` |
||||
|
||||
- List one service with details |
||||
|
||||
`grpc_cli ls` command inspects a service given its full name (in the format of |
||||
\<package\>.\<service\>). It can print information with a long listing format |
||||
when `-l` flag is set. This flag can be used to get more details about a |
||||
service. |
||||
|
||||
```sh |
||||
$ grpc_cli ls localhost:50051 helloworld.Greeter -l |
||||
``` |
||||
|
||||
output: |
||||
```sh |
||||
filename: helloworld.proto |
||||
package: helloworld; |
||||
service Greeter { |
||||
rpc SayHello(helloworld.HelloRequest) returns (helloworld.HelloReply) {} |
||||
} |
||||
|
||||
``` |
||||
|
||||
### List methods |
||||
|
||||
- List one method with details |
||||
|
||||
`grpc_cli ls` command also inspects a method given its full name (in the |
||||
format of \<package\>.\<service\>.\<method\>). |
||||
|
||||
```sh |
||||
$ grpc_cli ls localhost:50051 helloworld.Greeter.SayHello -l |
||||
``` |
||||
|
||||
output: |
||||
```sh |
||||
rpc SayHello(helloworld.HelloRequest) returns (helloworld.HelloReply) {} |
||||
``` |
||||
|
||||
### Inspect message types |
||||
|
||||
We can use`grpc_cli type` command to inspect request/response types given the |
||||
full name of the type (in the format of \<package\>.\<type\>). |
||||
|
||||
- Get information about the request type |
||||
|
||||
```sh |
||||
$ grpc_cli type localhost:50051 helloworld.HelloRequest |
||||
``` |
||||
|
||||
output: |
||||
```sh |
||||
message HelloRequest { |
||||
optional string name = 1; |
||||
} |
||||
``` |
||||
|
||||
### Call a remote method |
||||
|
||||
We can send RPCs to a server and get responses using `grpc_cli call` command. |
||||
|
||||
- Call a unary method |
||||
|
||||
```sh |
||||
$ grpc_cli call localhost:50051 SayHello "name: 'gRPC CLI'" |
||||
``` |
||||
|
||||
output: |
||||
```sh |
||||
message: "Hello gRPC CLI" |
||||
``` |
||||
|
||||
## Use Server Reflection in a C++ client |
||||
|
||||
Server Reflection can be used by clients to get information about gRPC services |
||||
at runtime. We've provided a descriptor database called |
||||
[grpc::ProtoReflectionDescriptorDatabase](../test/cpp/util/proto_reflection_descriptor_database.h) |
||||
which implements the |
||||
[google::protobuf::DescriptorDatabase](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.descriptor_database#DescriptorDatabase) |
||||
interface. It manages the communication between clients and reflection services |
||||
and the storage of received information. Clients can use it as using a local |
||||
descriptor database. |
||||
|
||||
- To use Server Reflection with grpc::ProtoReflectionDescriptorDatabase, first |
||||
initialize an instance with a grpc::Channel. |
||||
|
||||
```c++ |
||||
std::shared_ptr<grpc::Channel> channel = |
||||
grpc::CreateChannel(server_address, server_cred); |
||||
grpc::ProtoReflectionDescriptorDatabase reflection_db(channel); |
||||
``` |
||||
|
||||
- Then use this instance to feed a |
||||
[google::protobuf::DescriptorPool](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.descriptor#DescriptorPool). |
||||
|
||||
```c++ |
||||
google::protobuf::DescriptorPool desc_pool(&reflection_db); |
||||
``` |
||||
|
||||
- Example usage of this descriptor pool |
||||
|
||||
* Get Service/method descriptors. |
||||
|
||||
```c++ |
||||
const google::protobuf::ServiceDescriptor* service_desc = |
||||
desc_pool->FindServiceByName("helloworld.Greeter"); |
||||
const google::protobuf::MethodDescriptor* method_desc = |
||||
desc_pool->FindMethodByName("helloworld.Greeter.SayHello"); |
||||
``` |
||||
|
||||
* Get message type descriptors. |
||||
|
||||
```c++ |
||||
const google::protobuf::Descriptor* request_desc = |
||||
desc_pool->FindMessageTypeByName("helloworld.HelloRequest"); |
||||
``` |
||||
|
||||
* Feed [google::protobuf::DynamicMessageFactory](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.dynamic_message#DynamicMessageFactory). |
||||
|
||||
```c++ |
||||
google::protobuf::DynamicMessageFactory(&desc_pool); |
||||
``` |
@ -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. |
@ -0,0 +1,4 @@ |
||||
The roots.pem file is periodically generated from: |
||||
https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt |
||||
using |
||||
https://github.com/agl/extract-nss-root-certs |
@ -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,47 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPCXX_IMPL_CODEGEN_STATUS_HELPER_H |
||||
#define GRPCXX_IMPL_CODEGEN_STATUS_HELPER_H |
||||
|
||||
#include <grpc++/impl/codegen/status.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
inline StatusCode GetCanonicalCode(const Status& status) { |
||||
return status.error_code(); |
||||
} |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_STATUS_HELPER_H
|
@ -1,122 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015-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_IMPL_CODEGEN_BYTE_BUFFER_H |
||||
#define GRPC_IMPL_CODEGEN_BYTE_BUFFER_H |
||||
|
||||
#include <grpc/impl/codegen/compression_types.h> |
||||
#include <grpc/impl/codegen/slice_buffer.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
typedef enum { |
||||
GRPC_BB_RAW |
||||
/* Future types may include GRPC_BB_PROTOBUF, etc. */ |
||||
} grpc_byte_buffer_type; |
||||
|
||||
struct grpc_byte_buffer { |
||||
void *reserved; |
||||
grpc_byte_buffer_type type; |
||||
union { |
||||
struct { |
||||
void *reserved[8]; |
||||
} reserved; |
||||
struct { |
||||
grpc_compression_algorithm compression; |
||||
gpr_slice_buffer slice_buffer; |
||||
} raw; |
||||
} data; |
||||
}; |
||||
typedef struct grpc_byte_buffer grpc_byte_buffer; |
||||
|
||||
/** Returns a RAW byte buffer instance over the given slices (up to \a nslices).
|
||||
* |
||||
* Increases the reference count for all \a slices processed. The user is |
||||
* responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/ |
||||
GRPCAPI grpc_byte_buffer *grpc_raw_byte_buffer_create(gpr_slice *slices, |
||||
size_t nslices); |
||||
|
||||
/** Returns a *compressed* RAW byte buffer instance over the given slices (up to
|
||||
* \a nslices). The \a compression argument defines the compression algorithm |
||||
* used to generate the data in \a slices. |
||||
* |
||||
* Increases the reference count for all \a slices processed. The user is |
||||
* responsible for invoking grpc_byte_buffer_destroy on the returned instance.*/ |
||||
GRPCAPI grpc_byte_buffer *grpc_raw_compressed_byte_buffer_create( |
||||
gpr_slice *slices, size_t nslices, grpc_compression_algorithm compression); |
||||
|
||||
/** Copies input byte buffer \a bb.
|
||||
* |
||||
* Increases the reference count of all the source slices. The user is |
||||
* responsible for calling grpc_byte_buffer_destroy over the returned copy. */ |
||||
GRPCAPI grpc_byte_buffer *grpc_byte_buffer_copy(grpc_byte_buffer *bb); |
||||
|
||||
/** Returns the size of the given byte buffer, in bytes. */ |
||||
GRPCAPI size_t grpc_byte_buffer_length(grpc_byte_buffer *bb); |
||||
|
||||
/** Destroys \a byte_buffer deallocating all its memory. */ |
||||
GRPCAPI void grpc_byte_buffer_destroy(grpc_byte_buffer *byte_buffer); |
||||
|
||||
/** Reader for byte buffers. Iterates over slices in the byte buffer */ |
||||
struct grpc_byte_buffer_reader; |
||||
typedef struct grpc_byte_buffer_reader grpc_byte_buffer_reader; |
||||
|
||||
/** Initialize \a reader to read over \a buffer.
|
||||
* Returns 1 upon success, 0 otherwise. */ |
||||
GRPCAPI int grpc_byte_buffer_reader_init(grpc_byte_buffer_reader *reader, |
||||
grpc_byte_buffer *buffer); |
||||
|
||||
/** Cleanup and destroy \a reader */ |
||||
GRPCAPI void grpc_byte_buffer_reader_destroy(grpc_byte_buffer_reader *reader); |
||||
|
||||
/** Updates \a slice with the next piece of data from from \a reader and returns
|
||||
* 1. Returns 0 at the end of the stream. Caller is responsible for calling |
||||
* gpr_slice_unref on the result. */ |
||||
GRPCAPI int grpc_byte_buffer_reader_next(grpc_byte_buffer_reader *reader, |
||||
gpr_slice *slice); |
||||
|
||||
/** Merge all data from \a reader into single slice */ |
||||
GRPCAPI gpr_slice |
||||
grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader); |
||||
|
||||
/** Returns a RAW byte buffer instance from the output of \a reader. */ |
||||
GRPCAPI grpc_byte_buffer *grpc_raw_byte_buffer_from_reader( |
||||
grpc_byte_buffer_reader *reader); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_BYTE_BUFFER_H */ |
@ -0,0 +1,140 @@ |
||||
/*
|
||||
* |
||||
* 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_IMPL_CODEGEN_GPR_TYPES_H |
||||
#define GRPC_IMPL_CODEGEN_GPR_TYPES_H |
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
#include <stddef.h> |
||||
#include <stdint.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* The clocks we support. */ |
||||
typedef enum { |
||||
/* Monotonic clock. Epoch undefined. Always moves forwards. */ |
||||
GPR_CLOCK_MONOTONIC = 0, |
||||
/* Realtime clock. May jump forwards or backwards. Settable by
|
||||
the system administrator. Has its epoch at 0:00:00 UTC 1 Jan 1970. */ |
||||
GPR_CLOCK_REALTIME, |
||||
/* CPU cycle time obtained by rdtsc instruction on x86 platforms. Epoch
|
||||
undefined. Degrades to GPR_CLOCK_REALTIME on other platforms. */ |
||||
GPR_CLOCK_PRECISE, |
||||
/* Unmeasurable clock type: no base, created by taking the difference
|
||||
between two times */ |
||||
GPR_TIMESPAN |
||||
} gpr_clock_type; |
||||
|
||||
/* Analogous to struct timespec. On some machines, absolute times may be in
|
||||
* local time. */ |
||||
typedef struct gpr_timespec { |
||||
int64_t tv_sec; |
||||
int32_t tv_nsec; |
||||
/** Against which clock was this time measured? (or GPR_TIMESPAN if
|
||||
this is a relative time meaure) */ |
||||
gpr_clock_type clock_type; |
||||
} gpr_timespec; |
||||
|
||||
/* Slice API
|
||||
|
||||
A slice represents a contiguous reference counted array of bytes. |
||||
It is cheap to take references to a slice, and it is cheap to create a |
||||
slice pointing to a subset of another slice. |
||||
|
||||
The data-structure for slices is exposed here to allow non-gpr code to |
||||
build slices from whatever data they have available. |
||||
|
||||
When defining interfaces that handle slices, care should be taken to define |
||||
reference ownership semantics (who should call unref?) and mutability |
||||
constraints (is the callee allowed to modify the slice?) */ |
||||
|
||||
/* Reference count container for gpr_slice. Contains function pointers to
|
||||
increment and decrement reference counts. Implementations should cleanup |
||||
when the reference count drops to zero. |
||||
Typically client code should not touch this, and use gpr_slice_malloc, |
||||
gpr_slice_new, or gpr_slice_new_with_len instead. */ |
||||
typedef struct gpr_slice_refcount { |
||||
void (*ref)(void *); |
||||
void (*unref)(void *); |
||||
} gpr_slice_refcount; |
||||
|
||||
#define GPR_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(uint8_t *) - 1) |
||||
|
||||
/* A gpr_slice s, if initialized, represents the byte range
|
||||
s.bytes[0..s.length-1]. |
||||
|
||||
It can have an associated ref count which has a destruction routine to be run |
||||
when the ref count reaches zero (see gpr_slice_new() and grp_slice_unref()). |
||||
Multiple gpr_slice values may share a ref count. |
||||
|
||||
If the slice does not have a refcount, it represents an inlined small piece |
||||
of data that is copied by value. */ |
||||
typedef struct gpr_slice { |
||||
struct gpr_slice_refcount *refcount; |
||||
union { |
||||
struct { |
||||
uint8_t *bytes; |
||||
size_t length; |
||||
} refcounted; |
||||
struct { |
||||
uint8_t length; |
||||
uint8_t bytes[GPR_SLICE_INLINED_SIZE]; |
||||
} inlined; |
||||
} data; |
||||
} gpr_slice; |
||||
|
||||
#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 8 |
||||
|
||||
/* Represents an expandable array of slices, to be interpreted as a
|
||||
single item. */ |
||||
typedef struct { |
||||
/* slices in the array */ |
||||
gpr_slice *slices; |
||||
/* the number of slices in the array */ |
||||
size_t count; |
||||
/* the number of slices allocated in the array */ |
||||
size_t capacity; |
||||
/* the combined length of all slices in the array */ |
||||
size_t length; |
||||
/* inlined elements to avoid allocations */ |
||||
gpr_slice inlined[GRPC_SLICE_BUFFER_INLINE_ELEMENTS]; |
||||
} gpr_slice_buffer; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_GPR_TYPES_H */ |
@ -1,118 +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_IMPL_CODEGEN_LOG_H |
||||
#define GRPC_IMPL_CODEGEN_LOG_H |
||||
|
||||
#include <inttypes.h> |
||||
#include <stdarg.h> |
||||
#include <stdlib.h> /* for abort() */ |
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
#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 */ |
||||
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, ...) GPRC_PRINT_FORMAT_CHECK(4, 5); |
||||
|
||||
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(); |
||||
|
||||
/* Log overrides: applications can use this API to intercept logging calls
|
||||
and use their own implementations */ |
||||
|
||||
typedef struct { |
||||
const char *file; |
||||
int line; |
||||
gpr_log_severity severity; |
||||
const char *message; |
||||
} 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 (!(x)) { \
|
||||
gpr_log(GPR_ERROR, "assertion failed: %s", #x); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0) |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_LOG_H */ |
@ -1,104 +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_IMPL_CODEGEN_SLICE_BUFFER_H |
||||
#define GRPC_IMPL_CODEGEN_SLICE_BUFFER_H |
||||
|
||||
#include <grpc/impl/codegen/slice.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 8 |
||||
|
||||
/* Represents an expandable array of slices, to be interpreted as a
|
||||
single item. */ |
||||
typedef struct { |
||||
/* slices in the array */ |
||||
gpr_slice *slices; |
||||
/* the number of slices in the array */ |
||||
size_t count; |
||||
/* the number of slices allocated in the array */ |
||||
size_t capacity; |
||||
/* the combined length of all slices in the array */ |
||||
size_t length; |
||||
/* inlined elements to avoid allocations */ |
||||
gpr_slice inlined[GRPC_SLICE_BUFFER_INLINE_ELEMENTS]; |
||||
} gpr_slice_buffer; |
||||
|
||||
/* initialize a slice buffer */ |
||||
GPRAPI void gpr_slice_buffer_init(gpr_slice_buffer *sb); |
||||
/* destroy a slice buffer - unrefs any held elements */ |
||||
GPRAPI void gpr_slice_buffer_destroy(gpr_slice_buffer *sb); |
||||
/* Add an element to a slice buffer - takes ownership of the slice.
|
||||
This function is allowed to concatenate the passed in slice to the end of |
||||
some other slice if desired by the slice buffer. */ |
||||
GPRAPI void gpr_slice_buffer_add(gpr_slice_buffer *sb, gpr_slice slice); |
||||
/* add an element to a slice buffer - takes ownership of the slice and returns
|
||||
the index of the slice. |
||||
Guarantees that the slice will not be concatenated at the end of another |
||||
slice (i.e. the data for this slice will begin at the first byte of the |
||||
slice at the returned index in sb->slices) |
||||
The implementation MAY decide to concatenate data at the end of a small |
||||
slice added in this fashion. */ |
||||
GPRAPI size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, |
||||
gpr_slice slice); |
||||
GPRAPI void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, |
||||
size_t n); |
||||
/* add a very small (less than 8 bytes) amount of data to the end of a slice
|
||||
buffer: returns a pointer into which to add the data */ |
||||
GPRAPI uint8_t *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t len); |
||||
/* pop the last buffer, but don't unref it */ |
||||
GPRAPI void gpr_slice_buffer_pop(gpr_slice_buffer *sb); |
||||
/* clear a slice buffer, unref all elements */ |
||||
GPRAPI void gpr_slice_buffer_reset_and_unref(gpr_slice_buffer *sb); |
||||
/* swap the contents of two slice buffers */ |
||||
GPRAPI void gpr_slice_buffer_swap(gpr_slice_buffer *a, gpr_slice_buffer *b); |
||||
/* move all of the elements of src into dst */ |
||||
GPRAPI void gpr_slice_buffer_move_into(gpr_slice_buffer *src, |
||||
gpr_slice_buffer *dst); |
||||
/* remove n bytes from the end of a slice buffer */ |
||||
GPRAPI void gpr_slice_buffer_trim_end(gpr_slice_buffer *src, size_t n, |
||||
gpr_slice_buffer *garbage); |
||||
/* move the first n bytes of src into dst */ |
||||
GPRAPI void gpr_slice_buffer_move_first(gpr_slice_buffer *src, size_t n, |
||||
gpr_slice_buffer *dst); |
||||
/* take the first slice in the slice buffer */ |
||||
GPRAPI gpr_slice gpr_slice_buffer_take_first(gpr_slice_buffer *src); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_SLICE_BUFFER_H */ |
@ -1,130 +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_IMPL_CODEGEN_TIME_H |
||||
#define GRPC_IMPL_CODEGEN_TIME_H |
||||
/* Time support.
|
||||
We use gpr_timespec, which is analogous to struct timespec. On some |
||||
machines, absolute times may be in local time. */ |
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
#include <stddef.h> |
||||
#include <time.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/* The clocks we support. */ |
||||
typedef enum { |
||||
/* Monotonic clock. Epoch undefined. Always moves forwards. */ |
||||
GPR_CLOCK_MONOTONIC = 0, |
||||
/* Realtime clock. May jump forwards or backwards. Settable by
|
||||
the system administrator. Has its epoch at 0:00:00 UTC 1 Jan 1970. */ |
||||
GPR_CLOCK_REALTIME, |
||||
/* CPU cycle time obtained by rdtsc instruction on x86 platforms. Epoch
|
||||
undefined. Degrades to GPR_CLOCK_REALTIME on other platforms. */ |
||||
GPR_CLOCK_PRECISE, |
||||
/* Unmeasurable clock type: no base, created by taking the difference
|
||||
between two times */ |
||||
GPR_TIMESPAN |
||||
} gpr_clock_type; |
||||
|
||||
typedef struct gpr_timespec { |
||||
int64_t tv_sec; |
||||
int32_t tv_nsec; |
||||
/** Against which clock was this time measured? (or GPR_TIMESPAN if
|
||||
this is a relative time meaure) */ |
||||
gpr_clock_type clock_type; |
||||
} gpr_timespec; |
||||
|
||||
/* Time constants. */ |
||||
GPRAPI gpr_timespec |
||||
gpr_time_0(gpr_clock_type type); /* The zero time interval. */ |
||||
GPRAPI gpr_timespec gpr_inf_future(gpr_clock_type type); /* The far future */ |
||||
GPRAPI gpr_timespec gpr_inf_past(gpr_clock_type type); /* The far past. */ |
||||
|
||||
#define GPR_MS_PER_SEC 1000 |
||||
#define GPR_US_PER_SEC 1000000 |
||||
#define GPR_NS_PER_SEC 1000000000 |
||||
#define GPR_NS_PER_MS 1000000 |
||||
#define GPR_NS_PER_US 1000 |
||||
#define GPR_US_PER_MS 1000 |
||||
|
||||
/* initialize time subsystem */ |
||||
GPRAPI void gpr_time_init(void); |
||||
|
||||
/* Return the current time measured from the given clocks epoch. */ |
||||
GPRAPI gpr_timespec gpr_now(gpr_clock_type clock); |
||||
|
||||
/* Convert a timespec from one clock to another */ |
||||
GPRAPI gpr_timespec gpr_convert_clock_type(gpr_timespec t, |
||||
gpr_clock_type target_clock); |
||||
|
||||
/* Return -ve, 0, or +ve according to whether a < b, a == b, or a > b
|
||||
respectively. */ |
||||
GPRAPI int gpr_time_cmp(gpr_timespec a, gpr_timespec b); |
||||
|
||||
GPRAPI gpr_timespec gpr_time_max(gpr_timespec a, gpr_timespec b); |
||||
GPRAPI gpr_timespec gpr_time_min(gpr_timespec a, gpr_timespec b); |
||||
|
||||
/* Add and subtract times. Calculations saturate at infinities. */ |
||||
GPRAPI gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b); |
||||
GPRAPI gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b); |
||||
|
||||
/* Return a timespec representing a given number of time units. INT64_MIN is
|
||||
interpreted as gpr_inf_past, and INT64_MAX as gpr_inf_future. */ |
||||
GPRAPI gpr_timespec gpr_time_from_micros(int64_t x, gpr_clock_type clock_type); |
||||
GPRAPI gpr_timespec gpr_time_from_nanos(int64_t x, gpr_clock_type clock_type); |
||||
GPRAPI gpr_timespec gpr_time_from_millis(int64_t x, gpr_clock_type clock_type); |
||||
GPRAPI gpr_timespec gpr_time_from_seconds(int64_t x, gpr_clock_type clock_type); |
||||
GPRAPI gpr_timespec gpr_time_from_minutes(int64_t x, gpr_clock_type clock_type); |
||||
GPRAPI gpr_timespec gpr_time_from_hours(int64_t x, gpr_clock_type clock_type); |
||||
|
||||
GPRAPI int32_t gpr_time_to_millis(gpr_timespec timespec); |
||||
|
||||
/* Return 1 if two times are equal or within threshold of each other,
|
||||
0 otherwise */ |
||||
GPRAPI int gpr_time_similar(gpr_timespec a, gpr_timespec b, |
||||
gpr_timespec threshold); |
||||
|
||||
/* Sleep until at least 'until' - an absolute timeout */ |
||||
GPRAPI void gpr_sleep_until(gpr_timespec until); |
||||
|
||||
GPRAPI double gpr_timespec_to_micros(gpr_timespec t); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_TIME_H */ |
@ -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 |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue