Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the port to connect to the sdkserver based on the AGONES_SDK_GRPC_PORT environment variable #1092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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