commit
af31a1ace7
85 changed files with 2961 additions and 133 deletions
@ -0,0 +1,153 @@ |
||||
/*
|
||||
* |
||||
* 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 <iostream> |
||||
#include <memory> |
||||
#include <string> |
||||
|
||||
#include <grpc++/grpc++.h> |
||||
#include <thread> |
||||
|
||||
#include "helloworld.grpc.pb.h" |
||||
|
||||
using grpc::Channel; |
||||
using grpc::ClientAsyncResponseReader; |
||||
using grpc::ClientContext; |
||||
using grpc::CompletionQueue; |
||||
using grpc::Status; |
||||
using helloworld::HelloRequest; |
||||
using helloworld::HelloReply; |
||||
using helloworld::Greeter; |
||||
|
||||
class GreeterClient { |
||||
public: |
||||
explicit GreeterClient(std::shared_ptr<Channel> channel) |
||||
: stub_(Greeter::NewStub(channel)) {} |
||||
|
||||
// Assembles the client's payload and sends it to the server.
|
||||
void SayHello(const std::string& user) { |
||||
// Data we are sending to the server.
|
||||
HelloRequest request; |
||||
request.set_name(user); |
||||
|
||||
// Call object to store rpc data
|
||||
AsyncClientCall* call = new AsyncClientCall; |
||||
|
||||
// stub_->AsyncSayHello() performs the RPC call, returning an instance to
|
||||
// store in "call". Because we are using the asynchronous API, we need to
|
||||
// hold on to the "call" instance in order to get updates on the ongoing RPC.
|
||||
call->response_reader = stub_->AsyncSayHello(&call->context, request, &cq_); |
||||
|
||||
|
||||
// Request that, upon completion of the RPC, "reply" be updated with the
|
||||
// server's response; "status" with the indication of whether the operation
|
||||
// was successful. Tag the request with the memory address of the call object.
|
||||
call->response_reader->Finish(&call->reply, &call->status, (void*)call); |
||||
|
||||
} |
||||
|
||||
// Loop while listening for completed responses.
|
||||
// Prints out the response from the server.
|
||||
void AsyncCompleteRpc() { |
||||
void* got_tag; |
||||
bool ok = false; |
||||
|
||||
// Block until the next result is available in the completion queue "cq".
|
||||
while (cq_.Next(&got_tag, &ok)) { |
||||
// The tag in this example is the memory location of the call object
|
||||
AsyncClientCall* call = static_cast<AsyncClientCall*>(got_tag); |
||||
|
||||
// Verify that the request was completed successfully. Note that "ok"
|
||||
// corresponds solely to the request for updates introduced by Finish().
|
||||
GPR_ASSERT(ok); |
||||
|
||||
if (call->status.ok()) |
||||
std::cout << "Greeter received: " << call->reply.message() << std::endl; |
||||
else |
||||
std::cout << "RPC failed" << std::endl; |
||||
|
||||
// Once we're complete, deallocate the call object.
|
||||
delete call; |
||||
} |
||||
} |
||||
|
||||
private: |
||||
|
||||
// struct for keeping state and data information
|
||||
struct AsyncClientCall { |
||||
// Container for the data we expect from the server.
|
||||
HelloReply reply; |
||||
|
||||
// Context for the client. It could be used to convey extra information to
|
||||
// the server and/or tweak certain RPC behaviors.
|
||||
ClientContext context; |
||||
|
||||
// Storage for the status of the RPC upon completion.
|
||||
Status status; |
||||
|
||||
|
||||
std::unique_ptr<ClientAsyncResponseReader<HelloReply>> response_reader; |
||||
}; |
||||
|
||||
// Out of the passed in Channel comes the stub, stored here, our view of the
|
||||
// server's exposed services.
|
||||
std::unique_ptr<Greeter::Stub> stub_; |
||||
|
||||
// The producer-consumer queue we use to communicate asynchronously with the
|
||||
// gRPC runtime.
|
||||
CompletionQueue cq_; |
||||
}; |
||||
|
||||
int main(int argc, char** argv) { |
||||
|
||||
|
||||
// Instantiate the client. It requires a channel, out of which the actual RPCs
|
||||
// are created. This channel models a connection to an endpoint (in this case,
|
||||
// localhost at port 50051). We indicate that the channel isn't authenticated
|
||||
// (use of InsecureChannelCredentials()).
|
||||
GreeterClient greeter(grpc::CreateChannel( |
||||
"localhost:50051", grpc::InsecureChannelCredentials())); |
||||
|
||||
// Spawn reader thread that loops indefinitely
|
||||
std::thread thread_ = std::thread(&GreeterClient::AsyncCompleteRpc, &greeter); |
||||
|
||||
for (int i = 0; i < 100; i++) { |
||||
std::string user("world " + std::to_string(i)); |
||||
greeter.SayHello(user); // The actual RPC call!
|
||||
} |
||||
|
||||
std::cout << "Press control-c to quit" << std::endl << std::endl; |
||||
thread_.join(); //blocks forever
|
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,51 @@ |
||||
/*
|
||||
* |
||||
* 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_GRPC_CRONET_H |
||||
#define GRPC_GRPC_CRONET_H |
||||
|
||||
#include <grpc/grpc.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
GRPCAPI grpc_channel *grpc_cronet_secure_channel_create( |
||||
void *engine, const char *target, const grpc_channel_args *args, |
||||
void *reserved); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* GRPC_GRPC_CRONET_H */ |
@ -0,0 +1,69 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/lib/surface/channel.h" |
||||
#include "src/core/lib/transport/transport_impl.h" |
||||
|
||||
// Cronet transport object
|
||||
typedef struct cronet_transport { |
||||
grpc_transport base; // must be first element in this structure
|
||||
void *engine; |
||||
char *host; |
||||
} cronet_transport; |
||||
|
||||
extern grpc_transport_vtable grpc_cronet_vtable; |
||||
|
||||
GRPCAPI grpc_channel *grpc_cronet_secure_channel_create( |
||||
void *engine, const char *target, const grpc_channel_args *args, |
||||
void *reserved) { |
||||
cronet_transport *ct = gpr_malloc(sizeof(cronet_transport)); |
||||
ct->base.vtable = &grpc_cronet_vtable; |
||||
ct->engine = engine; |
||||
ct->host = gpr_malloc(strlen(target) + 1); |
||||
strcpy(ct->host, target); |
||||
gpr_log(GPR_DEBUG, |
||||
"grpc_create_cronet_transport: cronet_engine = %p, target=%s", engine, |
||||
ct->host); |
||||
|
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
return grpc_channel_create(&exec_ctx, target, args, |
||||
GRPC_CLIENT_DIRECT_CHANNEL, (grpc_transport *)ct); |
||||
} |
@ -0,0 +1,85 @@ |
||||
/*
|
||||
* |
||||
* 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. |
||||
* |
||||
*/ |
||||
|
||||
/* This file has empty implementation of all the functions exposed by the cronet
|
||||
library, so we can build it in all environments */ |
||||
|
||||
#include <stdbool.h> |
||||
|
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "third_party/objective_c/Cronet/cronet_c_for_grpc.h" |
||||
|
||||
#ifdef GRPC_COMPILE_WITH_CRONET |
||||
/* link with the real CRONET library in the build system */ |
||||
#else |
||||
/* Dummy implementation of cronet API just to test for build-ability */ |
||||
cronet_bidirectional_stream* cronet_bidirectional_stream_create( |
||||
cronet_engine* engine, void* annotation, |
||||
cronet_bidirectional_stream_callback* callback) { |
||||
GPR_ASSERT(0); |
||||
return NULL; |
||||
} |
||||
|
||||
int cronet_bidirectional_stream_destroy(cronet_bidirectional_stream* stream) { |
||||
GPR_ASSERT(0); |
||||
return 0; |
||||
} |
||||
|
||||
int cronet_bidirectional_stream_start( |
||||
cronet_bidirectional_stream* stream, const char* url, int priority, |
||||
const char* method, const cronet_bidirectional_stream_header_array* headers, |
||||
bool end_of_stream) { |
||||
GPR_ASSERT(0); |
||||
return 0; |
||||
} |
||||
|
||||
int cronet_bidirectional_stream_read(cronet_bidirectional_stream* stream, |
||||
char* buffer, int capacity) { |
||||
GPR_ASSERT(0); |
||||
return 0; |
||||
} |
||||
|
||||
int cronet_bidirectional_stream_write(cronet_bidirectional_stream* stream, |
||||
const char* buffer, int count, |
||||
bool end_of_stream) { |
||||
GPR_ASSERT(0); |
||||
return 0; |
||||
} |
||||
|
||||
int cronet_bidirectional_stream_cancel(cronet_bidirectional_stream* stream) { |
||||
GPR_ASSERT(0); |
||||
return 0; |
||||
} |
||||
|
||||
#endif /* GRPC_COMPILE_WITH_CRONET */ |
@ -0,0 +1,640 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/host_port.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/slice_buffer.h> |
||||
#include <grpc/support/string_util.h> |
||||
#include <grpc/support/useful.h> |
||||
|
||||
#include "src/core/ext/transport/chttp2/transport/incoming_metadata.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
#include "src/core/lib/support/string.h" |
||||
#include "src/core/lib/surface/channel.h" |
||||
#include "src/core/lib/transport/metadata_batch.h" |
||||
#include "src/core/lib/transport/transport_impl.h" |
||||
#include "third_party/objective_c/Cronet/cronet_c_for_grpc.h" |
||||
|
||||
#define GRPC_HEADER_SIZE_IN_BYTES 5 |
||||
|
||||
// Global flag that gets set with GRPC_TRACE env variable
|
||||
int grpc_cronet_trace = 1; |
||||
|
||||
// Cronet transport object
|
||||
struct grpc_cronet_transport { |
||||
grpc_transport base; /* must be first element in this structure */ |
||||
cronet_engine *engine; |
||||
char *host; |
||||
}; |
||||
|
||||
typedef struct grpc_cronet_transport grpc_cronet_transport; |
||||
|
||||
enum send_state { |
||||
CRONET_SEND_IDLE = 0, |
||||
CRONET_REQ_STARTED, |
||||
CRONET_SEND_HEADER, |
||||
CRONET_WRITE, |
||||
CRONET_WRITE_COMPLETED, |
||||
}; |
||||
|
||||
enum recv_state { |
||||
CRONET_RECV_IDLE = 0, |
||||
CRONET_RECV_READ_LENGTH, |
||||
CRONET_RECV_READ_DATA, |
||||
CRONET_RECV_CLOSED, |
||||
}; |
||||
|
||||
static const char *recv_state_name[] = { |
||||
"CRONET_RECV_IDLE", "CRONET_RECV_READ_LENGTH", "CRONET_RECV_READ_DATA,", |
||||
"CRONET_RECV_CLOSED"}; |
||||
|
||||
// Enum that identifies calling function.
|
||||
enum e_caller { |
||||
PERFORM_STREAM_OP, |
||||
ON_READ_COMPLETE, |
||||
ON_RESPONSE_HEADERS_RECEIVED, |
||||
ON_RESPONSE_TRAILERS_RECEIVED |
||||
}; |
||||
|
||||
enum callback_id { |
||||
CB_SEND_INITIAL_METADATA = 0, |
||||
CB_SEND_MESSAGE, |
||||
CB_SEND_TRAILING_METADATA, |
||||
CB_RECV_MESSAGE, |
||||
CB_RECV_INITIAL_METADATA, |
||||
CB_RECV_TRAILING_METADATA, |
||||
CB_NUM_CALLBACKS |
||||
}; |
||||
|
||||
struct stream_obj { |
||||
// we store received bytes here as they trickle in.
|
||||
gpr_slice_buffer write_slice_buffer; |
||||
cronet_bidirectional_stream *cbs; |
||||
gpr_slice slice; |
||||
gpr_slice_buffer read_slice_buffer; |
||||
struct grpc_slice_buffer_stream sbs; |
||||
char *read_buffer; |
||||
int remaining_read_bytes; |
||||
int total_read_bytes; |
||||
|
||||
char *write_buffer; |
||||
size_t write_buffer_size; |
||||
|
||||
// Hold the URL
|
||||
char *url; |
||||
|
||||
bool response_headers_received; |
||||
bool read_requested; |
||||
bool response_trailers_received; |
||||
bool read_closed; |
||||
|
||||
// Recv message stuff
|
||||
grpc_byte_buffer **recv_message; |
||||
// Initial metadata stuff
|
||||
grpc_metadata_batch *recv_initial_metadata; |
||||
// Trailing metadata stuff
|
||||
grpc_metadata_batch *recv_trailing_metadata; |
||||
grpc_chttp2_incoming_metadata_buffer imb; |
||||
|
||||
// This mutex protects receive state machine execution
|
||||
gpr_mu recv_mu; |
||||
// we can queue up up to 2 callbacks for each OP
|
||||
grpc_closure *callback_list[CB_NUM_CALLBACKS][2]; |
||||
|
||||
// storage for header
|
||||
cronet_bidirectional_stream_header *headers; |
||||
uint32_t num_headers; |
||||
cronet_bidirectional_stream_header_array header_array; |
||||
// state tracking
|
||||
enum recv_state cronet_recv_state; |
||||
enum send_state cronet_send_state; |
||||
}; |
||||
|
||||
typedef struct stream_obj stream_obj; |
||||
|
||||
static void next_send_step(stream_obj *s); |
||||
static void next_recv_step(stream_obj *s, enum e_caller caller); |
||||
|
||||
static void set_pollset_do_nothing(grpc_exec_ctx *exec_ctx, grpc_transport *gt, |
||||
grpc_stream *gs, grpc_pollset *pollset) {} |
||||
|
||||
static void enqueue_callbacks(grpc_closure *callback_list[]) { |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
if (callback_list[0]) { |
||||
grpc_exec_ctx_enqueue(&exec_ctx, callback_list[0], true, NULL); |
||||
callback_list[0] = NULL; |
||||
} |
||||
if (callback_list[1]) { |
||||
grpc_exec_ctx_enqueue(&exec_ctx, callback_list[1], true, NULL); |
||||
callback_list[1] = NULL; |
||||
} |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
} |
||||
|
||||
static void on_canceled(cronet_bidirectional_stream *stream) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "on_canceled %p", stream); |
||||
} |
||||
} |
||||
|
||||
static void on_failed(cronet_bidirectional_stream *stream, int net_error) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "on_failed %p, error = %d", stream, net_error); |
||||
} |
||||
} |
||||
|
||||
static void on_succeeded(cronet_bidirectional_stream *stream) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "on_succeeded %p", stream); |
||||
} |
||||
} |
||||
|
||||
static void on_response_trailers_received( |
||||
cronet_bidirectional_stream *stream, |
||||
const cronet_bidirectional_stream_header_array *trailers) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "R: on_response_trailers_received"); |
||||
} |
||||
stream_obj *s = (stream_obj *)stream->annotation; |
||||
|
||||
memset(&s->imb, 0, sizeof(s->imb)); |
||||
grpc_chttp2_incoming_metadata_buffer_init(&s->imb); |
||||
unsigned int i = 0; |
||||
for (i = 0; i < trailers->count; i++) { |
||||
grpc_chttp2_incoming_metadata_buffer_add( |
||||
&s->imb, grpc_mdelem_from_metadata_strings( |
||||
grpc_mdstr_from_string(trailers->headers[i].key), |
||||
grpc_mdstr_from_string(trailers->headers[i].value))); |
||||
} |
||||
s->response_trailers_received = true; |
||||
next_recv_step(s, ON_RESPONSE_TRAILERS_RECEIVED); |
||||
} |
||||
|
||||
static void on_write_completed(cronet_bidirectional_stream *stream, |
||||
const char *data) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "W: on_write_completed"); |
||||
} |
||||
stream_obj *s = (stream_obj *)stream->annotation; |
||||
enqueue_callbacks(s->callback_list[CB_SEND_MESSAGE]); |
||||
s->cronet_send_state = CRONET_WRITE_COMPLETED; |
||||
next_send_step(s); |
||||
} |
||||
|
||||
static void process_recv_message(stream_obj *s, const uint8_t *recv_data) { |
||||
gpr_slice read_data_slice = gpr_slice_malloc((uint32_t)s->total_read_bytes); |
||||
uint8_t *dst_p = GPR_SLICE_START_PTR(read_data_slice); |
||||
memcpy(dst_p, recv_data, (size_t)s->total_read_bytes); |
||||
gpr_slice_buffer_add(&s->read_slice_buffer, read_data_slice); |
||||
grpc_slice_buffer_stream_init(&s->sbs, &s->read_slice_buffer, 0); |
||||
*s->recv_message = (grpc_byte_buffer *)&s->sbs; |
||||
} |
||||
|
||||
static int parse_grpc_header(const uint8_t *data) { |
||||
const uint8_t *p = data + 1; |
||||
int length = 0; |
||||
length |= ((uint8_t)*p++) << 24; |
||||
length |= ((uint8_t)*p++) << 16; |
||||
length |= ((uint8_t)*p++) << 8; |
||||
length |= ((uint8_t)*p++); |
||||
return length; |
||||
} |
||||
|
||||
static void on_read_completed(cronet_bidirectional_stream *stream, char *data, |
||||
int count) { |
||||
stream_obj *s = (stream_obj *)stream->annotation; |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "R: on_read_completed count=%d, total=%d, remaining=%d", |
||||
count, s->total_read_bytes, s->remaining_read_bytes); |
||||
} |
||||
if (count > 0) { |
||||
GPR_ASSERT(s->recv_message); |
||||
s->remaining_read_bytes -= count; |
||||
next_recv_step(s, ON_READ_COMPLETE); |
||||
} else { |
||||
s->read_closed = true; |
||||
next_recv_step(s, ON_READ_COMPLETE); |
||||
} |
||||
} |
||||
|
||||
static void on_response_headers_received( |
||||
cronet_bidirectional_stream *stream, |
||||
const cronet_bidirectional_stream_header_array *headers, |
||||
const char *negotiated_protocol) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "R: on_response_headers_received"); |
||||
} |
||||
stream_obj *s = (stream_obj *)stream->annotation; |
||||
enqueue_callbacks(s->callback_list[CB_RECV_INITIAL_METADATA]); |
||||
s->response_headers_received = true; |
||||
next_recv_step(s, ON_RESPONSE_HEADERS_RECEIVED); |
||||
} |
||||
|
||||
static void on_request_headers_sent(cronet_bidirectional_stream *stream) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "W: on_request_headers_sent"); |
||||
} |
||||
stream_obj *s = (stream_obj *)stream->annotation; |
||||
enqueue_callbacks(s->callback_list[CB_SEND_INITIAL_METADATA]); |
||||
s->cronet_send_state = CRONET_SEND_HEADER; |
||||
next_send_step(s); |
||||
} |
||||
|
||||
// Callback function pointers (invoked by cronet in response to events)
|
||||
static cronet_bidirectional_stream_callback callbacks = { |
||||
on_request_headers_sent, |
||||
on_response_headers_received, |
||||
on_read_completed, |
||||
on_write_completed, |
||||
on_response_trailers_received, |
||||
on_succeeded, |
||||
on_failed, |
||||
on_canceled}; |
||||
|
||||
static void invoke_closing_callback(stream_obj *s) { |
||||
grpc_chttp2_incoming_metadata_buffer_publish(&s->imb, |
||||
s->recv_trailing_metadata); |
||||
if (s->callback_list[CB_RECV_TRAILING_METADATA]) { |
||||
enqueue_callbacks(s->callback_list[CB_RECV_TRAILING_METADATA]); |
||||
} |
||||
} |
||||
|
||||
static void set_recv_state(stream_obj *s, enum recv_state state) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "next_state = %s", recv_state_name[state]); |
||||
} |
||||
s->cronet_recv_state = state; |
||||
} |
||||
|
||||
// This is invoked from perform_stream_op, and all on_xxxx callbacks.
|
||||
static void next_recv_step(stream_obj *s, enum e_caller caller) { |
||||
gpr_mu_lock(&s->recv_mu); |
||||
switch (s->cronet_recv_state) { |
||||
case CRONET_RECV_IDLE: |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "cronet_recv_state = CRONET_RECV_IDLE"); |
||||
} |
||||
if (caller == PERFORM_STREAM_OP || |
||||
caller == ON_RESPONSE_HEADERS_RECEIVED) { |
||||
if (s->read_closed && s->response_trailers_received) { |
||||
invoke_closing_callback(s); |
||||
set_recv_state(s, CRONET_RECV_CLOSED); |
||||
} else if (s->response_headers_received == true && |
||||
s->read_requested == true) { |
||||
set_recv_state(s, CRONET_RECV_READ_LENGTH); |
||||
s->total_read_bytes = s->remaining_read_bytes = |
||||
GRPC_HEADER_SIZE_IN_BYTES; |
||||
GPR_ASSERT(s->read_buffer); |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "R: cronet_bidirectional_stream_read()"); |
||||
} |
||||
cronet_bidirectional_stream_read(s->cbs, s->read_buffer, |
||||
s->remaining_read_bytes); |
||||
} |
||||
} |
||||
break; |
||||
case CRONET_RECV_READ_LENGTH: |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "cronet_recv_state = CRONET_RECV_READ_LENGTH"); |
||||
} |
||||
if (caller == ON_READ_COMPLETE) { |
||||
if (s->read_closed) { |
||||
invoke_closing_callback(s); |
||||
enqueue_callbacks(s->callback_list[CB_RECV_MESSAGE]); |
||||
set_recv_state(s, CRONET_RECV_CLOSED); |
||||
} else { |
||||
GPR_ASSERT(s->remaining_read_bytes == 0); |
||||
set_recv_state(s, CRONET_RECV_READ_DATA); |
||||
s->total_read_bytes = s->remaining_read_bytes = |
||||
parse_grpc_header((const uint8_t *)s->read_buffer); |
||||
s->read_buffer = |
||||
gpr_realloc(s->read_buffer, (uint32_t)s->remaining_read_bytes); |
||||
GPR_ASSERT(s->read_buffer); |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "R: cronet_bidirectional_stream_read()"); |
||||
} |
||||
cronet_bidirectional_stream_read(s->cbs, (char *)s->read_buffer, |
||||
s->remaining_read_bytes); |
||||
} |
||||
} |
||||
break; |
||||
case CRONET_RECV_READ_DATA: |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "cronet_recv_state = CRONET_RECV_READ_DATA"); |
||||
} |
||||
if (caller == ON_READ_COMPLETE) { |
||||
if (s->remaining_read_bytes > 0) { |
||||
int offset = s->total_read_bytes - s->remaining_read_bytes; |
||||
GPR_ASSERT(s->read_buffer); |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "R: cronet_bidirectional_stream_read()"); |
||||
} |
||||
cronet_bidirectional_stream_read( |
||||
s->cbs, (char *)s->read_buffer + offset, s->remaining_read_bytes); |
||||
} else { |
||||
gpr_slice_buffer_init(&s->read_slice_buffer); |
||||
uint8_t *p = (uint8_t *)s->read_buffer; |
||||
process_recv_message(s, p); |
||||
set_recv_state(s, CRONET_RECV_IDLE); |
||||
enqueue_callbacks(s->callback_list[CB_RECV_MESSAGE]); |
||||
} |
||||
} |
||||
break; |
||||
case CRONET_RECV_CLOSED: |
||||
break; |
||||
default: |
||||
GPR_ASSERT(0); // Should not reach here
|
||||
break; |
||||
} |
||||
gpr_mu_unlock(&s->recv_mu); |
||||
} |
||||
|
||||
// This function takes the data from s->write_slice_buffer and assembles into
|
||||
// a contiguous byte stream with 5 byte gRPC header prepended.
|
||||
static void create_grpc_frame(stream_obj *s) { |
||||
gpr_slice slice = gpr_slice_buffer_take_first(&s->write_slice_buffer); |
||||
uint8_t *raw_data = GPR_SLICE_START_PTR(slice); |
||||
size_t length = GPR_SLICE_LENGTH(slice); |
||||
s->write_buffer_size = length + GRPC_HEADER_SIZE_IN_BYTES; |
||||
s->write_buffer = gpr_realloc(s->write_buffer, s->write_buffer_size); |
||||
uint8_t *p = (uint8_t *)s->write_buffer; |
||||
// Append 5 byte header
|
||||
*p++ = 0; |
||||
*p++ = (uint8_t)(length >> 24); |
||||
*p++ = (uint8_t)(length >> 16); |
||||
*p++ = (uint8_t)(length >> 8); |
||||
*p++ = (uint8_t)(length); |
||||
// append actual data
|
||||
memcpy(p, raw_data, length); |
||||
} |
||||
|
||||
static void do_write(stream_obj *s) { |
||||
gpr_slice_buffer *sb = &s->write_slice_buffer; |
||||
GPR_ASSERT(sb->count <= 1); |
||||
if (sb->count > 0) { |
||||
create_grpc_frame(s); |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "W: cronet_bidirectional_stream_write"); |
||||
} |
||||
cronet_bidirectional_stream_write(s->cbs, s->write_buffer, |
||||
(int)s->write_buffer_size, false); |
||||
} |
||||
} |
||||
|
||||
//
|
||||
static void next_send_step(stream_obj *s) { |
||||
switch (s->cronet_send_state) { |
||||
case CRONET_SEND_IDLE: |
||||
GPR_ASSERT( |
||||
s->cbs); // cronet_bidirectional_stream is not initialized yet.
|
||||
s->cronet_send_state = CRONET_REQ_STARTED; |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "cronet_bidirectional_stream_start to %s", s->url); |
||||
} |
||||
cronet_bidirectional_stream_start(s->cbs, s->url, 0, "POST", |
||||
&s->header_array, false); |
||||
// we no longer need the memory that was allocated earlier.
|
||||
gpr_free(s->header_array.headers); |
||||
break; |
||||
case CRONET_SEND_HEADER: |
||||
do_write(s); |
||||
s->cronet_send_state = CRONET_WRITE; |
||||
break; |
||||
case CRONET_WRITE_COMPLETED: |
||||
do_write(s); |
||||
break; |
||||
default: |
||||
GPR_ASSERT(0); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
static void convert_metadata_to_cronet_headers(grpc_linked_mdelem *head, |
||||
const char *host, |
||||
stream_obj *s) { |
||||
grpc_linked_mdelem *curr = head; |
||||
// Walk the linked list and get number of header fields
|
||||
uint32_t num_headers_available = 0; |
||||
while (curr != NULL) { |
||||
curr = curr->next; |
||||
num_headers_available++; |
||||
} |
||||
// Allocate enough memory
|
||||
s->headers = (cronet_bidirectional_stream_header *)gpr_malloc( |
||||
sizeof(cronet_bidirectional_stream_header) * num_headers_available); |
||||
|
||||
// Walk the linked list again, this time copying the header fields.
|
||||
// s->num_headers
|
||||
// can be less than num_headers_available, as some headers are not used for
|
||||
// cronet
|
||||
curr = head; |
||||
s->num_headers = 0; |
||||
while (s->num_headers < num_headers_available) { |
||||
grpc_mdelem *mdelem = curr->md; |
||||
curr = curr->next; |
||||
const char *key = grpc_mdstr_as_c_string(mdelem->key); |
||||
const char *value = grpc_mdstr_as_c_string(mdelem->value); |
||||
if (strcmp(key, ":scheme") == 0 || strcmp(key, ":method") == 0 || |
||||
strcmp(key, ":authority") == 0) { |
||||
// Cronet populates these fields on its own.
|
||||
continue; |
||||
} |
||||
if (strcmp(key, ":path") == 0) { |
||||
// Create URL by appending :path value to the hostname
|
||||
gpr_asprintf(&s->url, "https://%s%s", host, value); |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "extracted URL = %s", s->url); |
||||
} |
||||
continue; |
||||
} |
||||
s->headers[s->num_headers].key = key; |
||||
s->headers[s->num_headers].value = value; |
||||
s->num_headers++; |
||||
if (curr == NULL) { |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, |
||||
grpc_stream *gs, grpc_transport_stream_op *op) { |
||||
grpc_cronet_transport *ct = (grpc_cronet_transport *)gt; |
||||
GPR_ASSERT(ct->engine); |
||||
stream_obj *s = (stream_obj *)gs; |
||||
if (op->recv_trailing_metadata) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, |
||||
"perform_stream_op - recv_trailing_metadata: on_complete=%p", |
||||
op->on_complete); |
||||
} |
||||
s->recv_trailing_metadata = op->recv_trailing_metadata; |
||||
GPR_ASSERT(!s->callback_list[CB_RECV_TRAILING_METADATA][0]); |
||||
s->callback_list[CB_RECV_TRAILING_METADATA][0] = op->on_complete; |
||||
} |
||||
if (op->recv_message) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "perform_stream_op - recv_message: on_complete=%p", |
||||
op->on_complete); |
||||
} |
||||
s->recv_message = (grpc_byte_buffer **)op->recv_message; |
||||
GPR_ASSERT(!s->callback_list[CB_RECV_MESSAGE][0]); |
||||
GPR_ASSERT(!s->callback_list[CB_RECV_MESSAGE][1]); |
||||
s->callback_list[CB_RECV_MESSAGE][0] = op->recv_message_ready; |
||||
s->callback_list[CB_RECV_MESSAGE][1] = op->on_complete; |
||||
s->read_requested = true; |
||||
next_recv_step(s, PERFORM_STREAM_OP); |
||||
} |
||||
if (op->recv_initial_metadata) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "perform_stream_op - recv_initial_metadata:=%p", |
||||
op->on_complete); |
||||
} |
||||
s->recv_initial_metadata = op->recv_initial_metadata; |
||||
GPR_ASSERT(!s->callback_list[CB_RECV_INITIAL_METADATA][0]); |
||||
GPR_ASSERT(!s->callback_list[CB_RECV_INITIAL_METADATA][1]); |
||||
s->callback_list[CB_RECV_INITIAL_METADATA][0] = |
||||
op->recv_initial_metadata_ready; |
||||
s->callback_list[CB_RECV_INITIAL_METADATA][1] = op->on_complete; |
||||
} |
||||
if (op->send_initial_metadata) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, |
||||
"perform_stream_op - send_initial_metadata: on_complete=%p", |
||||
op->on_complete); |
||||
} |
||||
s->num_headers = 0; |
||||
convert_metadata_to_cronet_headers(op->send_initial_metadata->list.head, |
||||
ct->host, s); |
||||
s->header_array.count = s->num_headers; |
||||
s->header_array.capacity = s->num_headers; |
||||
s->header_array.headers = s->headers; |
||||
GPR_ASSERT(!s->callback_list[CB_SEND_INITIAL_METADATA][0]); |
||||
s->callback_list[CB_SEND_INITIAL_METADATA][0] = op->on_complete; |
||||
} |
||||
if (op->send_message) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "perform_stream_op - send_message: on_complete=%p", |
||||
op->on_complete); |
||||
} |
||||
grpc_byte_stream_next(exec_ctx, op->send_message, &s->slice, |
||||
op->send_message->length, NULL); |
||||
// Check that compression flag is not ON. We don't support compression yet.
|
||||
// TODO (makdharma): add compression support
|
||||
GPR_ASSERT(op->send_message->flags == 0); |
||||
gpr_slice_buffer_add(&s->write_slice_buffer, s->slice); |
||||
if (s->cbs == NULL) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "cronet_bidirectional_stream_create"); |
||||
} |
||||
s->cbs = cronet_bidirectional_stream_create(ct->engine, s, &callbacks); |
||||
GPR_ASSERT(s->cbs); |
||||
s->read_closed = false; |
||||
s->response_trailers_received = false; |
||||
s->response_headers_received = false; |
||||
s->cronet_send_state = CRONET_SEND_IDLE; |
||||
s->cronet_recv_state = CRONET_RECV_IDLE; |
||||
} |
||||
GPR_ASSERT(!s->callback_list[CB_SEND_MESSAGE][0]); |
||||
s->callback_list[CB_SEND_MESSAGE][0] = op->on_complete; |
||||
next_send_step(s); |
||||
} |
||||
if (op->send_trailing_metadata) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, |
||||
"perform_stream_op - send_trailing_metadata: on_complete=%p", |
||||
op->on_complete); |
||||
} |
||||
GPR_ASSERT(!s->callback_list[CB_SEND_TRAILING_METADATA][0]); |
||||
s->callback_list[CB_SEND_TRAILING_METADATA][0] = op->on_complete; |
||||
if (s->cbs) { |
||||
// Send an "empty" write to the far end to signal that we're done.
|
||||
// This will induce the server to send down trailers.
|
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "W: cronet_bidirectional_stream_write"); |
||||
} |
||||
cronet_bidirectional_stream_write(s->cbs, "abc", 0, true); |
||||
} else { |
||||
// We never created a stream. This was probably an empty request.
|
||||
invoke_closing_callback(s); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, |
||||
grpc_stream *gs, grpc_stream_refcount *refcount, |
||||
const void *server_data) { |
||||
stream_obj *s = (stream_obj *)gs; |
||||
memset(s->callback_list, 0, sizeof(s->callback_list)); |
||||
s->cbs = NULL; |
||||
gpr_mu_init(&s->recv_mu); |
||||
s->read_buffer = gpr_malloc(GRPC_HEADER_SIZE_IN_BYTES); |
||||
s->write_buffer = gpr_malloc(GRPC_HEADER_SIZE_IN_BYTES); |
||||
gpr_slice_buffer_init(&s->write_slice_buffer); |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "cronet_transport - init_stream"); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static void destroy_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt, |
||||
grpc_stream *gs, void *and_free_memory) { |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "Destroy stream"); |
||||
} |
||||
stream_obj *s = (stream_obj *)gs; |
||||
s->cbs = NULL; |
||||
gpr_free(s->read_buffer); |
||||
gpr_free(s->write_buffer); |
||||
gpr_free(s->url); |
||||
gpr_mu_destroy(&s->recv_mu); |
||||
if (and_free_memory) { |
||||
gpr_free(and_free_memory); |
||||
} |
||||
} |
||||
|
||||
static void destroy_transport(grpc_exec_ctx *exec_ctx, grpc_transport *gt) { |
||||
grpc_cronet_transport *ct = (grpc_cronet_transport *)gt; |
||||
gpr_free(ct->host); |
||||
if (grpc_cronet_trace) { |
||||
gpr_log(GPR_DEBUG, "Destroy transport"); |
||||
} |
||||
} |
||||
|
||||
const grpc_transport_vtable grpc_cronet_vtable = { |
||||
sizeof(stream_obj), "cronet_http", init_stream, |
||||
set_pollset_do_nothing, perform_stream_op, NULL, |
||||
destroy_stream, destroy_transport, NULL}; |
@ -0,0 +1,34 @@ |
||||
%YAML 1.2 |
||||
--- | |
||||
# 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. |
||||
|
||||
# AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_version.py.template`!!! |
||||
|
||||
VERSION='${settings.python_version.pep440()}' |
@ -0,0 +1,202 @@ |
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_ |
||||
#define COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_ |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#include <stddef.h> |
||||
|
||||
/* Cronet Engine API. */ |
||||
|
||||
/* Opaque object representing Cronet Engine. Created and configured outside
|
||||
* of this API to facilitate sharing with other components */ |
||||
typedef struct cronet_engine { void* obj; } cronet_engine; |
||||
|
||||
void cronet_engine_add_quic_hint(cronet_engine* engine, |
||||
const char* host, |
||||
int port, |
||||
int alternate_port); |
||||
|
||||
/* Cronet Bidirectional Stream API */ |
||||
|
||||
/* Opaque object representing Cronet Bidirectional Stream. */ |
||||
typedef struct cronet_bidirectional_stream { |
||||
void* obj; |
||||
void* annotation; |
||||
} cronet_bidirectional_stream; |
||||
|
||||
/* A single request or response header element. */ |
||||
typedef struct cronet_bidirectional_stream_header { |
||||
const char* key; |
||||
const char* value; |
||||
} cronet_bidirectional_stream_header; |
||||
|
||||
/* Array of request or response headers or trailers. */ |
||||
typedef struct cronet_bidirectional_stream_header_array { |
||||
size_t count; |
||||
size_t capacity; |
||||
cronet_bidirectional_stream_header* headers; |
||||
} cronet_bidirectional_stream_header_array; |
||||
|
||||
/* Set of callbacks used to receive callbacks from bidirectional stream. */ |
||||
typedef struct cronet_bidirectional_stream_callback { |
||||
/* Invoked when request headers are sent. Indicates that stream has initiated
|
||||
* the request. Consumer may call cronet_bidirectional_stream_write() to start |
||||
* writing data. |
||||
*/ |
||||
void (*on_request_headers_sent)(cronet_bidirectional_stream* stream); |
||||
|
||||
/* Invoked when initial response headers are received.
|
||||
* Consumer must call cronet_bidirectional_stream_read() to start reading. |
||||
* Consumer may call cronet_bidirectional_stream_write() to start writing or |
||||
* close the stream. Contents of |headers| is valid for duration of the call. |
||||
*/ |
||||
void (*on_response_headers_received)( |
||||
cronet_bidirectional_stream* stream, |
||||
const cronet_bidirectional_stream_header_array* headers, |
||||
const char* negotiated_protocol); |
||||
|
||||
/* Invoked when data is read into the buffer passed to
|
||||
* cronet_bidirectional_stream_read(). Only part of the buffer may be |
||||
* populated. To continue reading, call cronet_bidirectional_stream_read(). |
||||
* It may be invoked after on_response_trailers_received()}, if there was |
||||
* pending read data before trailers were received. |
||||
* |
||||
* If count is 0, it means the remote side has signaled that it will send no |
||||
* more data; future calls to cronet_bidirectional_stream_read() will result |
||||
* in the on_data_read() callback or on_succeded() callback if |
||||
* cronet_bidirectional_stream_write() was invoked with end_of_stream set to |
||||
* true. |
||||
*/ |
||||
void (*on_read_completed)(cronet_bidirectional_stream* stream, |
||||
char* data, |
||||
int count); |
||||
|
||||
/**
|
||||
* Invoked when all data passed to cronet_bidirectional_stream_write() is |
||||
* sent. |
||||
* To continue writing, call cronet_bidirectional_stream_write(). |
||||
*/ |
||||
void (*on_write_completed)(cronet_bidirectional_stream* stream, |
||||
const char* data); |
||||
|
||||
/* Invoked when trailers are received before closing the stream. Only invoked
|
||||
* when server sends trailers, which it may not. May be invoked while there is |
||||
* read data remaining in local buffer. Contents of |trailers| is valid for |
||||
* duration of the call. |
||||
*/ |
||||
void (*on_response_trailers_received)( |
||||
cronet_bidirectional_stream* stream, |
||||
const cronet_bidirectional_stream_header_array* trailers); |
||||
|
||||
/**
|
||||
* Invoked when there is no data to be read or written and the stream is |
||||
* closed successfully remotely and locally. Once invoked, no further callback |
||||
* methods will be invoked. |
||||
*/ |
||||
void (*on_succeded)(cronet_bidirectional_stream* stream); |
||||
|
||||
/**
|
||||
* Invoked if the stream failed for any reason after |
||||
* cronet_bidirectional_stream_start(). HTTP/2 error codes are |
||||
* mapped to chrome net error codes. Once invoked, no further callback methods |
||||
* will be invoked. |
||||
*/ |
||||
void (*on_failed)(cronet_bidirectional_stream* stream, int net_error); |
||||
|
||||
/**
|
||||
* Invoked if the stream was canceled via |
||||
* cronet_bidirectional_stream_cancel(). Once invoked, no further callback |
||||
* methods will be invoked. |
||||
*/ |
||||
void (*on_canceled)(cronet_bidirectional_stream* stream); |
||||
} cronet_bidirectional_stream_callback; |
||||
|
||||
/* Create a new stream object that uses |engine| and |callback|. All stream
|
||||
* tasks are performed asynchronously on the |engine| network thread. |callback| |
||||
* methods are invoked synchronously on the |engine| network thread, but must |
||||
* not run tasks on the current thread to prevent blocking networking operations |
||||
* and causing exceptions during shutdown. The |annotation| is stored in |
||||
* bidirectional stream for arbitrary use by application. |
||||
* |
||||
* Returned |cronet_bidirectional_stream*| is owned by the caller, and must be |
||||
* destroyed using |cronet_bidirectional_stream_destroy|. |
||||
* |
||||
* Both |calback| and |engine| must remain valid until stream is destroyed. |
||||
*/ |
||||
cronet_bidirectional_stream* cronet_bidirectional_stream_create( |
||||
cronet_engine* engine, |
||||
void* annotation, |
||||
cronet_bidirectional_stream_callback* callback); |
||||
|
||||
/* TBD: The following methods return int. Should it be a custom type? */ |
||||
|
||||
/* Destroy stream object. Destroy could be called from any thread, including
|
||||
* network thread, but is posted, so |stream| is valid until calling task is |
||||
* complete. |
||||
*/ |
||||
int cronet_bidirectional_stream_destroy(cronet_bidirectional_stream* stream); |
||||
|
||||
/* Start the stream by sending request to |url| using |method| and |headers|. If
|
||||
* |end_of_stream| is true, then no data is expected to be written. |
||||
*/ |
||||
int cronet_bidirectional_stream_start( |
||||
cronet_bidirectional_stream* stream, |
||||
const char* url, |
||||
int priority, |
||||
const char* method, |
||||
const cronet_bidirectional_stream_header_array* headers, |
||||
bool end_of_stream); |
||||
|
||||
/* Read response data into |buffer| of |capacity| length. Must only be called at
|
||||
* most once in response to each invocation of the |
||||
* on_response_headers_received() and on_read_completed() methods of the |
||||
* cronet_bidirectional_stream_callback. |
||||
* Each call will result in an invocation of one of the callback's |
||||
* on_read_completed method if data is read, its on_succeeded() method if |
||||
* the stream is closed, or its on_failed() method if there's an error. |
||||
*/ |
||||
int cronet_bidirectional_stream_read(cronet_bidirectional_stream* stream, |
||||
char* buffer, |
||||
int capacity); |
||||
|
||||
/* Read response data into |buffer| of |capacity| length. Must only be called at
|
||||
* most once in response to each invocation of the |
||||
* on_response_headers_received() and on_read_completed() methods of the |
||||
* cronet_bidirectional_stream_callback. |
||||
* Each call will result in an invocation of one of the callback's |
||||
* on_read_completed method if data is read, its on_succeeded() method if |
||||
* the stream is closed, or its on_failed() method if there's an error. |
||||
*/ |
||||
int cronet_bidirectional_stream_write(cronet_bidirectional_stream* stream, |
||||
const char* buffer, |
||||
int count, |
||||
bool end_of_stream); |
||||
|
||||
/* Cancels the stream. Can be called at any time after
|
||||
* cronet_bidirectional_stream_start(). The on_canceled() method of |
||||
* cronet_bidirectional_stream_callback will be invoked when cancelation |
||||
* is complete and no further callback methods will be invoked. If the |
||||
* stream has completed or has not started, calling |
||||
* cronet_bidirectional_stream_cancel() has no effect and on_canceled() will not |
||||
* be invoked. At most one callback method may be invoked after |
||||
* cronet_bidirectional_stream_cancel() has completed. |
||||
*/ |
||||
int cronet_bidirectional_stream_cancel(cronet_bidirectional_stream* stream); |
||||
|
||||
/* Returns true if the |stream| was successfully started and is now done
|
||||
* (succeeded, canceled, or failed). |
||||
* Returns false if the |stream| stream is not yet started or is in progress. |
||||
*/ |
||||
bool cronet_bidirectional_stream_is_done(cronet_bidirectional_stream* stream); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif // COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_
|
@ -0,0 +1,46 @@ |
||||
#!/bin/bash |
||||
|
||||
# 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. |
||||
|
||||
cd $(dirname $0)/../../../ |
||||
|
||||
# First check if bazel is installed on the machine. If it is, then we don't need |
||||
# to invoke the docker bazel. |
||||
if [ "bazel version" ] |
||||
then |
||||
cd third_party/protobuf |
||||
bazel query 'deps('$1')' |
||||
else |
||||
docker build -t bazel `realpath ./tools/dockerfile/bazel/` |
||||
docker run -v "`realpath .`:/src/grpc/" \ |
||||
-w /src/grpc/third_party/protobuf \ |
||||
bazel \ |
||||
bazel query 'deps('$1')' |
||||
fi |
@ -0,0 +1,45 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
# 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. |
||||
|
||||
import cStringIO |
||||
|
||||
import make_grpcio_tools as make |
||||
|
||||
OUT_OF_DATE_MESSAGE = """file {} is out of date |
||||
|
||||
Have you called tools/distrib/python/make_grpcio_tools.py since upgrading protobuf?""" |
||||
|
||||
check_protoc_lib_deps_content = make.get_deps(make.BAZEL_DEPS_PROTOC_LIB_QUERY) |
||||
|
||||
with open(make.GRPC_PYTHON_PROTOC_LIB_DEPS, 'r') as protoc_lib_deps_file: |
||||
if protoc_lib_deps_file.read() != check_protoc_lib_deps_content: |
||||
print(OUT_OF_DATE_MESSAGE.format(make.GRPC_PYTHON_PROTOC_LIB_DEPS)) |
||||
raise SystemExit(1) |
@ -0,0 +1,7 @@ |
||||
build/ |
||||
protobuf/ |
||||
grpc_plugin/ |
||||
grpc_root/ |
||||
*.c |
||||
*.cpp |
||||
*.egg-info |
@ -0,0 +1,5 @@ |
||||
include protoc_deps.py |
||||
include protoc_lib_deps.py |
||||
graft grpc |
||||
graft grpc_root |
||||
graft third_party |
@ -0,0 +1,30 @@ |
||||
# 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. |
||||
|
||||
__import__('pkg_resources').declare_namespace(__name__) |
@ -0,0 +1,29 @@ |
||||
# 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. |
||||
|
@ -0,0 +1,38 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
# 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. |
||||
|
||||
import sys |
||||
|
||||
from grpc.protoc import protoc_compiler |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
protoc_compiler.run_main(sys.argv) |
@ -0,0 +1,54 @@ |
||||
// Copyright 2016, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <google/protobuf/compiler/command_line_interface.h> |
||||
#include <google/protobuf/compiler/python/python_generator.h> |
||||
|
||||
#include "src/compiler/python_generator.h" |
||||
|
||||
#include "grpc/protoc/main.h" |
||||
|
||||
int protoc_main(int argc, char* argv[]) { |
||||
google::protobuf::compiler::CommandLineInterface cli; |
||||
cli.AllowPlugins("protoc-"); |
||||
|
||||
// Proto2 Python
|
||||
google::protobuf::compiler::python::Generator py_generator; |
||||
cli.RegisterGenerator("--python_out", &py_generator, |
||||
"Generate Python source file."); |
||||
|
||||
// gRPC Python
|
||||
grpc_python_generator::GeneratorConfiguration grpc_py_config; |
||||
grpc_py_config.beta_package_root = "grpc.beta"; |
||||
grpc_python_generator::PythonGrpcGenerator grpc_py_generator(grpc_py_config); |
||||
cli.RegisterGenerator("--grpc_python_out", &grpc_py_generator, |
||||
"Generate Python source file."); |
||||
|
||||
return cli.Run(argc, argv); |
||||
} |
@ -0,0 +1,33 @@ |
||||
// 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.
|
||||
|
||||
|
||||
// We declare `protoc_main` here since we want access to it from Cython as an
|
||||
// extern but *without* triggering a dllimport declspec when on Windows.
|
||||
int protoc_main(int argc, char *argv[]); |
@ -0,0 +1,39 @@ |
||||
# 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. |
||||
|
||||
from libc cimport stdlib |
||||
|
||||
cdef extern from "grpc/protoc/main.h": |
||||
int protoc_main(int argc, char *argv[]) |
||||
|
||||
def run_main(list args not None): |
||||
cdef char **argv = <char **>stdlib.malloc(len(args)*sizeof(char *)) |
||||
for i in range(len(args)): |
||||
argv[i] = args[i] |
||||
return protoc_main(len(args), argv) |
@ -0,0 +1,32 @@ |
||||
# 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. |
||||
|
||||
# AUTO-GENERATED FROM `$REPO_ROOT/templates/tools/distrib/python/grpcio_tools/grpc_version.py.template`!!! |
||||
|
||||
VERSION='0.15.0.dev0' |
File diff suppressed because one or more lines are too long
@ -0,0 +1,84 @@ |
||||
# 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. |
||||
|
||||
from distutils import extension |
||||
import os |
||||
import os.path |
||||
import sys |
||||
|
||||
import setuptools |
||||
from setuptools.command import build_ext |
||||
|
||||
# TODO(atash) add flag to disable Cython use |
||||
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__))) |
||||
sys.path.insert(0, os.path.abspath('.')) |
||||
|
||||
import protoc_lib_deps |
||||
import grpc_version |
||||
|
||||
def protoc_ext_module(): |
||||
plugin_sources = [ |
||||
'grpc/protoc/main.cc', |
||||
'grpc_root/src/compiler/python_generator.cc'] + [ |
||||
os.path.join('third_party/protobuf/src', cc_file) |
||||
for cc_file in protoc_lib_deps.CC_FILES] |
||||
plugin_ext = extension.Extension( |
||||
name='grpc.protoc.protoc_compiler', |
||||
sources=['grpc/protoc/protoc_compiler.pyx'] + plugin_sources, |
||||
include_dirs=[ |
||||
'.', |
||||
'grpc_root', |
||||
'grpc_root/include', |
||||
'third_party/protobuf/src', |
||||
], |
||||
language='c++', |
||||
define_macros=[('HAVE_PTHREAD', 1)], |
||||
extra_compile_args=['-lpthread', '-frtti', '-std=c++11'], |
||||
) |
||||
return plugin_ext |
||||
|
||||
def maybe_cythonize(exts): |
||||
from Cython import Build |
||||
return Build.cythonize(exts) |
||||
|
||||
setuptools.setup( |
||||
name='grpcio_tools', |
||||
version=grpc_version.VERSION, |
||||
license='', |
||||
ext_modules=maybe_cythonize([ |
||||
protoc_ext_module(), |
||||
]), |
||||
packages=setuptools.find_packages('.'), |
||||
# TODO(atash): Figure out why auditwheel doesn't like namespace packages. |
||||
#namespace_packages=['grpc'], |
||||
install_requires=[ |
||||
'protobuf>=3.0.0a3', |
||||
], |
||||
) |
@ -0,0 +1,140 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
# 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. |
||||
|
||||
import os |
||||
import os.path |
||||
import shutil |
||||
import subprocess |
||||
import sys |
||||
import traceback |
||||
|
||||
DEPS_FILE_CONTENT=""" |
||||
# 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. |
||||
|
||||
# AUTO-GENERATED BY make_grpcio_tools.py! |
||||
CC_FILES={} |
||||
""" |
||||
|
||||
# Bazel query result prefix for expected source files in protobuf. |
||||
PROTOBUF_CC_PREFIX = '//:src/' |
||||
|
||||
GRPC_ROOT = os.path.abspath( |
||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), |
||||
'..', '..', '..')) |
||||
|
||||
GRPC_PYTHON_ROOT = os.path.join(GRPC_ROOT, 'tools/distrib/python/grpcio_tools') |
||||
|
||||
GRPC_PROTOBUF = os.path.join(GRPC_ROOT, 'third_party/protobuf/src') |
||||
GRPC_PROTOC_PLUGINS = os.path.join(GRPC_ROOT, 'src/compiler') |
||||
GRPC_PYTHON_PROTOBUF = os.path.join(GRPC_PYTHON_ROOT, |
||||
'third_party/protobuf/src') |
||||
GRPC_PYTHON_PROTOC_PLUGINS = os.path.join(GRPC_PYTHON_ROOT, |
||||
'grpc_root/src/compiler') |
||||
GRPC_PYTHON_PROTOC_LIB_DEPS = os.path.join(GRPC_PYTHON_ROOT, |
||||
'protoc_lib_deps.py') |
||||
|
||||
GRPC_INCLUDE = os.path.join(GRPC_ROOT, 'include') |
||||
GRPC_PYTHON_INCLUDE = os.path.join(GRPC_PYTHON_ROOT, 'grpc_root/include') |
||||
|
||||
BAZEL_DEPS = os.path.join(GRPC_ROOT, 'tools/distrib/python/bazel_deps.sh') |
||||
BAZEL_DEPS_PROTOC_LIB_QUERY = '//:protoc_lib' |
||||
|
||||
|
||||
def get_deps(query): |
||||
"""Write the result of the bazel query `query` against protobuf to |
||||
`out_file`.""" |
||||
output = subprocess.check_output([BAZEL_DEPS, query]) |
||||
output = output.splitlines() |
||||
cc_files = [ |
||||
name for name in output |
||||
if name.endswith('.cc') and name.startswith(PROTOBUF_CC_PREFIX)] |
||||
cc_files = [cc_file[len(PROTOBUF_CC_PREFIX):] for cc_file in cc_files] |
||||
deps_file_content = DEPS_FILE_CONTENT.format(cc_files) |
||||
return deps_file_content |
||||
|
||||
|
||||
def main(): |
||||
os.chdir(GRPC_ROOT) |
||||
|
||||
for tree in [GRPC_PYTHON_PROTOBUF, |
||||
GRPC_PYTHON_PROTOC_PLUGINS, |
||||
GRPC_PYTHON_INCLUDE]: |
||||
try: |
||||
shutil.rmtree(tree) |
||||
except Exception as _: |
||||
pass |
||||
shutil.copytree(GRPC_PROTOBUF, GRPC_PYTHON_PROTOBUF) |
||||
shutil.copytree(GRPC_PROTOC_PLUGINS, GRPC_PYTHON_PROTOC_PLUGINS) |
||||
shutil.copytree(GRPC_INCLUDE, GRPC_PYTHON_INCLUDE) |
||||
|
||||
try: |
||||
protoc_lib_deps_content = get_deps(BAZEL_DEPS_PROTOC_LIB_QUERY) |
||||
except Exception as error: |
||||
# We allow this script to succeed even if we couldn't get the dependencies, |
||||
# as then we can assume that even without a successful bazel run the |
||||
# dependencies currently in source control are 'good enough'. |
||||
sys.stderr.write("Got non-fatal error:\n") |
||||
traceback.print_exc(file=sys.stderr) |
||||
return |
||||
# If we successfully got the dependencies, truncate and rewrite the deps file. |
||||
with open(GRPC_PYTHON_PROTOC_LIB_DEPS, 'w') as deps_file: |
||||
deps_file.write(protoc_lib_deps_content) |
||||
|
||||
if __name__ == '__main__': |
||||
main() |
||||
|
@ -0,0 +1,52 @@ |
||||
# 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. |
||||
|
||||
FROM ubuntu:wily |
||||
RUN apt-get update |
||||
RUN apt-get -y install software-properties-common python-software-properties |
||||
RUN add-apt-repository ppa:webupd8team/java |
||||
RUN apt-get update |
||||
RUN apt-get -y install \ |
||||
vim \ |
||||
wget \ |
||||
openjdk-8-jdk \ |
||||
pkg-config \ |
||||
zip \ |
||||
g++ \ |
||||
zlib1g-dev \ |
||||
unzip \ |
||||
git |
||||
|
||||
RUN git clone https://github.com/bazelbuild/bazel.git /bazel |
||||
RUN cd /bazel && ./compile.sh |
||||
|
||||
RUN ln -s /bazel/output/bazel /bin/ |
||||
|
||||
# ensure the installation has been extracted |
||||
RUN bazel |
@ -0,0 +1,43 @@ |
||||
# 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. |
||||
|
||||
# Docker file for building gRPC manylinux Python artifacts. |
||||
|
||||
FROM quay.io/pypa/manylinux1_x86_64 |
||||
|
||||
# Update the package manager |
||||
RUN yum update -y |
||||
|
||||
################################### |
||||
# Install Python build requirements |
||||
RUN /opt/python/cp27-cp27m/bin/pip install cython |
||||
RUN /opt/python/cp27-cp27mu/bin/pip install cython |
||||
RUN /opt/python/cp34-cp34m/bin/pip install cython |
||||
RUN /opt/python/cp35-cp35m/bin/pip install cython |
||||
|
@ -0,0 +1,43 @@ |
||||
# 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. |
||||
|
||||
# Docker file for building gRPC manylinux Python artifacts. |
||||
|
||||
FROM quay.io/pypa/manylinux1_i686 |
||||
|
||||
# Update the package manager |
||||
RUN yum update -y |
||||
|
||||
################################### |
||||
# Install Python build requirements |
||||
RUN /opt/python/cp27-cp27m/bin/pip install cython |
||||
RUN /opt/python/cp27-cp27mu/bin/pip install cython |
||||
RUN /opt/python/cp34-cp34m/bin/pip install cython |
||||
RUN /opt/python/cp35-cp35m/bin/pip install cython |
||||
|
Loading…
Reference in new issue