commit
c9fef6f521
211 changed files with 6419 additions and 1185 deletions
@ -0,0 +1,77 @@ |
||||
/*
|
||||
* |
||||
* 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_AUTH_PROPERTY_ITERATOR_H |
||||
#define GRPCXX_AUTH_PROPERTY_ITERATOR_H |
||||
|
||||
#include <iterator> |
||||
#include <vector> |
||||
|
||||
#include <grpc++/config.h> |
||||
|
||||
struct grpc_auth_context; |
||||
struct grpc_auth_property; |
||||
struct grpc_auth_property_iterator; |
||||
|
||||
namespace grpc { |
||||
class SecureAuthContext; |
||||
|
||||
typedef std::pair<grpc::string, grpc::string> AuthProperty; |
||||
|
||||
class AuthPropertyIterator |
||||
: public std::iterator<std::input_iterator_tag, const AuthProperty> { |
||||
public: |
||||
~AuthPropertyIterator(); |
||||
AuthPropertyIterator& operator++(); |
||||
AuthPropertyIterator operator++(int); |
||||
bool operator==(const AuthPropertyIterator& rhs) const; |
||||
bool operator!=(const AuthPropertyIterator& rhs) const; |
||||
const AuthProperty operator*(); |
||||
|
||||
protected: |
||||
AuthPropertyIterator(); |
||||
AuthPropertyIterator(const grpc_auth_property* property, |
||||
const grpc_auth_property_iterator* iter); |
||||
private: |
||||
friend class SecureAuthContext; |
||||
const grpc_auth_property* property_; |
||||
// The following items form a grpc_auth_property_iterator.
|
||||
const grpc_auth_context* ctx_; |
||||
size_t index_; |
||||
const char* name_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_AUTH_PROPERTY_ITERATOR_H
|
||||
|
@ -0,0 +1,130 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/support/stack_lockfree.h" |
||||
|
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/atm.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
/* The lockfree node structure is a single architecture-level
|
||||
word that allows for an atomic CAS to set it up. */ |
||||
struct lockfree_node_contents { |
||||
/* next thing to look at. Actual index for head, next index otherwise */ |
||||
gpr_uint16 index; |
||||
#ifdef GPR_ARCH_64 |
||||
gpr_uint16 pad; |
||||
gpr_uint32 aba_ctr; |
||||
#else |
||||
#ifdef GPR_ARCH_32 |
||||
gpr_uint16 aba_ctr; |
||||
#else |
||||
#error Unsupported bit width architecture |
||||
#endif |
||||
#endif |
||||
}; |
||||
|
||||
/* Use a union to make sure that these are in the same bits as an atm word */ |
||||
typedef union lockfree_node { |
||||
gpr_atm atm; |
||||
struct lockfree_node_contents contents; |
||||
} lockfree_node; |
||||
|
||||
#define ENTRY_ALIGNMENT_BITS 3 /* make sure that entries aligned to 8-bytes */ |
||||
#define INVALID_ENTRY_INDEX ((1 << 16) - 1) /* reserve this entry as invalid \ |
||||
*/ |
||||
|
||||
struct gpr_stack_lockfree { |
||||
lockfree_node *entries; |
||||
lockfree_node head; /* An atomic entry describing curr head */ |
||||
}; |
||||
|
||||
gpr_stack_lockfree *gpr_stack_lockfree_create(int entries) { |
||||
gpr_stack_lockfree *stack; |
||||
stack = gpr_malloc(sizeof(*stack)); |
||||
/* Since we only allocate 16 bits to represent an entry number,
|
||||
* make sure that we are within the desired range */ |
||||
/* Reserve the highest entry number as a dummy */ |
||||
GPR_ASSERT(entries < INVALID_ENTRY_INDEX); |
||||
stack->entries = gpr_malloc_aligned(entries * sizeof(stack->entries[0]), |
||||
ENTRY_ALIGNMENT_BITS); |
||||
/* Clear out all entries */ |
||||
memset(stack->entries, 0, entries * sizeof(stack->entries[0])); |
||||
memset(&stack->head, 0, sizeof(stack->head)); |
||||
|
||||
/* Point the head at reserved dummy entry */ |
||||
stack->head.contents.index = INVALID_ENTRY_INDEX; |
||||
return stack; |
||||
} |
||||
|
||||
void gpr_stack_lockfree_destroy(gpr_stack_lockfree *stack) { |
||||
gpr_free_aligned(stack->entries); |
||||
gpr_free(stack); |
||||
} |
||||
|
||||
void gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) { |
||||
lockfree_node head; |
||||
lockfree_node newhead; |
||||
|
||||
/* First fill in the entry's index and aba ctr for new head */ |
||||
newhead.contents.index = (gpr_uint16)entry; |
||||
/* Also post-increment the aba_ctr */ |
||||
newhead.contents.aba_ctr = stack->entries[entry].contents.aba_ctr++; |
||||
|
||||
do { |
||||
/* Atomically get the existing head value for use */ |
||||
head.atm = gpr_atm_no_barrier_load(&(stack->head.atm)); |
||||
/* Point to it */ |
||||
stack->entries[entry].contents.index = head.contents.index; |
||||
} while (!gpr_atm_rel_cas(&(stack->head.atm), head.atm, newhead.atm)); |
||||
/* Use rel_cas above to make sure that entry index is set properly */ |
||||
} |
||||
|
||||
int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) { |
||||
lockfree_node head; |
||||
lockfree_node newhead; |
||||
do { |
||||
head.atm = gpr_atm_acq_load(&(stack->head.atm)); |
||||
if (head.contents.index == INVALID_ENTRY_INDEX) { |
||||
return -1; |
||||
} |
||||
newhead.atm = |
||||
gpr_atm_no_barrier_load(&(stack->entries[head.contents.index].atm)); |
||||
|
||||
} while (!gpr_atm_no_barrier_cas(&(stack->head.atm), head.atm, newhead.atm)); |
||||
return head.contents.index; |
||||
} |
@ -0,0 +1,50 @@ |
||||
/*
|
||||
* |
||||
* 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_INTERNAL_CORE_SUPPORT_STACK_LOCKFREE_H |
||||
#define GRPC_INTERNAL_CORE_SUPPORT_STACK_LOCKFREE_H |
||||
|
||||
typedef struct gpr_stack_lockfree gpr_stack_lockfree; |
||||
|
||||
/* This stack must specify the maximum number of entries to track.
|
||||
The current implementation only allows up to 65534 entries */ |
||||
gpr_stack_lockfree* gpr_stack_lockfree_create(int entries); |
||||
void gpr_stack_lockfree_destroy(gpr_stack_lockfree* stack); |
||||
|
||||
/* Pass in a valid entry number for the next stack entry */ |
||||
void gpr_stack_lockfree_push(gpr_stack_lockfree* stack, int entry); |
||||
|
||||
/* Returns -1 on empty or the actual entry number */ |
||||
int gpr_stack_lockfree_pop(gpr_stack_lockfree* stack); |
||||
|
||||
#endif /* GRPC_INTERNAL_CORE_SUPPORT_STACK_LOCKFREE_H */ |
@ -0,0 +1,87 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc++/auth_property_iterator.h> |
||||
|
||||
#include <grpc/grpc_security.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
AuthPropertyIterator::AuthPropertyIterator() |
||||
: property_(nullptr), ctx_(nullptr), index_(0), name_(nullptr) {} |
||||
|
||||
AuthPropertyIterator::AuthPropertyIterator( |
||||
const grpc_auth_property* property, const grpc_auth_property_iterator* iter) |
||||
: property_(property), |
||||
ctx_(iter->ctx), |
||||
index_(iter->index), |
||||
name_(iter->name) {} |
||||
|
||||
AuthPropertyIterator::~AuthPropertyIterator() {} |
||||
|
||||
AuthPropertyIterator& AuthPropertyIterator::operator++() { |
||||
grpc_auth_property_iterator iter = {ctx_, index_, name_}; |
||||
property_ = grpc_auth_property_iterator_next(&iter); |
||||
ctx_ = iter.ctx; |
||||
index_ = iter.index; |
||||
name_ = iter.name; |
||||
return *this; |
||||
} |
||||
|
||||
AuthPropertyIterator AuthPropertyIterator::operator++(int) { |
||||
AuthPropertyIterator tmp(*this); |
||||
operator++(); |
||||
return tmp; |
||||
} |
||||
|
||||
bool AuthPropertyIterator::operator==( |
||||
const AuthPropertyIterator& rhs) const { |
||||
if (property_ == nullptr || rhs.property_ == nullptr) { |
||||
return property_ == rhs.property_; |
||||
} else { |
||||
return index_ == rhs.index_; |
||||
} |
||||
} |
||||
|
||||
bool AuthPropertyIterator::operator!=( |
||||
const AuthPropertyIterator& rhs) const { |
||||
return !operator==(rhs); |
||||
} |
||||
|
||||
const AuthProperty AuthPropertyIterator::operator*() { |
||||
return std::make_pair<grpc::string, grpc::string>( |
||||
grpc::string(property_->name), |
||||
grpc::string(property_->value, property_->value_length)); |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -1,99 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc++/async_server_context.h> |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/log.h> |
||||
#include "src/cpp/proto/proto_utils.h" |
||||
#include <grpc++/config.h> |
||||
#include <grpc++/status.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
AsyncServerContext::AsyncServerContext( |
||||
grpc_call* call, const grpc::string& method, const grpc::string& host, |
||||
system_clock::time_point absolute_deadline) |
||||
: method_(method), |
||||
host_(host), |
||||
absolute_deadline_(absolute_deadline), |
||||
request_(nullptr), |
||||
call_(call) {} |
||||
|
||||
AsyncServerContext::~AsyncServerContext() { grpc_call_destroy(call_); } |
||||
|
||||
void AsyncServerContext::Accept(grpc_completion_queue* cq) { |
||||
GPR_ASSERT(grpc_call_server_accept_old(call_, cq, this) == GRPC_CALL_OK); |
||||
GPR_ASSERT(grpc_call_server_end_initial_metadata_old( |
||||
call_, GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK); |
||||
} |
||||
|
||||
bool AsyncServerContext::StartRead(grpc::protobuf::Message* request) { |
||||
GPR_ASSERT(request); |
||||
request_ = request; |
||||
grpc_call_error err = grpc_call_start_read_old(call_, this); |
||||
return err == GRPC_CALL_OK; |
||||
} |
||||
|
||||
bool AsyncServerContext::StartWrite(const grpc::protobuf::Message& response, |
||||
int flags) { |
||||
grpc_byte_buffer* buffer = nullptr; |
||||
GRPC_TIMER_MARK(SER_PROTO_BEGIN, call_->call()); |
||||
if (!SerializeProto(response, &buffer)) { |
||||
return false; |
||||
} |
||||
GRPC_TIMER_MARK(SER_PROTO_END, call_->call()); |
||||
grpc_call_error err = grpc_call_start_write_old(call_, buffer, this, flags); |
||||
grpc_byte_buffer_destroy(buffer); |
||||
return err == GRPC_CALL_OK; |
||||
} |
||||
|
||||
bool AsyncServerContext::StartWriteStatus(const Status& status) { |
||||
grpc_call_error err = grpc_call_start_write_status_old( |
||||
call_, static_cast<grpc_status_code>(status.code()), |
||||
status.details().empty() ? nullptr |
||||
: const_cast<char*>(status.details().c_str()), |
||||
this); |
||||
return err == GRPC_CALL_OK; |
||||
} |
||||
|
||||
bool AsyncServerContext::ParseRead(grpc_byte_buffer* read_buffer) { |
||||
GPR_ASSERT(request_); |
||||
GRPC_TIMER_MARK(DESER_PROTO_BEGIN, call_->call()); |
||||
bool success = DeserializeProto(read_buffer, request_); |
||||
GRPC_TIMER_MARK(DESER_PROTO_END, call_->call()); |
||||
request_ = nullptr; |
||||
return success; |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,5 @@ |
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
// The current version of gRPC C#. |
||||
[assembly: AssemblyVersion("0.6.0.*")] |
@ -0,0 +1,2 @@ |
||||
bin |
||||
obj |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue