diff options
author | Craig Tiller <ctiller@google.com> | 2022-11-10 16:24:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 16:24:30 -0800 |
commit | 867dc6cae219e21f931ff66c9281580ef0ec0e59 (patch) | |
tree | 4c1a44cebc47d94290d926ba9c6964dc7f17add6 /examples | |
parent | 51f296b4f84fc2adeffa6341223d647ae5552873 (diff) | |
download | grpc-grpc-867dc6cae219e21f931ff66c9281580ef0ec0e59.tar.gz |
Revert "Add support for systemd socket activation (#30485)" (#31617)
This reverts commit a638c407bb9da4626e686794892ac613f25f4486.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/cpp/features/sd_sock_act/BUILD | 34 | ||||
-rw-r--r-- | examples/cpp/features/sd_sock_act/client.cc | 100 | ||||
-rw-r--r-- | examples/cpp/features/sd_sock_act/server.cc | 68 | ||||
-rwxr-xr-x | examples/cpp/features/sd_sock_act/test.sh | 73 |
4 files changed, 0 insertions, 275 deletions
diff --git a/examples/cpp/features/sd_sock_act/BUILD b/examples/cpp/features/sd_sock_act/BUILD deleted file mode 100644 index b1c5cbcdbf..0000000000 --- a/examples/cpp/features/sd_sock_act/BUILD +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2022 the gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -licenses(["notice"]) - -cc_binary( - name = "client", - srcs = ["client.cc"], - deps = [ - "//:grpc++", - "//examples/protos:helloworld_cc_grpc", - ], -) - -cc_binary( - name = "server", - srcs = ["server.cc"], - deps = [ - "//:grpc++", - "//:grpc++_reflection", - "//examples/protos:helloworld_cc_grpc", - ], -) diff --git a/examples/cpp/features/sd_sock_act/client.cc b/examples/cpp/features/sd_sock_act/client.cc deleted file mode 100644 index 53071e54a7..0000000000 --- a/examples/cpp/features/sd_sock_act/client.cc +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2022 the gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include <iostream> -#include <memory> -#include <string> - -#include "examples/protos/helloworld.grpc.pb.h" - -#include <grpcpp/grpcpp.h> - -using grpc::Channel; -using grpc::ClientContext; -using grpc::Status; -using helloworld::Greeter; -using helloworld::HelloReply; -using helloworld::HelloRequest; - -class GreeterClient { - public: - GreeterClient(std::shared_ptr<Channel> channel) - : stub_(Greeter::NewStub(channel)) {} - - // Assembles the client's payload, sends it and presents the response back - // from the server. - std::string SayHello(const std::string& user) { - // Data we are sending to the server. - HelloRequest request; - request.set_name(user); - - // Container for the data we expect from the server. - HelloReply reply; - - // Context for the client. It could be used to convey extra information to - // the server and/or tweak certain RPC behaviors. - ClientContext context; - - // The actual RPC. - Status status = stub_->SayHello(&context, request, &reply); - - // Act upon its status. - if (status.ok()) { - return reply.message(); - } else { - std::cout << status.error_code() << ": " << status.error_message() - << std::endl; - return "RPC failed"; - } - } - - private: - std::unique_ptr<Greeter::Stub> stub_; -}; - -int main(int argc, char** argv) { - // Instantiate the client. It requires a channel, out of which the actual RPCs - // are created. This channel models a connection to an endpoint specified by - // the argument "--target=" which is the only expected argument. - // We indicate that the channel isn't authenticated (use of - // InsecureChannelCredentials()). - std::string target_str; - std::string arg_str("--target"); - if (argc > 1) { - std::string arg_val = argv[1]; - size_t start_pos = arg_val.find(arg_str); - if (start_pos != std::string::npos) { - start_pos += arg_str.size(); - if (arg_val[start_pos] == '=') { - target_str = arg_val.substr(start_pos + 1); - } else { - std::cout << "The only correct argument syntax is --target=" - << std::endl; - return 0; - } - } else { - std::cout << "The only acceptable argument is --target=" << std::endl; - return 0; - } - } else { - target_str = "unix:/tmp/server"; - } - GreeterClient greeter( - grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); - std::string user("world"); - std::string reply = greeter.SayHello(user); - std::cout << "Greeter received: " << reply << std::endl; - - return 0; -} diff --git a/examples/cpp/features/sd_sock_act/server.cc b/examples/cpp/features/sd_sock_act/server.cc deleted file mode 100644 index 28ec68114a..0000000000 --- a/examples/cpp/features/sd_sock_act/server.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2022 the gRPC authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include <iostream> -#include <memory> -#include <string> - -#include "examples/protos/helloworld.grpc.pb.h" - -#include <grpcpp/ext/proto_server_reflection_plugin.h> -#include <grpcpp/grpcpp.h> -#include <grpcpp/health_check_service_interface.h> - -using grpc::Server; -using grpc::ServerBuilder; -using grpc::ServerContext; -using grpc::Status; -using helloworld::Greeter; -using helloworld::HelloReply; -using helloworld::HelloRequest; - -// Logic and data behind the server's behavior. -class GreeterServiceImpl final : public Greeter::Service { - Status SayHello(ServerContext* context, const HelloRequest* request, - HelloReply* reply) override { - std::string prefix("Hello "); - reply->set_message(prefix + request->name()); - return Status::OK; - } -}; - -void RunServer() { - std::string server_address("unix:/tmp/server"); - GreeterServiceImpl service; - - grpc::EnableDefaultHealthCheckService(true); - grpc::reflection::InitProtoReflectionServerBuilderPlugin(); - ServerBuilder builder; - // Listen on the given address without any authentication mechanism. - builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); - // Register "service" as the instance through which we'll communicate with - // clients. In this case it corresponds to an *synchronous* service. - builder.RegisterService(&service); - // Finally assemble the server. - std::unique_ptr<Server> server(builder.BuildAndStart()); - std::cout << "Server listening on " << server_address << std::endl; - - // Wait for the server to shutdown. Note that some other thread must be - // responsible for shutting down the server for this call to ever return. - server->Wait(); -} - -int main(int argc, char** argv) { - RunServer(); - - return 0; -} diff --git a/examples/cpp/features/sd_sock_act/test.sh b/examples/cpp/features/sd_sock_act/test.sh deleted file mode 100755 index 02c51cd254..0000000000 --- a/examples/cpp/features/sd_sock_act/test.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2022 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Test structure borrowed with gratitude from -# https://github.com/grpc/grpc-go/tree/master/examples/features - -# Run this script as root - -clean() { - echo "Cleaning..." - systemctl stop sdsockact.socket - systemctl stop sdsockact.service - systemctl daemon-reload - rm /tmp/greeter_server - rm /tmp/greeter_client - rm /etc/systemd/system/sdsockact.service - rm /etc/systemd/system/sdsockact.socket -} - -fail() { - clean - echo "FAIL: $@" >&2 - exit 1 -} - -pass() { - echo "SUCCESS: $1" -} - -bazel build --define=use_systemd=true //examples/cpp/features/sd_sock_act:all || fail "Failed to build sd_sock_act" -cp ../../../../bazel-bin/examples/cpp/features/sd_sock_act/server /tmp/greeter_server -cp ../../../../bazel-bin/examples/cpp/features/sd_sock_act/client /tmp/greeter_client - -cat << EOF > /etc/systemd/system/sdsockact.service -[Service] -ExecStart=/tmp/greeter_server -EOF - -cat << EOF > /etc/systemd/system/sdsockact.socket -[Socket] -ListenStream=/tmp/server -ReusePort=true - -[Install] -WantedBy=sockets.target -EOF - -systemctl daemon-reload -systemctl enable sdsockact.socket -systemctl start sdsockact.socket - -pushd /tmp -./greeter_client | grep "Hello" -if [ $? -ne 0 ]; then - popd - fail "Response not received" -fi - -popd -pass "Response received" -clean |