Пример #1
0
// Class/Function Implementation
void
RunServer (AgentServerLog *logger, AgentSystem *sys_handle,
           PathValidator *path_validator)
{
    // This is NA grpc server address as configured by the user
    std::string my_server_address;
    if (global_config.running_mode == RUNNING_MODE_OFF_BOX) {
        my_server_address = global_config.grpc_server_ip + ":" +
                            std::to_string(global_config.grpc_server_port);
    } else {
        my_server_address = "unix:" + global_config.grpc_server_unix_socket;
    }
    AgentServer service(logger, sys_handle, path_validator);
    ServerBuilder builder;

    // Listen on the given address without any authentication mechanism.
    builder.AddListeningPort(my_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 " << my_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();
}
void RunServer(const std::string& db_path) {
	std::string server_address("0.0.0.0:50051");
	RouteGuideImpl service(db_path);

	ServerBuilder builder;
	builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
	builder.RegisterService(&service);
	std::unique_ptr<Server> server(builder.BuildAndStart());
	std::cout << "Server listening on " << server_address << std::endl;
	server->Wait();
}
Пример #3
0
int RunServer(const std::string& address, EnigmaPlugin& plugin, OptionsParser &options, CallBack &ecb) {
  CompilerServiceImpl service(plugin, options, ecb);

  ServerBuilder builder;
  builder.AddListeningPort(address, grpc::InsecureServerCredentials());
  builder.RegisterService(&service);
  std::unique_ptr<Server> server(builder.BuildAndStart());
  std::cout << "Server listening on " << address << std::endl;
  server->Wait();
  return 0;
}
Пример #4
0
ServerRunner::ServerRunner(const string & address, const vector<SynchronousService *> & services)
{
	  ServerBuilder builder;

	  builder.AddListeningPort(address, grpc::InsecureServerCredentials());
	  for (auto s : services){
		  builder.RegisterService(s);
	  }
	  unique_ptr<Server> server(builder.BuildAndStart());
	  cout << address << ": Server listening" << endl;
	  server->Wait();
}
ServerRunner::ServerRunner(const string & address, const vector<SynchronousService *> & services)
{
	  ServerBuilder builder;

	  builder.AddListeningPort(address, grpc::InsecureServerCredentials());
	  for (auto s : services){
		  builder.RegisterService(s);
	  }
	  m_server = builder.BuildAndStart();

	  LOG(INFO) << address << ": Server listening";

	  m_server->Wait();
}
Пример #6
0
 void chordService::startRPCServer(std::string server_address) {
   ServerBuilder builder;
   // Listen on the given address without any authentication mechanism.
   builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
   // Register "rpc_service" as the instance through which we'll communicate with
   // clients. In this case it corresponds to an *synchronous* rpc_service.
   builder.RegisterService(rpc_service);
   // Finally assemble the server.
   std::unique_ptr<Server> server(builder.BuildAndStart());
   std::string info =  "RPC Server listening on " + server_address;
   DEBUG_PRINT(info.c_str());
   rpcserverInitialized = true;
   // 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();
 }
Пример #7
0
void* RunServer(void* MY_IP_PORT) {//同步调用服务端
  std::string server_address((char*)MY_IP_PORT);
  dumpServiceImpl service;
    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();
}
Пример #8
0
void Run() {//构建一个服务器导出异步服务
    ServerImpl* server=new ServerImpl();
    std::string server_address("0.0.0.0:6000");
    ServerBuilder builder;
    builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
    builder.RegisterAsyncService(&(server->service_));
    server->cq_ = builder.AddCompletionQueue();
    server->server_ = builder.BuildAndStart();
    std::cout << "Server listening on " << server_address << std::endl;
    pthread_t thdId[3];
	pthread_create(&thdId[0], NULL, HandleRpcs,(void *)server);
	//pthread_create(&thdId[1], NULL, HandleRpcs,(void *)server);
	//pthread_create(&thdId[2], NULL, HandleRpcs,(void *)server);
	int iRet = 0;
	pthread_join(thdId[0],(void **)&iRet);  //接收子线程的返回值*/
	//pthread_join(thdId[1],(void **)&iRet);  //接收子线程的返回值*/
	//pthread_join(thdId[2],(void **)&iRet);  //接收子线程的返回值*/
}
Пример #9
0
void HybridSimulationManager::Start()
{
     GOOGLE_PROTOBUF_VERIFY_VERSION;
     grpc_init();

     ///0.0.0.0 means to listen on all devices
     string jupedsim_service_address("0.0.0.0:"+std::to_string(_config->GetServicePort()));

     JPSserver service(this, _latches, _config);
     _service = &service;
     ServerBuilder builder;
     builder.AddListeningPort(jupedsim_service_address, grpc::InsecureServerCredentials());
     builder.RegisterService(&service);
     _server = builder.BuildAndStart();

     Log->Write("INFO:\tJPS server at port: "+std::to_string(_config->GetServicePort())+" is up and running.");

     _server->Wait();
}
Пример #10
0
void server()
{
	std::string server_address("0.0.0.0:50051");
	TestServiceImpl service;

	grpc::SslServerCredentialsOptions sslopt;
	grpc::SslServerCredentialsOptions::PemKeyCertPair pair;

	sslopt.pem_root_certs = loadFile("ca.cert.pem");
	pair.private_key = loadFile("server.key.pem");
	pair.cert_chain = loadFile("server.cert.pem");
	sslopt.pem_key_cert_pairs.emplace_back(std::move(pair));

	ServerBuilder builder;
	builder.AddListeningPort(server_address, grpc::SslServerCredentials(sslopt));
	builder.RegisterService(&service);
	std::unique_ptr<Server> server(builder.BuildAndStart());
	std::cout << "Server listening on " << server_address << std::endl;
	server->Wait();
}
Пример #11
0
Try<Connection> MockCSIPlugin::startup(const Option<string>& address)
{
  ServerBuilder builder;

  if (address.isSome()) {
    builder.AddListeningPort(address.get(), InsecureServerCredentials());
  }

  builder.RegisterService(static_cast<Identity::Service*>(this));
  builder.RegisterService(static_cast<Controller::Service*>(this));
  builder.RegisterService(static_cast<Node::Service*>(this));

  server = builder.BuildAndStart();
  if (!server) {
    return Error("Unable to start a mock CSI plugin.");
  }

  return address.isSome()
    ? Connection(address.get())
    : Connection(server->InProcessChannel(ChannelArguments()));
}