Skip to content

Commit

Permalink
expose the server's cq through the generic service object
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-g committed Mar 16, 2015
1 parent 5333c5a commit 1ad253d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion include/grpc++/async_generic_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ class AsyncGenericService GRPC_FINAL {
public:
// TODO(yangg) Once we can add multiple completion queues to the server
// in c core, add a CompletionQueue* argument to the ctor here.
AsyncGenericService() : server_(nullptr) {}
// TODO(yangg) support methods list.
AsyncGenericService(const grpc::string& methods) : server_(nullptr) {}

void RequestCall(GenericServerContext* ctx,
GenericServerAsyncReaderWriter* reader_writer,
CompletionQueue* cq, void* tag);

// The new rpc event should be obtained from this completion queue.
CompletionQueue* completion_queue();

private:
friend class Server;
Server* server_;
Expand Down
2 changes: 0 additions & 2 deletions include/grpc++/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ class Server GRPC_FINAL : private CallHook,
// function to ever return)
void Wait();

CompletionQueue* cq() { return &cq_; }

private:
friend class AsyncGenericService;
friend class ServerBuilder;
Expand Down
4 changes: 4 additions & 0 deletions src/cpp/server/async_generic_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@ void AsyncGenericService::RequestCall(
server_->RequestAsyncGenericCall(ctx, reader_writer, cq, tag);
}

CompletionQueue* AsyncGenericService::completion_queue() {
return &server_->cq_;
}

} // namespace grpc

4 changes: 2 additions & 2 deletions src/cpp/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bool Server::RegisterService(RpcService* service) {

bool Server::RegisterAsyncService(AsynchronousService* service) {
GPR_ASSERT(service->dispatch_impl_ == nullptr &&
"Can only register one asynchronous service against one server.");
"Can only register an asynchronous service against one server.");
service->dispatch_impl_ = this;
service->request_args_ = new void* [service->method_count_];
for (size_t i = 0; i < service->method_count_; ++i) {
Expand All @@ -230,7 +230,7 @@ bool Server::RegisterAsyncService(AsynchronousService* service) {

void Server::RegisterAsyncGenericService(AsyncGenericService* service) {
GPR_ASSERT(service->server_ == nullptr &&
"Can only register one generic service against one server.");
"Can only register an async generic service against one server.");
service->server_ = this;
}

Expand Down
6 changes: 3 additions & 3 deletions test/cpp/end2end/generic_end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message) {

class GenericEnd2endTest : public ::testing::Test {
protected:
GenericEnd2endTest() {}
GenericEnd2endTest() : generic_service_("*") {}

void SetUp() GRPC_OVERRIDE {
int port = grpc_pick_unused_port_or_die();
Expand Down Expand Up @@ -145,7 +145,7 @@ class GenericEnd2endTest : public ::testing::Test {

generic_service_.RequestCall(&srv_ctx, &stream, &srv_cq_, tag(2));

verify_ok(server_->cq(), 2, true);
verify_ok(generic_service_.completion_queue(), 2, true);
EXPECT_EQ(server_address_.str(), srv_ctx.host());
EXPECT_EQ("/grpc.cpp.test.util.TestService/Echo", srv_ctx.method());
ByteBuffer recv_buffer;
Expand Down Expand Up @@ -212,7 +212,7 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) {

generic_service_.RequestCall(&srv_ctx, &srv_stream, &srv_cq_, tag(2));

verify_ok(server_->cq(), 2, true);
verify_ok(generic_service_.completion_queue(), 2, true);
EXPECT_EQ(server_address_.str(), srv_ctx.host());
EXPECT_EQ("/grpc.cpp.test.util.TestService/BidiStream", srv_ctx.method());

Expand Down

0 comments on commit 1ad253d

Please sign in to comment.