1 /** 2 * Copyright 2023 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_DISTRIBUTED_RPC_RPC_SERVER_BASE_H_ 18 #define MINDSPORE_CCSRC_DISTRIBUTED_RPC_RPC_SERVER_BASE_H_ 19 20 #include <string> 21 #include <memory> 22 23 #include "include/backend/distributed/constants.h" 24 25 namespace mindspore { 26 namespace distributed { 27 namespace rpc { 28 class RPCServerBase { 29 public: RPCServerBase(bool enable_ssl,const ServerPortRange & port_range)30 explicit RPCServerBase(bool enable_ssl, const ServerPortRange &port_range) 31 : ip_(""), port_(0), enable_ssl_(enable_ssl), port_range_(port_range) {} 32 virtual ~RPCServerBase() = default; 33 34 // Init server using the specified url, with memory allocating function. 35 virtual bool Initialize(const std::string &url, const MemAllocateCallback &allocate_cb = {}) { return true; } 36 37 // Init server using local IP and random port. 38 virtual bool Initialize(const MemAllocateCallback &allocate_cb = {}) { return true; } 39 40 // Destroy the tcp server. Finalize()41 virtual void Finalize() {} 42 43 // Set the message processing handler. 44 virtual void SetMessageHandler(const MessageHandler &handler, uint32_t func_id = 0) {} 45 46 // Return the IP and port bound to this server. GetIP()47 virtual std::string GetIP() const { return ip_; } GetPort()48 virtual uint32_t GetPort() const { return port_; } 49 50 protected: 51 std::string ip_; 52 uint32_t port_; 53 54 bool enable_ssl_; 55 ServerPortRange port_range_; 56 }; 57 } // namespace rpc 58 } // namespace distributed 59 } // namespace mindspore 60 61 #endif // MINDSPORE_CCSRC_DISTRIBUTED_RPC_RPC_SERVER_BASE_H_ 62