1 //===------------- OffloadingServer.cpp - Server Application --------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // Offloading server for remote host. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include <future> 14 #include <grpcpp/server.h> 15 #include <grpcpp/server_builder.h> 16 #include <iostream> 17 #include <thread> 18 19 #include "Server.h" 20 21 using grpc::Server; 22 using grpc::ServerBuilder; 23 24 std::promise<void> ShutdownPromise; 25 main()26int main() { 27 ClientManagerConfigTy Config; 28 29 RemoteOffloadImpl Service(Config.MaxSize, Config.BlockSize); 30 31 ServerBuilder Builder; 32 Builder.AddListeningPort(Config.ServerAddresses[0], 33 grpc::InsecureServerCredentials()); 34 Builder.RegisterService(&Service); 35 Builder.SetMaxMessageSize(INT_MAX); 36 std::unique_ptr<Server> Server(Builder.BuildAndStart()); 37 if (getDebugLevel()) 38 std::cerr << "Server listening on " << Config.ServerAddresses[0] 39 << std::endl; 40 41 auto WaitForServer = [&]() { Server->Wait(); }; 42 43 std::thread ServerThread(WaitForServer); 44 45 auto ShutdownFuture = ShutdownPromise.get_future(); 46 ShutdownFuture.wait(); 47 Server->Shutdown(); 48 ServerThread.join(); 49 50 return 0; 51 } 52