Skip to content

Commit

Permalink
Set the port to connect to the sdkserver based on the AGONES_SDK_GRPC…
Browse files Browse the repository at this point in the history
…_PORT

environment variable.
  • Loading branch information
roberthbailey committed Oct 16, 2019
1 parent c05bc4e commit 41412ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/cpp-simple/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main() {

std::cout << "Attempting to connect...\n" << std::flush;
if (!sdk->Connect()) {
std::cerr << "Could not connect to the sidecar. Exiting!\n";
std::cerr << "Exiting!\n";
return -1;
}
std::cout << "...handshake complete.\n" << std::flush;
Expand Down
9 changes: 7 additions & 2 deletions sdks/cpp/src/agones/sdk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
namespace agones {

struct SDK::SDKImpl {
std::string host_;
std::shared_ptr<grpc::Channel> channel_;
std::unique_ptr<agones::dev::sdk::SDK::Stub> stub_;
std::unique_ptr<grpc::ClientWriter<agones::dev::sdk::Empty>> health_;
std::unique_ptr<grpc::ClientContext> health_context_;
};

SDK::SDK() : pimpl_{std::make_unique<SDKImpl>()} {
pimpl_->channel_ = grpc::CreateChannel("localhost:59357",
grpc::InsecureChannelCredentials());
const char* port = std::getenv("AGONES_SDK_GRPC_PORT");
pimpl_->host_ = std::string("localhost:") + (port ? port : "59357");
pimpl_->channel_ =
grpc::CreateChannel(pimpl_->host_, grpc::InsecureChannelCredentials());
}

SDK::~SDK() {}
Expand All @@ -37,6 +40,8 @@ bool SDK::Connect() {
if (!pimpl_->channel_->WaitForConnected(
gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
gpr_time_from_seconds(30, GPR_TIMESPAN)))) {
std::cerr << "Could not connect to the sidecar at " << pimpl_->host_
<< ".\n";
return false;
}

Expand Down

0 comments on commit 41412ed

Please sign in to comment.