parent
f3ddb7c55a
commit
08a0a3306e
44 changed files with 1311 additions and 743 deletions
@ -0,0 +1,51 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPCXX_IMPL_CODEGEN_CALL_HOOK_H |
||||
#define GRPCXX_IMPL_CODEGEN_CALL_HOOK_H |
||||
|
||||
namespace grpc { |
||||
|
||||
class CallOpSetInterface; |
||||
class Call; |
||||
|
||||
/// Channel and Server implement this to allow them to hook performing ops
|
||||
class CallHook { |
||||
public: |
||||
virtual ~CallHook() {} |
||||
virtual void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) = 0; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_CALL_HOOK_H
|
@ -0,0 +1,52 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPCXX_COMPLETION_QUEUE_TAG_H |
||||
#define GRPCXX_COMPLETION_QUEUE_TAG_H |
||||
|
||||
namespace grpc { |
||||
|
||||
/// An interface allowing implementors to process and filter event tags.
|
||||
class CompletionQueueTag { |
||||
public: |
||||
virtual ~CompletionQueueTag() {} |
||||
// Called prior to returning from Next(), return value is the status of the
|
||||
// operation (return status is the default thing to do). If this function
|
||||
// returns false, the tag is dropped and not returned from the completion
|
||||
// queue
|
||||
virtual bool FinalizeResult(void** tag, bool* status) = 0; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_COMPLETION_QUEUE_TAG_H
|
@ -0,0 +1,116 @@ |
||||
/*
|
||||
* |
||||
* 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_CONFIG_H |
||||
#define GRPCXX_IMPL_CODEGEN_CONFIG_H |
||||
|
||||
#if !defined(GRPC_NO_AUTODETECT_PLATFORM) |
||||
|
||||
#ifdef _MSC_VER |
||||
// Visual Studio 2010 is 1600.
|
||||
#if _MSC_VER < 1600 |
||||
#error "gRPC is only supported with Visual Studio starting at 2010" |
||||
// Visual Studio 2013 is 1800.
|
||||
#elif _MSC_VER < 1800 |
||||
#define GRPC_CXX0X_NO_FINAL 1 |
||||
#define GRPC_CXX0X_NO_OVERRIDE 1 |
||||
#define GRPC_CXX0X_NO_CHRONO 1 |
||||
#define GRPC_CXX0X_NO_THREAD 1 |
||||
#endif |
||||
#endif // Visual Studio
|
||||
|
||||
#ifndef __clang__ |
||||
#ifdef __GNUC__ |
||||
// nullptr was added in gcc 4.6
|
||||
#if (__GNUC__ * 100 + __GNUC_MINOR__ < 406) |
||||
#define GRPC_CXX0X_NO_NULLPTR 1 |
||||
#endif |
||||
// final and override were added in gcc 4.7
|
||||
#if (__GNUC__ * 100 + __GNUC_MINOR__ < 407) |
||||
#define GRPC_CXX0X_NO_FINAL 1 |
||||
#define GRPC_CXX0X_NO_OVERRIDE 1 |
||||
#endif |
||||
#endif |
||||
#endif |
||||
|
||||
#endif |
||||
|
||||
#ifdef GRPC_CXX0X_NO_FINAL |
||||
#define GRPC_FINAL |
||||
#else |
||||
#define GRPC_FINAL final |
||||
#endif |
||||
|
||||
#ifdef GRPC_CXX0X_NO_OVERRIDE |
||||
#define GRPC_OVERRIDE |
||||
#else |
||||
#define GRPC_OVERRIDE override |
||||
#endif |
||||
|
||||
#ifdef GRPC_CXX0X_NO_NULLPTR |
||||
#include <memory> |
||||
namespace grpc { |
||||
const class { |
||||
public: |
||||
template <class T> |
||||
operator T *() const { |
||||
return static_cast<T *>(0); |
||||
} |
||||
template <class T> |
||||
operator std::unique_ptr<T>() const { |
||||
return std::unique_ptr<T>(static_cast<T *>(0)); |
||||
} |
||||
template <class T> |
||||
operator std::shared_ptr<T>() const { |
||||
return std::shared_ptr<T>(static_cast<T *>(0)); |
||||
} |
||||
operator bool() const { return false; } |
||||
|
||||
private: |
||||
void operator&() const = delete; |
||||
} nullptr = {}; |
||||
} |
||||
#endif |
||||
|
||||
#ifndef GRPC_CUSTOM_STRING |
||||
#include <string> |
||||
#define GRPC_CUSTOM_STRING std::string |
||||
#endif |
||||
|
||||
namespace grpc { |
||||
|
||||
typedef GRPC_CUSTOM_STRING string; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_CONFIG_H
|
@ -0,0 +1,76 @@ |
||||
/*
|
||||
* |
||||
* 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_H |
||||
#define GRPCXX_IMPL_CODEGEN_STATUS_H |
||||
|
||||
#include <grpc++/impl/codegen/config.h> |
||||
#include <grpc++/impl/codegen/status_code_enum.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
/// Did it work? If it didn't, why?
|
||||
///
|
||||
/// See \a grpc::StatusCode for details on the available code and their meaning.
|
||||
class Status { |
||||
public: |
||||
/// Construct an OK instance.
|
||||
Status() : code_(StatusCode::OK) {} |
||||
|
||||
/// Construct an instance with associated \a code and \a details (also
|
||||
// referred to as "error_message").
|
||||
Status(StatusCode code, const grpc::string& details) |
||||
: code_(code), details_(details) {} |
||||
|
||||
// Pre-defined special status objects.
|
||||
/// An OK pre-defined instance.
|
||||
static const Status& OK; |
||||
/// A CANCELLED pre-defined instance.
|
||||
static const Status& CANCELLED; |
||||
|
||||
/// Return the instance's error code.
|
||||
StatusCode error_code() const { return code_; } |
||||
/// Return the instance's error message.
|
||||
grpc::string error_message() const { return details_; } |
||||
|
||||
/// Is the status OK?
|
||||
bool ok() const { return code_ == StatusCode::OK; } |
||||
|
||||
private: |
||||
StatusCode code_; |
||||
grpc::string details_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_STATUS_H
|
@ -0,0 +1,152 @@ |
||||
/*
|
||||
* |
||||
* 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_CODE_ENUM_H |
||||
#define GRPCXX_IMPL_CODEGEN_STATUS_CODE_ENUM_H |
||||
|
||||
namespace grpc { |
||||
|
||||
enum StatusCode { |
||||
/// Not an error; returned on success.
|
||||
OK = 0, |
||||
|
||||
/// The operation was cancelled (typically by the caller).
|
||||
CANCELLED = 1, |
||||
|
||||
/// Unknown error. An example of where this error may be returned is if a
|
||||
/// Status value received from another address space belongs to an error-space
|
||||
/// that is not known in this address space. Also errors raised by APIs that
|
||||
/// do not return enough error information may be converted to this error.
|
||||
UNKNOWN = 2, |
||||
|
||||
/// Client specified an invalid argument. Note that this differs from
|
||||
/// FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are
|
||||
/// problematic regardless of the state of the system (e.g., a malformed file
|
||||
/// name).
|
||||
INVALID_ARGUMENT = 3, |
||||
|
||||
/// Deadline expired before operation could complete. For operations that
|
||||
/// change the state of the system, this error may be returned even if the
|
||||
/// operation has completed successfully. For example, a successful response
|
||||
/// from a server could have been delayed long enough for the deadline to
|
||||
/// expire.
|
||||
DEADLINE_EXCEEDED = 4, |
||||
|
||||
/// Some requested entity (e.g., file or directory) was not found.
|
||||
NOT_FOUND = 5, |
||||
|
||||
/// Some entity that we attempted to create (e.g., file or directory) already
|
||||
/// exists.
|
||||
ALREADY_EXISTS = 6, |
||||
|
||||
/// The caller does not have permission to execute the specified operation.
|
||||
/// PERMISSION_DENIED must not be used for rejections caused by exhausting
|
||||
/// some resource (use RESOURCE_EXHAUSTED instead for those errors).
|
||||
/// PERMISSION_DENIED must not be used if the caller can not be identified
|
||||
/// (use UNAUTHENTICATED instead for those errors).
|
||||
PERMISSION_DENIED = 7, |
||||
|
||||
/// The request does not have valid authentication credentials for the
|
||||
/// operation.
|
||||
UNAUTHENTICATED = 16, |
||||
|
||||
/// Some resource has been exhausted, perhaps a per-user quota, or perhaps the
|
||||
/// entire file system is out of space.
|
||||
RESOURCE_EXHAUSTED = 8, |
||||
|
||||
/// Operation was rejected because the system is not in a state required for
|
||||
/// the operation's execution. For example, directory to be deleted may be
|
||||
/// non-empty, an rmdir operation is applied to a non-directory, etc.
|
||||
///
|
||||
/// A litmus test that may help a service implementor in deciding
|
||||
/// between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
|
||||
/// (a) Use UNAVAILABLE if the client can retry just the failing call.
|
||||
/// (b) Use ABORTED if the client should retry at a higher-level
|
||||
/// (e.g., restarting a read-modify-write sequence).
|
||||
/// (c) Use FAILED_PRECONDITION if the client should not retry until
|
||||
/// the system state has been explicitly fixed. E.g., if an "rmdir"
|
||||
/// fails because the directory is non-empty, FAILED_PRECONDITION
|
||||
/// should be returned since the client should not retry unless
|
||||
/// they have first fixed up the directory by deleting files from it.
|
||||
/// (d) Use FAILED_PRECONDITION if the client performs conditional
|
||||
/// REST Get/Update/Delete on a resource and the resource on the
|
||||
/// server does not match the condition. E.g., conflicting
|
||||
/// read-modify-write on the same resource.
|
||||
FAILED_PRECONDITION = 9, |
||||
|
||||
/// The operation was aborted, typically due to a concurrency issue like
|
||||
/// sequencer check failures, transaction aborts, etc.
|
||||
///
|
||||
/// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
|
||||
/// and UNAVAILABLE.
|
||||
ABORTED = 10, |
||||
|
||||
/// Operation was attempted past the valid range. E.g., seeking or reading
|
||||
/// past end of file.
|
||||
///
|
||||
/// Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed
|
||||
/// if the system state changes. For example, a 32-bit file system will
|
||||
/// generate INVALID_ARGUMENT if asked to read at an offset that is not in the
|
||||
/// range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to read from
|
||||
/// an offset past the current file size.
|
||||
///
|
||||
/// There is a fair bit of overlap between FAILED_PRECONDITION and
|
||||
/// OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error)
|
||||
/// when it applies so that callers who are iterating through a space can
|
||||
/// easily look for an OUT_OF_RANGE error to detect when they are done.
|
||||
OUT_OF_RANGE = 11, |
||||
|
||||
/// Operation is not implemented or not supported/enabled in this service.
|
||||
UNIMPLEMENTED = 12, |
||||
|
||||
/// Internal errors. Means some invariants expected by underlying System has
|
||||
/// been broken. If you see one of these errors, Something is very broken.
|
||||
INTERNAL = 13, |
||||
|
||||
/// The service is currently unavailable. This is a most likely a transient
|
||||
/// condition and may be corrected by retrying with a backoff.
|
||||
///
|
||||
/// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
|
||||
/// and UNAVAILABLE.
|
||||
UNAVAILABLE = 14, |
||||
|
||||
/// Unrecoverable data loss or corruption.
|
||||
DATA_LOSS = 15, |
||||
|
||||
/// Force users to include a default branch:
|
||||
DO_NOT_USE = -1 |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_STATUS_CODE_ENUM_H
|
@ -0,0 +1,111 @@ |
||||
/*
|
||||
* |
||||
* 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 GRPCXX_IMPL_CODEGEN_TIME_H |
||||
#define GRPCXX_IMPL_CODEGEN_TIME_H |
||||
|
||||
#include <grpc++/impl/codegen/config.h> |
||||
#include <grpc/impl/codegen/time.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
/* If you are trying to use CompletionQueue::AsyncNext with a time class that
|
||||
isn't either gpr_timespec or std::chrono::system_clock::time_point, you |
||||
will most likely be looking at this comment as your compiler will have |
||||
fired an error below. In order to fix this issue, you have two potential |
||||
solutions: |
||||
|
||||
1. Use gpr_timespec or std::chrono::system_clock::time_point instead |
||||
2. Specialize the TimePoint class with whichever time class that you |
||||
want to use here. See below for two examples of how to do this. |
||||
*/ |
||||
|
||||
template <typename T> |
||||
class TimePoint { |
||||
public: |
||||
TimePoint(const T& time) { you_need_a_specialization_of_TimePoint(); } |
||||
gpr_timespec raw_time() { |
||||
gpr_timespec t; |
||||
return t; |
||||
} |
||||
|
||||
private: |
||||
void you_need_a_specialization_of_TimePoint(); |
||||
}; |
||||
|
||||
template <> |
||||
class TimePoint<gpr_timespec> { |
||||
public: |
||||
TimePoint(const gpr_timespec& time) : time_(time) {} |
||||
gpr_timespec raw_time() { return time_; } |
||||
|
||||
private: |
||||
gpr_timespec time_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#ifndef GRPC_CXX0X_NO_CHRONO |
||||
|
||||
#include <chrono> |
||||
|
||||
#include <grpc/support/time.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
// from and to should be absolute time.
|
||||
void Timepoint2Timespec(const std::chrono::system_clock::time_point& from, |
||||
gpr_timespec* to); |
||||
void TimepointHR2Timespec( |
||||
const std::chrono::high_resolution_clock::time_point& from, |
||||
gpr_timespec* to); |
||||
|
||||
std::chrono::system_clock::time_point Timespec2Timepoint(gpr_timespec t); |
||||
|
||||
template <> |
||||
class TimePoint<std::chrono::system_clock::time_point> { |
||||
public: |
||||
TimePoint(const std::chrono::system_clock::time_point& time) { |
||||
Timepoint2Timespec(time, &time_); |
||||
} |
||||
gpr_timespec raw_time() const { return time_; } |
||||
|
||||
private: |
||||
gpr_timespec time_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // !GRPC_CXX0X_NO_CHRONO
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_TIME_H
|
@ -0,0 +1,59 @@ |
||||
/*
|
||||
* |
||||
* 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_CONNECTIVITY_STATE_H |
||||
#define GRPC_IMPL_CODEGEN_CONNECTIVITY_STATE_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/** Connectivity state of a channel. */ |
||||
typedef enum { |
||||
/** channel is idle */ |
||||
GRPC_CHANNEL_IDLE, |
||||
/** channel is connecting */ |
||||
GRPC_CHANNEL_CONNECTING, |
||||
/** channel is ready for work */ |
||||
GRPC_CHANNEL_READY, |
||||
/** channel has seen a failure but expects to recover */ |
||||
GRPC_CHANNEL_TRANSIENT_FAILURE, |
||||
/** channel has seen a failure that it cannot recover from */ |
||||
GRPC_CHANNEL_FATAL_FAILURE |
||||
} grpc_connectivity_state; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_CONNECTIVITY_STATE_H */ |
@ -0,0 +1,340 @@ |
||||
/*
|
||||
* |
||||
* 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_PORT_PLATFORM_H |
||||
#define GRPC_IMPL_CODEGEN_PORT_PLATFORM_H |
||||
|
||||
/* Get windows.h included everywhere (we need it) */ |
||||
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) |
||||
#ifndef WIN32_LEAN_AND_MEAN |
||||
#define GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
||||
#define WIN32_LEAN_AND_MEAN |
||||
#endif /* WIN32_LEAN_AND_MEAN */ |
||||
|
||||
#ifndef NOMINMAX |
||||
#define GRPC_NOMINMX_WAS_NOT_DEFINED |
||||
#define NOMINMAX |
||||
#endif /* NOMINMAX */ |
||||
|
||||
#ifndef _WIN32_WINNT |
||||
#error \ |
||||
"Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" |
||||
#else /* !defined(_WIN32_WINNT) */ |
||||
#if (_WIN32_WINNT < 0x0600) |
||||
#error \ |
||||
"Please compile grpc with _WIN32_WINNT of at least 0x600 (aka Windows Vista)" |
||||
#endif /* _WIN32_WINNT < 0x0600 */ |
||||
#endif /* defined(_WIN32_WINNT) */ |
||||
|
||||
#include <windows.h> |
||||
|
||||
#ifdef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
||||
#undef GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED |
||||
#undef WIN32_LEAN_AND_MEAN |
||||
#endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ |
||||
|
||||
#ifdef GRPC_NOMINMAX_WAS_NOT_DEFINED |
||||
#undef GRPC_NOMINMAX_WAS_NOT_DEFINED |
||||
#undef NOMINMAX |
||||
#endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */ |
||||
#endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \ |
||||
defined(WIN32) */ |
||||
|
||||
/* Override this file with one for your platform if you need to redefine
|
||||
things. */ |
||||
|
||||
#if !defined(GPR_NO_AUTODETECT_PLATFORM) |
||||
#if defined(_WIN64) || defined(WIN64) |
||||
#define GPR_PLATFORM_STRING "windows" |
||||
#define GPR_WIN32 1 |
||||
#define GPR_ARCH_64 1 |
||||
#define GPR_GETPID_IN_PROCESS_H 1 |
||||
#define GPR_WINSOCK_SOCKET 1 |
||||
#ifdef __GNUC__ |
||||
#define GPR_GCC_ATOMIC 1 |
||||
#define GPR_GCC_TLS 1 |
||||
#else |
||||
#define GPR_WIN32_ATOMIC 1 |
||||
#define GPR_MSVC_TLS 1 |
||||
#endif |
||||
#define GPR_WINDOWS_CRASH_HANDLER 1 |
||||
#elif defined(_WIN32) || defined(WIN32) |
||||
#define GPR_PLATFORM_STRING "windows" |
||||
#define GPR_ARCH_32 1 |
||||
#define GPR_WIN32 1 |
||||
#define GPR_GETPID_IN_PROCESS_H 1 |
||||
#define GPR_WINSOCK_SOCKET 1 |
||||
#ifdef __GNUC__ |
||||
#define GPR_GCC_ATOMIC 1 |
||||
#define GPR_GCC_TLS 1 |
||||
#else |
||||
#define GPR_WIN32_ATOMIC 1 |
||||
#define GPR_MSVC_TLS 1 |
||||
#endif |
||||
#define GPR_WINDOWS_CRASH_HANDLER 1 |
||||
#elif defined(ANDROID) || defined(__ANDROID__) |
||||
#define GPR_PLATFORM_STRING "android" |
||||
#define GPR_ANDROID 1 |
||||
#define GPR_ARCH_32 1 |
||||
#define GPR_CPU_LINUX 1 |
||||
#define GPR_GCC_SYNC 1 |
||||
#define GPR_GCC_TLS 1 |
||||
#define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
||||
#define GPR_POSIX_WAKEUP_FD 1 |
||||
#define GPR_LINUX_EVENTFD 1 |
||||
#define GPR_POSIX_SOCKET 1 |
||||
#define GPR_POSIX_SOCKETADDR 1 |
||||
#define GPR_POSIX_SOCKETUTILS 1 |
||||
#define GPR_POSIX_ENV 1 |
||||
#define GPR_POSIX_FILE 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 |
||||
#define GPR_HAVE_MSG_NOSIGNAL 1 |
||||
#elif defined(__linux__) |
||||
#define GPR_POSIX_CRASH_HANDLER 1 |
||||
#define GPR_PLATFORM_STRING "linux" |
||||
#ifndef _BSD_SOURCE |
||||
#define _BSD_SOURCE |
||||
#endif |
||||
#ifndef _DEFAULT_SOURCE |
||||
#define _DEFAULT_SOURCE |
||||
#endif |
||||
#ifndef _GNU_SOURCE |
||||
#define _GNU_SOURCE |
||||
#endif |
||||
#include <features.h> |
||||
#define GPR_CPU_LINUX 1 |
||||
#define GPR_GCC_ATOMIC 1 |
||||
#define GPR_GCC_TLS 1 |
||||
#define GPR_LINUX 1 |
||||
#define GPR_LINUX_MULTIPOLL_WITH_EPOLL 1 |
||||
#define GPR_POSIX_WAKEUP_FD 1 |
||||
#define GPR_POSIX_SOCKET 1 |
||||
#define GPR_POSIX_SOCKETADDR 1 |
||||
#ifdef __GLIBC_PREREQ |
||||
#if __GLIBC_PREREQ(2, 9) |
||||
#define GPR_LINUX_EVENTFD 1 |
||||
#endif |
||||
#if __GLIBC_PREREQ(2, 10) |
||||
#define GPR_LINUX_SOCKETUTILS 1 |
||||
#endif |
||||
#if __GLIBC_PREREQ(2, 17) |
||||
#define GPR_LINUX_ENV 1 |
||||
#endif |
||||
#endif |
||||
#ifndef GPR_LINUX_EVENTFD |
||||
#define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
||||
#endif |
||||
#ifndef GPR_LINUX_SOCKETUTILS |
||||
#define GPR_POSIX_SOCKETUTILS |
||||
#endif |
||||
#ifndef GPR_LINUX_ENV |
||||
#define GPR_POSIX_ENV 1 |
||||
#endif |
||||
#define GPR_POSIX_FILE 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 |
||||
#define GPR_HAVE_MSG_NOSIGNAL 1 |
||||
#ifdef _LP64 |
||||
#define GPR_ARCH_64 1 |
||||
#else /* _LP64 */ |
||||
#define GPR_ARCH_32 1 |
||||
#endif /* _LP64 */ |
||||
#elif defined(__APPLE__) |
||||
#include <TargetConditionals.h> |
||||
#ifndef _BSD_SOURCE |
||||
#define _BSD_SOURCE |
||||
#endif |
||||
#define GPR_MSG_IOVLEN_TYPE int |
||||
#if TARGET_OS_IPHONE |
||||
#define GPR_FORBID_UNREACHABLE_CODE 1 |
||||
#define GPR_PLATFORM_STRING "ios" |
||||
#define GPR_CPU_IPHONE 1 |
||||
#define GPR_PTHREAD_TLS 1 |
||||
#else /* TARGET_OS_IPHONE */ |
||||
#define GPR_PLATFORM_STRING "osx" |
||||
#define GPR_CPU_POSIX 1 |
||||
#define GPR_GCC_TLS 1 |
||||
#define GPR_POSIX_CRASH_HANDLER 1 |
||||
#endif |
||||
#define GPR_GCC_ATOMIC 1 |
||||
#define GPR_POSIX_LOG 1 |
||||
#define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
||||
#define GPR_POSIX_WAKEUP_FD 1 |
||||
#define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
||||
#define GPR_POSIX_SOCKET 1 |
||||
#define GPR_POSIX_SOCKETADDR 1 |
||||
#define GPR_POSIX_SOCKETUTILS 1 |
||||
#define GPR_POSIX_ENV 1 |
||||
#define GPR_POSIX_FILE 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 |
||||
#define GPR_HAVE_SO_NOSIGPIPE 1 |
||||
#ifdef _LP64 |
||||
#define GPR_ARCH_64 1 |
||||
#else /* _LP64 */ |
||||
#define GPR_ARCH_32 1 |
||||
#endif /* _LP64 */ |
||||
#elif defined(__FreeBSD__) |
||||
#define GPR_PLATFORM_STRING "freebsd" |
||||
#ifndef _BSD_SOURCE |
||||
#define _BSD_SOURCE |
||||
#endif |
||||
#define GPR_CPU_POSIX 1 |
||||
#define GPR_GCC_ATOMIC 1 |
||||
#define GPR_GCC_TLS 1 |
||||
#define GPR_POSIX_LOG 1 |
||||
#define GPR_POSIX_MULTIPOLL_WITH_POLL 1 |
||||
#define GPR_POSIX_WAKEUP_FD 1 |
||||
#define GPR_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
||||
#define GPR_POSIX_SOCKET 1 |
||||
#define GPR_POSIX_SOCKETADDR 1 |
||||
#define GPR_POSIX_SOCKETUTILS 1 |
||||
#define GPR_POSIX_ENV 1 |
||||
#define GPR_POSIX_FILE 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 |
||||
#define GPR_HAVE_SO_NOSIGPIPE 1 |
||||
#ifdef _LP64 |
||||
#define GPR_ARCH_64 1 |
||||
#else /* _LP64 */ |
||||
#define GPR_ARCH_32 1 |
||||
#endif /* _LP64 */ |
||||
#else |
||||
#error Could not auto-detect platform |
||||
#endif |
||||
#endif /* GPR_NO_AUTODETECT_PLATFORM */ |
||||
|
||||
#ifndef GPR_PLATFORM_STRING |
||||
#warning "GPR_PLATFORM_STRING not auto-detected" |
||||
#define GPR_PLATFORM_STRING "unknown" |
||||
#endif |
||||
|
||||
#ifdef GPR_GCOV |
||||
#undef GPR_FORBID_UNREACHABLE_CODE |
||||
#define GPR_FORBID_UNREACHABLE_CODE 1 |
||||
#endif |
||||
|
||||
/* For a common case, assume that the platform has a C99-like stdint.h */ |
||||
|
||||
#include <stdint.h> |
||||
|
||||
/* Cache line alignment */ |
||||
#ifndef GPR_CACHELINE_SIZE_LOG |
||||
#if defined(__i386__) || defined(__x86_64__) |
||||
#define GPR_CACHELINE_SIZE_LOG 6 |
||||
#endif |
||||
#ifndef GPR_CACHELINE_SIZE_LOG |
||||
/* A reasonable default guess. Note that overestimates tend to waste more
|
||||
space, while underestimates tend to waste more time. */ |
||||
#define GPR_CACHELINE_SIZE_LOG 6 |
||||
#endif /* GPR_CACHELINE_SIZE_LOG */ |
||||
#endif /* GPR_CACHELINE_SIZE_LOG */ |
||||
|
||||
#define GPR_CACHELINE_SIZE (1 << GPR_CACHELINE_SIZE_LOG) |
||||
|
||||
/* scrub GCC_ATOMIC if it's not available on this compiler */ |
||||
#if defined(GPR_GCC_ATOMIC) && !defined(__ATOMIC_RELAXED) |
||||
#undef GPR_GCC_ATOMIC |
||||
#define GPR_GCC_SYNC 1 |
||||
#endif |
||||
|
||||
/* Validate platform combinations */ |
||||
#if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + \ |
||||
defined(GPR_WIN32_ATOMIC) != \
|
||||
1 |
||||
#error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WIN32_ATOMIC |
||||
#endif |
||||
|
||||
#if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1 |
||||
#error Must define exactly one of GPR_ARCH_32, GPR_ARCH_64 |
||||
#endif |
||||
|
||||
#if defined(GPR_CPU_LINUX) + defined(GPR_CPU_POSIX) + defined(GPR_WIN32) + \ |
||||
defined(GPR_CPU_IPHONE) + defined(GPR_CPU_CUSTOM) != \
|
||||
1 |
||||
#error Must define exactly one of GPR_CPU_LINUX, GPR_CPU_POSIX, GPR_WIN32, GPR_CPU_IPHONE, GPR_CPU_CUSTOM |
||||
#endif |
||||
|
||||
#if defined(GPR_POSIX_MULTIPOLL_WITH_POLL) && !defined(GPR_POSIX_SOCKET) |
||||
#error Must define GPR_POSIX_SOCKET to use GPR_POSIX_MULTIPOLL_WITH_POLL |
||||
#endif |
||||
|
||||
#if defined(GPR_POSIX_SOCKET) + defined(GPR_WINSOCK_SOCKET) + \ |
||||
defined(GPR_CUSTOM_SOCKET) != \
|
||||
1 |
||||
#error Must define exactly one of GPR_POSIX_SOCKET, GPR_WINSOCK_SOCKET, GPR_CUSTOM_SOCKET |
||||
#endif |
||||
|
||||
#if defined(GPR_MSVC_TLS) + defined(GPR_GCC_TLS) + defined(GPR_PTHREAD_TLS) + \ |
||||
defined(GPR_CUSTOM_TLS) != \
|
||||
1 |
||||
#error Must define exactly one of GPR_MSVC_TLS, GPR_GCC_TLS, GPR_PTHREAD_TLS, GPR_CUSTOM_TLS |
||||
#endif |
||||
|
||||
/* maximum alignment needed for any type on this platform, rounded up to a
|
||||
power of two */ |
||||
#define GPR_MAX_ALIGNMENT 16 |
||||
|
||||
#ifndef GRPC_MUST_USE_RESULT |
||||
#ifdef __GNUC__ |
||||
#define GRPC_MUST_USE_RESULT __attribute__((warn_unused_result)) |
||||
#else |
||||
#define GRPC_MUST_USE_RESULT |
||||
#endif |
||||
#endif |
||||
|
||||
#if GPR_FORBID_UNREACHABLE_CODE |
||||
#define GPR_UNREACHABLE_CODE(STATEMENT) |
||||
#else |
||||
#define GPR_UNREACHABLE_CODE(STATEMENT) \ |
||||
do { \
|
||||
gpr_log(GPR_ERROR, "Should never reach here."); \
|
||||
abort(); \
|
||||
STATEMENT; \
|
||||
} while (0) |
||||
#endif /* GPR_FORBID_UNREACHABLE_CODE */ |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */ |
@ -0,0 +1,128 @@ |
||||
/*
|
||||
* |
||||
* 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. */ |
||||
gpr_timespec gpr_time_0(gpr_clock_type type); /* The zero time interval. */ |
||||
gpr_timespec gpr_inf_future(gpr_clock_type type); /* The far future */ |
||||
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 */ |
||||
void gpr_time_init(void); |
||||
|
||||
/* Return the current time measured from the given clocks epoch. */ |
||||
gpr_timespec gpr_now(gpr_clock_type clock); |
||||
|
||||
/* Convert a timespec from one clock to another */ |
||||
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. */ |
||||
int gpr_time_cmp(gpr_timespec a, gpr_timespec b); |
||||
|
||||
gpr_timespec gpr_time_max(gpr_timespec a, gpr_timespec b); |
||||
gpr_timespec gpr_time_min(gpr_timespec a, gpr_timespec b); |
||||
|
||||
/* Add and subtract times. Calculations saturate at infinities. */ |
||||
gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b); |
||||
gpr_timespec gpr_time_sub(gpr_timespec a, gpr_timespec b); |
||||
|
||||
/* Return a timespec representing a given number of time units. LONG_MIN is
|
||||
interpreted as gpr_inf_past, and LONG_MAX as gpr_inf_future. */ |
||||
gpr_timespec gpr_time_from_micros(long x, gpr_clock_type clock_type); |
||||
gpr_timespec gpr_time_from_nanos(long x, gpr_clock_type clock_type); |
||||
gpr_timespec gpr_time_from_millis(long x, gpr_clock_type clock_type); |
||||
gpr_timespec gpr_time_from_seconds(long x, gpr_clock_type clock_type); |
||||
gpr_timespec gpr_time_from_minutes(long x, gpr_clock_type clock_type); |
||||
gpr_timespec gpr_time_from_hours(long x, gpr_clock_type clock_type); |
||||
|
||||
int32_t gpr_time_to_millis(gpr_timespec timespec); |
||||
|
||||
/* Return 1 if two times are equal or within threshold of each other,
|
||||
0 otherwise */ |
||||
int gpr_time_similar(gpr_timespec a, gpr_timespec b, gpr_timespec threshold); |
||||
|
||||
/* Sleep until at least 'until' - an absolute timeout */ |
||||
void gpr_sleep_until(gpr_timespec until); |
||||
|
||||
double gpr_timespec_to_micros(gpr_timespec t); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_IMPL_CODEGEN_TIME_H */ |
Loading…
Reference in new issue