mirror of https://github.com/grpc/grpc.git
Conflicts: Makefile templates/Makefile.templatepull/1047/head
commit
f0863b0227
175 changed files with 3929 additions and 3678 deletions
@ -0,0 +1,80 @@ |
||||
/*
|
||||
* |
||||
* 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_ASYNC_GENERIC_SERVICE_H |
||||
#define GRPCXX_ASYNC_GENERIC_SERVICE_H |
||||
|
||||
#include <grpc++/byte_buffer.h> |
||||
#include <grpc++/stream.h> |
||||
|
||||
struct grpc_server; |
||||
|
||||
namespace grpc { |
||||
|
||||
typedef ServerAsyncReaderWriter<ByteBuffer, ByteBuffer> |
||||
GenericServerAsyncReaderWriter; |
||||
|
||||
class GenericServerContext GRPC_FINAL : public ServerContext { |
||||
public: |
||||
const grpc::string& method() const { return method_; } |
||||
const grpc::string& host() const { return host_; } |
||||
|
||||
private: |
||||
friend class Server; |
||||
|
||||
grpc::string method_; |
||||
grpc::string host_; |
||||
}; |
||||
|
||||
class AsyncGenericService GRPC_FINAL { |
||||
public: |
||||
// TODO(yangg) Once we can add multiple completion queues to the server
|
||||
// in c core, add a CompletionQueue* argument to the ctor here.
|
||||
// TODO(yangg) support methods list.
|
||||
AsyncGenericService(const grpc::string& methods) : server_(nullptr) {} |
||||
|
||||
void RequestCall(GenericServerContext* ctx, |
||||
GenericServerAsyncReaderWriter* reader_writer, |
||||
CompletionQueue* cq, void* tag); |
||||
|
||||
// The new rpc event should be obtained from this completion queue.
|
||||
CompletionQueue* completion_queue(); |
||||
|
||||
private: |
||||
friend class Server; |
||||
Server* server_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_ASYNC_GENERIC_SERVICE_H
|
@ -0,0 +1,82 @@ |
||||
/*
|
||||
* |
||||
* 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_BYTE_BUFFER_H |
||||
#define GRPCXX_BYTE_BUFFER_H |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc++/config.h> |
||||
#include <grpc++/slice.h> |
||||
|
||||
#include <vector> |
||||
|
||||
namespace grpc { |
||||
|
||||
class ByteBuffer GRPC_FINAL { |
||||
public: |
||||
ByteBuffer() : buffer_(nullptr) {} |
||||
|
||||
ByteBuffer(Slice* slices, size_t nslices); |
||||
|
||||
~ByteBuffer() { |
||||
if (buffer_) { |
||||
grpc_byte_buffer_destroy(buffer_); |
||||
} |
||||
} |
||||
|
||||
void Dump(std::vector<Slice>* slices); |
||||
|
||||
void Clear(); |
||||
size_t Length(); |
||||
|
||||
private: |
||||
friend class CallOpBuffer; |
||||
|
||||
// takes ownership
|
||||
void set_buffer(grpc_byte_buffer* buf) { |
||||
if (buffer_) { |
||||
gpr_log(GPR_ERROR, "Overriding existing buffer"); |
||||
Clear(); |
||||
} |
||||
buffer_ = buf; |
||||
} |
||||
|
||||
grpc_byte_buffer* buffer() const { return buffer_; } |
||||
|
||||
grpc_byte_buffer* buffer_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_BYTE_BUFFER_H
|
@ -0,0 +1,62 @@ |
||||
/*
|
||||
* |
||||
* 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_GENERIC_STUB_H |
||||
#define GRPCXX_GENERIC_STUB_H |
||||
|
||||
#include <grpc++/byte_buffer.h> |
||||
#include <grpc++/stream.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
typedef ClientAsyncReaderWriter<ByteBuffer, ByteBuffer> |
||||
GenericClientAsyncReaderWriter; |
||||
|
||||
// Generic stubs provide a type-unsafe interface to call gRPC methods
|
||||
// by name.
|
||||
class GenericStub GRPC_FINAL { |
||||
public: |
||||
explicit GenericStub(std::shared_ptr<ChannelInterface> channel) |
||||
: channel_(channel) {} |
||||
|
||||
// begin a call to a named method
|
||||
std::unique_ptr<GenericClientAsyncReaderWriter> Call( |
||||
ClientContext* context, const grpc::string& method); |
||||
|
||||
private: |
||||
std::shared_ptr<ChannelInterface> channel_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_GENERIC_STUB_H
|
@ -0,0 +1,74 @@ |
||||
/*
|
||||
* |
||||
* 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_SLICE_H |
||||
#define GRPCXX_SLICE_H |
||||
|
||||
#include <grpc/support/slice.h> |
||||
#include <grpc++/config.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
class Slice GRPC_FINAL { |
||||
public: |
||||
// construct empty slice
|
||||
Slice(); |
||||
// destructor - drops one ref
|
||||
~Slice(); |
||||
// construct slice from grpc slice, adding a ref
|
||||
enum AddRef { ADD_REF }; |
||||
Slice(gpr_slice slice, AddRef); |
||||
// construct slice from grpc slice, stealing a ref
|
||||
enum StealRef { STEAL_REF }; |
||||
Slice(gpr_slice slice, StealRef); |
||||
// copy constructor - adds a ref
|
||||
Slice(const Slice& other); |
||||
// assignment - ref count is unchanged
|
||||
Slice& operator=(Slice other) { |
||||
std::swap(slice_, other.slice_); |
||||
return *this; |
||||
} |
||||
|
||||
size_t size() const { return GPR_SLICE_LENGTH(slice_); } |
||||
const gpr_uint8* begin() const { return GPR_SLICE_START_PTR(slice_); } |
||||
const gpr_uint8* end() const { return GPR_SLICE_END_PTR(slice_); } |
||||
|
||||
private: |
||||
friend class ByteBuffer; |
||||
|
||||
gpr_slice slice_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_SLICE_H
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,53 @@ |
||||
/*
|
||||
* |
||||
* 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/support/port_platform.h> |
||||
|
||||
#ifdef GPR_CPU_IPHONE |
||||
|
||||
/* Probably 2 instead of 1, but see comment on gpr_cpu_current_cpu. */ |
||||
unsigned gpr_cpu_num_cores(void) { |
||||
return 1; |
||||
} |
||||
|
||||
/* Most code that's using this is using it to shard across work queues. So
|
||||
unless profiling shows it's a problem or there appears a way to detect the |
||||
currently running CPU core, let's have it shard the default way. |
||||
Note that the interface in cpu.h lets gpr_cpu_num_cores return 0, but doing |
||||
it makes it impossible for gpr_cpu_current_cpu to satisfy its stated range, |
||||
and some code might be relying on it. */ |
||||
unsigned gpr_cpu_current_cpu(void) { |
||||
return 0; |
||||
} |
||||
|
||||
#endif /* GPR_CPU_IPHONE */ |
@ -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. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc++/async_generic_service.h> |
||||
|
||||
#include <grpc++/server.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
void AsyncGenericService::RequestCall( |
||||
GenericServerContext* ctx, GenericServerAsyncReaderWriter* reader_writer, |
||||
CompletionQueue* cq, void* tag) { |
||||
server_->RequestAsyncGenericCall(ctx, reader_writer, cq, tag); |
||||
} |
||||
|
||||
CompletionQueue* AsyncGenericService::completion_queue() { |
||||
return &server_->cq_; |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,76 @@ |
||||
/*
|
||||
* |
||||
* 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++/byte_buffer.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
ByteBuffer::ByteBuffer(Slice* slices, size_t nslices) { |
||||
// TODO(yangg) maybe expose some core API to simplify this
|
||||
std::vector<gpr_slice> c_slices(nslices); |
||||
for (size_t i = 0; i < nslices; i++) { |
||||
c_slices[i] = slices[i].slice_; |
||||
} |
||||
buffer_ = grpc_byte_buffer_create(c_slices.data(), nslices); |
||||
} |
||||
|
||||
void ByteBuffer::Clear() { |
||||
if (buffer_) { |
||||
grpc_byte_buffer_destroy(buffer_); |
||||
buffer_ = nullptr; |
||||
} |
||||
} |
||||
|
||||
void ByteBuffer::Dump(std::vector<Slice>* slices) { |
||||
slices->clear(); |
||||
if (!buffer_) { |
||||
return; |
||||
} |
||||
grpc_byte_buffer_reader* reader = grpc_byte_buffer_reader_create(buffer_); |
||||
gpr_slice s; |
||||
while (grpc_byte_buffer_reader_next(reader, &s)) { |
||||
slices->push_back(Slice(s, Slice::STEAL_REF)); |
||||
gpr_slice_unref(s); |
||||
} |
||||
grpc_byte_buffer_reader_destroy(reader); |
||||
} |
||||
|
||||
size_t ByteBuffer::Length() { |
||||
if (buffer_) { |
||||
return grpc_byte_buffer_length(buffer_); |
||||
} else { |
||||
return 0; |
||||
} |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,48 @@ |
||||
/*
|
||||
* |
||||
* 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++/slice.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
Slice::Slice() : slice_(gpr_empty_slice()) {} |
||||
|
||||
Slice::~Slice() { gpr_slice_unref(slice_); } |
||||
|
||||
Slice::Slice(gpr_slice slice, AddRef) : slice_(gpr_slice_ref(slice)) {} |
||||
|
||||
Slice::Slice(gpr_slice slice, StealRef) : slice_(slice) {} |
||||
|
||||
Slice::Slice(const Slice& other) : slice_(gpr_slice_ref(other.slice_)) {} |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,62 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// 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. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using Grpc.Core; |
||||
using Grpc.Core.Internal; |
||||
using Grpc.Core.Utils; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Grpc.Core.Internal.Tests |
||||
{ |
||||
public class MetadataArraySafeHandleTest |
||||
{ |
||||
[Test] |
||||
public void CreateEmptyAndDestroy() |
||||
{ |
||||
var metadata = Metadata.CreateBuilder().Build(); |
||||
var nativeMetadata = MetadataArraySafeHandle.Create(metadata); |
||||
nativeMetadata.Dispose(); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateAndDestroy() |
||||
{ |
||||
var metadata = Metadata.CreateBuilder() |
||||
.Add(new Metadata.MetadataEntry("host", "somehost")) |
||||
.Add(new Metadata.MetadataEntry("header2", "header value")).Build(); |
||||
var nativeMetadata = MetadataArraySafeHandle.Create(metadata); |
||||
nativeMetadata.Dispose(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,72 @@ |
||||
#region Copyright notice and license |
||||
// 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. |
||||
#endregion |
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace Grpc.Core.Internal |
||||
{ |
||||
/// <summary> |
||||
/// grpc_metadata_array from <grpc/grpc.h> |
||||
/// </summary> |
||||
internal class MetadataArraySafeHandle : SafeHandleZeroIsInvalid |
||||
{ |
||||
[DllImport("grpc_csharp_ext.dll")] |
||||
static extern MetadataArraySafeHandle grpcsharp_metadata_array_create(UIntPtr capacity); |
||||
|
||||
[DllImport("grpc_csharp_ext.dll", CharSet = CharSet.Ansi)] |
||||
static extern void grpcsharp_metadata_array_add(MetadataArraySafeHandle array, string key, byte[] value, UIntPtr valueLength); |
||||
|
||||
[DllImport("grpc_csharp_ext.dll")] |
||||
static extern void grpcsharp_metadata_array_destroy_full(IntPtr array); |
||||
|
||||
private MetadataArraySafeHandle() |
||||
{ |
||||
} |
||||
|
||||
public static MetadataArraySafeHandle Create(Metadata metadata) |
||||
{ |
||||
var entries = metadata.Entries; |
||||
var metadataArray = grpcsharp_metadata_array_create(new UIntPtr((ulong)entries.Count)); |
||||
for (int i = 0; i < entries.Count; i++) |
||||
{ |
||||
grpcsharp_metadata_array_add(metadataArray, entries[i].Key, entries[i].ValueBytes, new UIntPtr((ulong)entries[i].ValueBytes.Length)); |
||||
} |
||||
return metadataArray; |
||||
} |
||||
|
||||
protected override bool ReleaseHandle() |
||||
{ |
||||
grpcsharp_metadata_array_destroy_full(handle); |
||||
return true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,126 @@ |
||||
#region Copyright notice and license |
||||
// 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. |
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.Immutable; |
||||
using System.Runtime.InteropServices; |
||||
using System.Text; |
||||
|
||||
namespace Grpc.Core |
||||
{ |
||||
/// <summary> |
||||
/// gRPC call metadata. |
||||
/// </summary> |
||||
public class Metadata |
||||
{ |
||||
public static readonly Metadata Empty = new Metadata(ImmutableList<MetadataEntry>.Empty); |
||||
|
||||
readonly ImmutableList<MetadataEntry> entries; |
||||
|
||||
public Metadata(ImmutableList<MetadataEntry> entries) |
||||
{ |
||||
this.entries = entries; |
||||
} |
||||
|
||||
public ImmutableList<MetadataEntry> Entries |
||||
{ |
||||
get |
||||
{ |
||||
return this.entries; |
||||
} |
||||
} |
||||
|
||||
public static Builder CreateBuilder() |
||||
{ |
||||
return new Builder(); |
||||
} |
||||
|
||||
public struct MetadataEntry |
||||
{ |
||||
readonly string key; |
||||
readonly byte[] valueBytes; |
||||
|
||||
public MetadataEntry(string key, byte[] valueBytes) |
||||
{ |
||||
this.key = key; |
||||
this.valueBytes = valueBytes; |
||||
} |
||||
|
||||
public MetadataEntry(string key, string value) |
||||
{ |
||||
this.key = key; |
||||
this.valueBytes = Encoding.ASCII.GetBytes(value); |
||||
} |
||||
|
||||
public string Key |
||||
{ |
||||
get |
||||
{ |
||||
return this.key; |
||||
} |
||||
} |
||||
|
||||
// TODO: using ByteString would guarantee immutability. |
||||
public byte[] ValueBytes |
||||
{ |
||||
get |
||||
{ |
||||
return this.valueBytes; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class Builder |
||||
{ |
||||
readonly List<Metadata.MetadataEntry> entries = new List<Metadata.MetadataEntry>(); |
||||
|
||||
public List<MetadataEntry> Entries |
||||
{ |
||||
get |
||||
{ |
||||
return entries; |
||||
} |
||||
} |
||||
|
||||
public Builder Add(MetadataEntry entry) |
||||
{ |
||||
entries.Add(entry); |
||||
return this; |
||||
} |
||||
|
||||
public Metadata Build() |
||||
{ |
||||
return new Metadata(entries.ToImmutableList()); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// 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. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using Grpc.Core.Internal; |
||||
|
||||
namespace Grpc.Core |
||||
{ |
||||
// TODO: support adding timeout to methods. |
||||
/// <summary> |
||||
/// Base for client-side stubs. |
||||
/// </summary> |
||||
public abstract class AbstractStub<TStub, TConfig> |
||||
where TConfig : StubConfiguration |
||||
{ |
||||
readonly Channel channel; |
||||
readonly TConfig config; |
||||
|
||||
public AbstractStub(Channel channel, TConfig config) |
||||
{ |
||||
this.channel = channel; |
||||
this.config = config; |
||||
} |
||||
|
||||
public Channel Channel |
||||
{ |
||||
get |
||||
{ |
||||
return this.channel; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a new call to given method. |
||||
/// </summary> |
||||
protected Call<TRequest, TResponse> CreateCall<TRequest, TResponse>(string serviceName, Method<TRequest, TResponse> method) |
||||
{ |
||||
var headerBuilder = Metadata.CreateBuilder(); |
||||
config.HeaderInterceptor(headerBuilder); |
||||
return new Call<TRequest, TResponse>(serviceName, method, channel, headerBuilder.Build()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// 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. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using Grpc.Core.Internal; |
||||
using Grpc.Core.Utils; |
||||
|
||||
namespace Grpc.Core |
||||
{ |
||||
public delegate void HeaderInterceptorDelegate(Metadata.Builder headerBuilder); |
||||
|
||||
public class StubConfiguration |
||||
{ |
||||
/// <summary> |
||||
/// The default stub configuration. |
||||
/// </summary> |
||||
public static readonly StubConfiguration Default = new StubConfiguration((headerBuilder) => { }); |
||||
|
||||
readonly HeaderInterceptorDelegate headerInterceptor; |
||||
|
||||
public StubConfiguration(HeaderInterceptorDelegate headerInterceptor) |
||||
{ |
||||
this.headerInterceptor = Preconditions.CheckNotNull(headerInterceptor); |
||||
} |
||||
|
||||
public HeaderInterceptorDelegate HeaderInterceptor |
||||
{ |
||||
get |
||||
{ |
||||
return headerInterceptor; |
||||
} |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue