|
|
@ -33,6 +33,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <forward_list> |
|
|
|
#include <forward_list> |
|
|
|
#include <functional> |
|
|
|
#include <functional> |
|
|
|
|
|
|
|
#include <memory> |
|
|
|
#include <mutex> |
|
|
|
#include <mutex> |
|
|
|
#include <sys/time.h> |
|
|
|
#include <sys/time.h> |
|
|
|
#include <sys/resource.h> |
|
|
|
#include <sys/resource.h> |
|
|
@ -158,11 +159,12 @@ class AsyncQpsServerTest : public Server { |
|
|
|
void *)> request_method, |
|
|
|
void *)> request_method, |
|
|
|
std::function<grpc::Status(const RequestType *, ResponseType *)> |
|
|
|
std::function<grpc::Status(const RequestType *, ResponseType *)> |
|
|
|
invoke_method) |
|
|
|
invoke_method) |
|
|
|
: next_state_(&ServerRpcContextUnaryImpl::invoker), |
|
|
|
: srv_ctx_(new ServerContext), |
|
|
|
|
|
|
|
next_state_(&ServerRpcContextUnaryImpl::invoker), |
|
|
|
request_method_(request_method), |
|
|
|
request_method_(request_method), |
|
|
|
invoke_method_(invoke_method), |
|
|
|
invoke_method_(invoke_method), |
|
|
|
response_writer_(&srv_ctx_) { |
|
|
|
response_writer_(srv_ctx_.get()) { |
|
|
|
request_method_(&srv_ctx_, &req_, &response_writer_, |
|
|
|
request_method_(srv_ctx_.get(), &req_, &response_writer_, |
|
|
|
AsyncQpsServerTest::tag(this)); |
|
|
|
AsyncQpsServerTest::tag(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
~ServerRpcContextUnaryImpl() GRPC_OVERRIDE {} |
|
|
|
~ServerRpcContextUnaryImpl() GRPC_OVERRIDE {} |
|
|
@ -170,14 +172,14 @@ class AsyncQpsServerTest : public Server { |
|
|
|
return (this->*next_state_)(ok); |
|
|
|
return (this->*next_state_)(ok); |
|
|
|
} |
|
|
|
} |
|
|
|
void Reset() GRPC_OVERRIDE { |
|
|
|
void Reset() GRPC_OVERRIDE { |
|
|
|
srv_ctx_ = ServerContext(); |
|
|
|
srv_ctx_.reset(new ServerContext); |
|
|
|
req_ = RequestType(); |
|
|
|
req_ = RequestType(); |
|
|
|
response_writer_ = |
|
|
|
response_writer_ = |
|
|
|
grpc::ServerAsyncResponseWriter<ResponseType>(&srv_ctx_); |
|
|
|
grpc::ServerAsyncResponseWriter<ResponseType>(srv_ctx_.get()); |
|
|
|
|
|
|
|
|
|
|
|
// Then request the method
|
|
|
|
// Then request the method
|
|
|
|
next_state_ = &ServerRpcContextUnaryImpl::invoker; |
|
|
|
next_state_ = &ServerRpcContextUnaryImpl::invoker; |
|
|
|
request_method_(&srv_ctx_, &req_, &response_writer_, |
|
|
|
request_method_(srv_ctx_.get(), &req_, &response_writer_, |
|
|
|
AsyncQpsServerTest::tag(this)); |
|
|
|
AsyncQpsServerTest::tag(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -198,7 +200,7 @@ class AsyncQpsServerTest : public Server { |
|
|
|
response_writer_.Finish(response, status, AsyncQpsServerTest::tag(this)); |
|
|
|
response_writer_.Finish(response, status, AsyncQpsServerTest::tag(this)); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
ServerContext srv_ctx_; |
|
|
|
std::unique_ptr<ServerContext> srv_ctx_; |
|
|
|
RequestType req_; |
|
|
|
RequestType req_; |
|
|
|
bool (ServerRpcContextUnaryImpl::*next_state_)(bool); |
|
|
|
bool (ServerRpcContextUnaryImpl::*next_state_)(bool); |
|
|
|
std::function<void(ServerContext *, RequestType *, |
|
|
|
std::function<void(ServerContext *, RequestType *, |
|
|
@ -218,25 +220,26 @@ class AsyncQpsServerTest : public Server { |
|
|
|
void *)> request_method, |
|
|
|
void *)> request_method, |
|
|
|
std::function<grpc::Status(const RequestType *, ResponseType *)> |
|
|
|
std::function<grpc::Status(const RequestType *, ResponseType *)> |
|
|
|
invoke_method) |
|
|
|
invoke_method) |
|
|
|
: next_state_(&ServerRpcContextStreamingImpl::request_done), |
|
|
|
: srv_ctx_(new ServerContext), |
|
|
|
|
|
|
|
next_state_(&ServerRpcContextStreamingImpl::request_done), |
|
|
|
request_method_(request_method), |
|
|
|
request_method_(request_method), |
|
|
|
invoke_method_(invoke_method), |
|
|
|
invoke_method_(invoke_method), |
|
|
|
stream_(&srv_ctx_) { |
|
|
|
stream_(srv_ctx_.get()) { |
|
|
|
request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this)); |
|
|
|
request_method_(srv_ctx_.get(), &stream_, AsyncQpsServerTest::tag(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
~ServerRpcContextStreamingImpl() GRPC_OVERRIDE {} |
|
|
|
~ServerRpcContextStreamingImpl() GRPC_OVERRIDE {} |
|
|
|
bool RunNextState(bool ok) GRPC_OVERRIDE { |
|
|
|
bool RunNextState(bool ok) GRPC_OVERRIDE { |
|
|
|
return (this->*next_state_)(ok); |
|
|
|
return (this->*next_state_)(ok); |
|
|
|
} |
|
|
|
} |
|
|
|
void Reset() GRPC_OVERRIDE { |
|
|
|
void Reset() GRPC_OVERRIDE { |
|
|
|
srv_ctx_ = ServerContext(); |
|
|
|
srv_ctx_.reset(new ServerContext); |
|
|
|
req_ = RequestType(); |
|
|
|
req_ = RequestType(); |
|
|
|
stream_ = |
|
|
|
stream_ = grpc::ServerAsyncReaderWriter<ResponseType, RequestType>( |
|
|
|
grpc::ServerAsyncReaderWriter<ResponseType, RequestType>(&srv_ctx_); |
|
|
|
srv_ctx_.get()); |
|
|
|
|
|
|
|
|
|
|
|
// Then request the method
|
|
|
|
// Then request the method
|
|
|
|
next_state_ = &ServerRpcContextStreamingImpl::request_done; |
|
|
|
next_state_ = &ServerRpcContextStreamingImpl::request_done; |
|
|
|
request_method_(&srv_ctx_, &stream_, AsyncQpsServerTest::tag(this)); |
|
|
|
request_method_(srv_ctx_.get(), &stream_, AsyncQpsServerTest::tag(this)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
@ -278,7 +281,7 @@ class AsyncQpsServerTest : public Server { |
|
|
|
} |
|
|
|
} |
|
|
|
bool finish_done(bool ok) { return false; /* reset the context */ } |
|
|
|
bool finish_done(bool ok) { return false; /* reset the context */ } |
|
|
|
|
|
|
|
|
|
|
|
ServerContext srv_ctx_; |
|
|
|
std::unique_ptr<ServerContext> srv_ctx_; |
|
|
|
RequestType req_; |
|
|
|
RequestType req_; |
|
|
|
bool (ServerRpcContextStreamingImpl::*next_state_)(bool); |
|
|
|
bool (ServerRpcContextStreamingImpl::*next_state_)(bool); |
|
|
|
std::function<void( |
|
|
|
std::function<void( |
|
|
|