Skip to content

Commit

Permalink
Merge pull request grpc#6858 from makdharma/issue5851
Browse files Browse the repository at this point in the history
implement interval_us functionality
  • Loading branch information
jtattermusch authored Jun 17, 2016
2 parents bd8d64a + 509246f commit ef03e53
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/cpp/interop/server_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ class TestServiceImpl : public TestService::Service {
response.mutable_payload())) {
return Status(grpc::StatusCode::INTERNAL, "Error creating payload.");
}
int time_us;
if ((time_us = request->response_parameters(i).interval_us()) > 0) {
// Sleep before response if needed
gpr_timespec sleep_time =
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_micros(time_us, GPR_TIMESPAN));
gpr_sleep_until(sleep_time);
}
write_success = writer->Write(response);
}
if (write_success) {
Expand Down Expand Up @@ -218,6 +226,14 @@ class TestServiceImpl : public TestService::Service {
response.mutable_payload()->set_type(request.payload().type());
response.mutable_payload()->set_body(
grpc::string(request.response_parameters(0).size(), '\0'));
int time_us;
if ((time_us = request.response_parameters(0).interval_us()) > 0) {
// Sleep before response if needed
gpr_timespec sleep_time =
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_micros(time_us, GPR_TIMESPAN));
gpr_sleep_until(sleep_time);
}
write_success = stream->Write(response);
}
}
Expand Down

0 comments on commit ef03e53

Please sign in to comment.