blob: b6b30a520467b81f2e6a488b999496559cd77fcd [file] [log] [blame]
Craig Tillerfbac5f12015-05-15 14:20:44 -07001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include <iostream>
35#include <memory>
36#include <string>
37#include <gflags/gflags.h>
38
39#include <grpc++/server.h>
40#include <grpc++/server_builder.h>
41#include <grpc++/server_context.h>
42#include <grpc++/server_credentials.h>
43#include <grpc++/status.h>
44#include "test/cpp/util/echo.grpc.pb.h"
45
46DEFINE_string(address, "", "Address to bind to");
47
48using grpc::cpp::test::util::EchoRequest;
49using grpc::cpp::test::util::EchoResponse;
50
51// In some distros, gflags is in the namespace google, and in some others,
52// in gflags. This hack is enabling us to find both.
53namespace google {}
54namespace gflags {}
55using namespace google;
56using namespace gflags;
57
58namespace grpc {
59namespace testing {
60
61class ServiceImpl final : public grpc::cpp::test::util::TestService::Service {
62 Status BidiStream(ServerContext* context,
63 ServerReaderWriter<EchoResponse, EchoRequest>* stream)
64 GRPC_OVERRIDE {
65 EchoRequest request;
66 EchoResponse response;
67 while (stream->Read(&request)) {
68 gpr_log(GPR_INFO, "recv msg %s", request.message().c_str());
69 response.set_message(request.message());
70 stream->Write(response);
71 }
72 return Status::OK;
73 }
74};
75
76void RunServer() {
77 ServiceImpl service;
78
79 ServerBuilder builder;
80 builder.AddListeningPort(FLAGS_address, grpc::InsecureServerCredentials());
81 builder.RegisterService(&service);
82 std::unique_ptr<Server> server(builder.BuildAndStart());
83 std::cout << "Server listening on " << FLAGS_address << std::endl;
84 server->Wait();
85}
86
87}
88}
89
90int main(int argc, char** argv) {
91 ParseCommandLineFlags(&argc, &argv, true);
92 grpc::testing::RunServer();
93
94 return 0;
95}