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