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 26 int main() { 27 RPCConfig Config; 28 parseEnvironment(Config); 29 30 RemoteOffloadImpl Service(Config.MaxSize, Config.BlockSize); 31 32 ServerBuilder Builder; 33 Builder.AddListeningPort(Config.ServerAddresses[0], 34 grpc::InsecureServerCredentials()); 35 Builder.RegisterService(&Service); 36 Builder.SetMaxMessageSize(INT_MAX); 37 std::unique_ptr<Server> Server(Builder.BuildAndStart()); 38 if (getDebugLevel()) 39 std::cerr << "Server listening on " << Config.ServerAddresses[0] 40 << std::endl; 41 42 auto WaitForServer = [&]() { Server->Wait(); }; 43 44 std::thread ServerThread(WaitForServer); 45 46 auto ShutdownFuture = ShutdownPromise.get_future(); 47 ShutdownFuture.wait(); 48 Server->Shutdown(); 49 ServerThread.join(); 50 51 return 0; 52 } 53