Skip to content

Commit

Permalink
sync to head and run clang-format again
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-g committed Mar 19, 2015
2 parents 757afae + 99f1c1e commit 1fc0469
Show file tree
Hide file tree
Showing 69 changed files with 950 additions and 766 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,11 @@ test_cxx: buildtests_cxx
$(Q) $(BINDIR)/$(CONFIG)/thread_pool_test || ( echo test thread_pool_test failed ; exit 1 )


test_python: static_c
$(E) "[RUN] Testing python code"
$(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG)


tools: privatelibs $(BINDIR)/$(CONFIG)/gen_hpack_tables $(BINDIR)/$(CONFIG)/grpc_create_jwt $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 $(BINDIR)/$(CONFIG)/grpc_print_google_default_creds_token

buildbenchmarks: privatelibs $(BINDIR)/$(CONFIG)/grpc_completion_queue_benchmark $(BINDIR)/$(CONFIG)/low_level_ping_pong_benchmark
Expand Down
84 changes: 44 additions & 40 deletions include/grpc++/completion_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,46 +89,50 @@ class CompletionQueue {
bool Next(void** tag, bool* ok) {
return (AsyncNext(tag, ok, std::chrono::system_clock::time_point::max()) !=
SHUTDOWN);
}

// Shutdown has to be called, and the CompletionQueue can only be
// destructed when false is returned from Next().
void Shutdown();

grpc_completion_queue* cq() { return cq_; }

private:
// Friend synchronous wrappers so that they can access Pluck(), which is
// a semi-private API geared towards the synchronous implementation.
template <class R>
friend class ::grpc::ClientReader;
template <class W>
friend class ::grpc::ClientWriter;
template <class R, class W>
friend class ::grpc::ClientReaderWriter;
template <class R>
friend class ::grpc::ServerReader;
template <class W>
friend class ::grpc::ServerWriter;
template <class R, class W>
friend class ::grpc::ServerReaderWriter;
friend class ::grpc::Server;
friend class ::grpc::ServerContext;
friend Status BlockingUnaryCall(ChannelInterface* channel,
const RpcMethod& method,
ClientContext* context,
const grpc::protobuf::Message& request,
grpc::protobuf::Message* result);

// Wraps grpc_completion_queue_pluck.
// Cannot be mixed with calls to Next().
bool Pluck(CompletionQueueTag* tag);

// Does a single polling pluck on tag
void TryPluck(CompletionQueueTag* tag);

grpc_completion_queue* cq_; // owned
};

bool Next(void** tag, bool* ok) {
return (
AsyncNext(tag, ok, (std::chrono::system_clock::time_point::max)()) !=
SHUTDOWN);
}

// Shutdown has to be called, and the CompletionQueue can only be
// destructed when false is returned from Next().
void Shutdown();

grpc_completion_queue* cq() { return cq_; }

private:
// Friend synchronous wrappers so that they can access Pluck(), which is
// a semi-private API geared towards the synchronous implementation.
template <class R>
friend class ::grpc::ClientReader;
template <class W>
friend class ::grpc::ClientWriter;
template <class R, class W>
friend class ::grpc::ClientReaderWriter;
template <class R>
friend class ::grpc::ServerReader;
template <class W>
friend class ::grpc::ServerWriter;
template <class R, class W>
friend class ::grpc::ServerReaderWriter;
friend class ::grpc::Server;
friend class ::grpc::ServerContext;
friend Status BlockingUnaryCall(
ChannelInterface * channel, const RpcMethod& method,
ClientContext* context, const grpc::protobuf::Message& request,
grpc::protobuf::Message* result);

// Wraps grpc_completion_queue_pluck.
// Cannot be mixed with calls to Next().
bool Pluck(CompletionQueueTag * tag);

// Does a single polling pluck on tag
void TryPluck(CompletionQueueTag * tag);

grpc_completion_queue* cq_; // owned
};

} // namespace grpc

Expand Down
6 changes: 6 additions & 0 deletions include/grpc++/credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ std::unique_ptr<Credentials> ServiceAccountCredentials(
std::unique_ptr<Credentials> JWTCredentials(
const grpc::string& json_key, std::chrono::seconds token_lifetime);

// Builds refresh token credentials.
// json_refresh_token is the JSON string containing the refresh token along
// with a client_id and client_secret.
std::unique_ptr<Credentials> RefreshTokenCredentials(
const grpc::string& json_refresh_token);

// Builds IAM credentials.
std::unique_ptr<Credentials> IAMCredentials(
const grpc::string& authorization_token,
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/atm.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
#include <grpc/support/atm_gcc_atomic.h>
#elif defined(GPR_GCC_SYNC)
#include <grpc/support/atm_gcc_sync.h>
#elif defined(GPR_WIN32)
#elif defined(GPR_WIN32_ATOMIC)
#include <grpc/support/atm_win32.h>
#else
#error could not determine platform for atm
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/atm_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static __inline gpr_atm gpr_atm_acq_load(const gpr_atm *p) {

static __inline gpr_atm gpr_atm_no_barrier_load(const gpr_atm *p) {
/* TODO(dklempner): Can we implement something better here? */
gpr_atm_acq_load(p);
return gpr_atm_acq_load(p);
}

static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
Expand Down
14 changes: 12 additions & 2 deletions include/grpc/support/port_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@
#define GPR_ARCH_64 1
#define GPR_GETPID_IN_PROCESS_H 1
#define GPR_WINSOCK_SOCKET 1
#ifdef __GNUC__
#define GPR_GCC_ATOMIC 1
#else
#define GPR_WIN32_ATOMIC 1
#endif
#elif defined(_WIN32) || defined(WIN32)
#define GPR_ARCH_32 1
#define GPR_WIN32 1
#define GPR_GETPID_IN_PROCESS_H 1
#define GPR_WINSOCK_SOCKET 1
#ifdef __GNUC__
#define GPR_GCC_ATOMIC 1
#else
#define GPR_WIN32_ATOMIC 1
#endif
#elif defined(ANDROID) || defined(__ANDROID__)
#define GPR_ANDROID 1
#define GPR_ARCH_32 1
Expand Down Expand Up @@ -167,8 +177,8 @@
#endif

/* Validate platform combinations */
#if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + defined(GPR_WIN32) != 1
#error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WIN32
#if defined(GPR_GCC_ATOMIC) + defined(GPR_GCC_SYNC) + defined(GPR_WIN32_ATOMIC) != 1
#error Must define exactly one of GPR_GCC_ATOMIC, GPR_GCC_SYNC, GPR_WIN32_ATOMIC
#endif

#if defined(GPR_ARCH_32) + defined(GPR_ARCH_64) != 1
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/python_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ bool PrintStubFactory(const std::string& package_qualified_service_name,
bool PrintPreamble(const FileDescriptor* file, Printer* out) {
out->Print("import abc\n");
out->Print("from grpc.early_adopter import implementations\n");
out->Print("from grpc.early_adopter import utilities\n");
out->Print("from grpc.framework.alpha import utilities\n");
return true;
}

Expand Down
19 changes: 19 additions & 0 deletions src/core/channel/http_server_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ typedef struct channel_data {
grpc_mdelem *status_ok;
grpc_mdelem *status_not_found;
grpc_mdstr *path_key;
grpc_mdstr *authority_key;
grpc_mdstr *host_key;

grpc_mdctx *mdctx;

size_t gettable_count;
gettable *gettables;
Expand Down Expand Up @@ -181,6 +185,15 @@ static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
}
calld->path = op->data.metadata;
op->done_cb(op->user_data, GRPC_OP_OK);
} else if (op->data.metadata->key == channeld->host_key) {
/* translate host to :authority since :authority may be
omitted */
grpc_mdelem *authority = grpc_mdelem_from_metadata_strings(
channeld->mdctx, channeld->authority_key, op->data.metadata->value);
grpc_mdelem_unref(op->data.metadata);
op->data.metadata = authority;
/* pass the event up */
grpc_call_next_op(elem, op);
} else {
/* pass the event up */
grpc_call_next_op(elem, op);
Expand Down Expand Up @@ -305,9 +318,13 @@ static void init_channel_elem(grpc_channel_element *elem,
channeld->https_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "https");
channeld->grpc_scheme = grpc_mdelem_from_strings(mdctx, ":scheme", "grpc");
channeld->path_key = grpc_mdstr_from_string(mdctx, ":path");
channeld->authority_key = grpc_mdstr_from_string(mdctx, ":authority");
channeld->host_key = grpc_mdstr_from_string(mdctx, "host");
channeld->content_type =
grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc");

channeld->mdctx = mdctx;

/* initialize http download support */
channeld->gettable_count = 0;
channeld->gettables = NULL;
Expand Down Expand Up @@ -357,6 +374,8 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
grpc_mdelem_unref(channeld->grpc_scheme);
grpc_mdelem_unref(channeld->content_type);
grpc_mdstr_unref(channeld->path_key);
grpc_mdstr_unref(channeld->authority_key);
grpc_mdstr_unref(channeld->host_key);
}

const grpc_channel_filter grpc_http_server_filter = {
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/client/secure_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ std::unique_ptr<Credentials> JWTCredentials(
grpc_jwt_credentials_create(json_key.c_str(), lifetime));
}

// Builds refresh token credentials.
std::unique_ptr<Credentials> RefreshTokenCredentials(
const grpc::string& json_refresh_token) {
return WrapCredentials(
grpc_refresh_token_credentials_create(json_refresh_token.c_str()));
}

// Builds IAM credentials.
std::unique_ptr<Credentials> IAMCredentials(
const grpc::string& authorization_token,
Expand Down
34 changes: 23 additions & 11 deletions src/node/ext/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ using v8::Value;
NanCallback *Call::constructor;
Persistent<FunctionTemplate> Call::fun_tpl;

bool EndsWith(const char *str, const char *substr) {
return strcmp(str+strlen(str)-strlen(substr), substr) == 0;
}

bool CreateMetadataArray(Handle<Object> metadata, grpc_metadata_array *array,
shared_ptr<Resources> resources) {
Expand All @@ -99,14 +102,19 @@ bool CreateMetadataArray(Handle<Object> metadata, grpc_metadata_array *array,
Handle<Value> value = values->Get(j);
grpc_metadata *current = &array->metadata[array->count];
current->key = **utf8_key;
if (::node::Buffer::HasInstance(value)) {
current->value = ::node::Buffer::Data(value);
current->value_length = ::node::Buffer::Length(value);
Persistent<Value> *handle = new Persistent<Value>();
NanAssignPersistent(*handle, value);
resources->handles.push_back(unique_ptr<PersistentHolder>(
new PersistentHolder(handle)));
} else if (value->IsString()) {
// Only allow binary headers for "-bin" keys
if (EndsWith(current->key, "-bin")) {
if (::node::Buffer::HasInstance(value)) {
current->value = ::node::Buffer::Data(value);
current->value_length = ::node::Buffer::Length(value);
Persistent<Value> *handle = new Persistent<Value>();
NanAssignPersistent(*handle, value);
resources->handles.push_back(unique_ptr<PersistentHolder>(
new PersistentHolder(handle)));
continue;
}
}
if (value->IsString()) {
Handle<String> string_value = value->ToString();
NanUtf8String *utf8_value = new NanUtf8String(string_value);
resources->strings.push_back(unique_ptr<NanUtf8String>(utf8_value));
Expand Down Expand Up @@ -146,9 +154,13 @@ Handle<Value> ParseMetadata(const grpc_metadata_array *metadata_array) {
array = NanNew<Array>(size_map[elem->key]);
metadata_object->Set(key_string, array);
}
array->Set(index_map[elem->key],
MakeFastBuffer(
NanNewBufferHandle(elem->value, elem->value_length)));
if (EndsWith(elem->key, "-bin")) {
array->Set(index_map[elem->key],
MakeFastBuffer(
NanNewBufferHandle(elem->value, elem->value_length)));
} else {
array->Set(index_map[elem->key], NanNew(elem->value));
}
index_map[elem->key] += 1;
}
return NanEscapeScope(metadata_object);
Expand Down
2 changes: 1 addition & 1 deletion src/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grpc",
"version": "0.5.5",
"version": "0.6.0",
"author": "Google Inc.",
"description": "gRPC Library for Node",
"homepage": "http://www.grpc.io/",
Expand Down
4 changes: 2 additions & 2 deletions src/node/test/call_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ describe('call', function() {
assert.doesNotThrow(function() {
var batch = {};
batch[grpc.opType.SEND_INITIAL_METADATA] = {
'key1': [new Buffer('value1')],
'key2': [new Buffer('value2')]
'key1-bin': [new Buffer('value1')],
'key2-bin': [new Buffer('value2')]
};
call.startBatch(batch, function(err, resp) {
assert.ifError(err);
Expand Down
18 changes: 9 additions & 9 deletions src/node/test/end_to_end_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ describe('end-to-end', function() {
client_batch[grpc.opType.RECV_STATUS_ON_CLIENT] = true;
call.startBatch(client_batch, function(err, response) {
assert.ifError(err);
assert(response['send metadata']);
assert(response['client close']);
assert(response.hasOwnProperty('metadata'));
assert.strictEqual(response.metadata.server_key[0].toString(),
'server_value');
assert.deepEqual(response.status, {'code': grpc.status.OK,
'details': status_text,
'metadata': {}});
assert.deepEqual(response,{
'send metadata': true,
'client close': true,
metadata: {server_key: ['server_value']},
status: {'code': grpc.status.OK,
'details': status_text,
'metadata': {}}
});
done();
});

server.requestCall(function(err, call_details) {
var new_call = call_details['new call'];
assert.notEqual(new_call, null);
assert.strictEqual(new_call.metadata.client_key[0].toString(),
assert.strictEqual(new_call.metadata.client_key[0],
'client_value');
var server_call = new_call.call;
assert.notEqual(server_call, null);
Expand Down
2 changes: 1 addition & 1 deletion src/python/interop/interop/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import enum
import threading

from grpc.early_adopter import utilities
from grpc.framework.alpha import utilities

from interop import empty_pb2
from interop import messages_pb2
Expand Down
6 changes: 3 additions & 3 deletions src/python/src/grpc/_adapter/_face_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from grpc._adapter import fore
from grpc._adapter import rear
from grpc.framework.base import util
from grpc.framework.base.packets import implementations as tickets_implementations
from grpc.framework.base import implementations as base_implementations
from grpc.framework.face import implementations as face_implementations
from grpc.framework.face.testing import coverage
from grpc.framework.face.testing import serial
Expand Down Expand Up @@ -69,8 +69,8 @@ def set_up_implementation(
serialization.request_serializers,
serialization.response_deserializers, False, None, None, None)
rear_link.start()
front = tickets_implementations.front(pool, pool, pool)
back = tickets_implementations.back(
front = base_implementations.front_link(pool, pool, pool)
back = base_implementations.back_link(
servicer, pool, pool, pool, _TIMEOUT, _MAXIMUM_TIMEOUT)
fore_link.join_rear_link(back)
back.join_fore_link(fore_link)
Expand Down
Loading

0 comments on commit 1fc0469

Please sign in to comment.