1 /** 2 * Copyright 2021 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_PS_CORE_COMMUNICATOR_TCP_MSG_HANDLER_H_ 18 #define MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_TCP_MSG_HANDLER_H_ 19 20 #include <memory> 21 #include "proto/ps.pb.h" 22 #include "ps/core/abstract_node.h" 23 #include "ps/core/communicator/message_handler.h" 24 #include "ps/constants.h" 25 26 namespace mindspore { 27 namespace ps { 28 namespace core { 29 class TcpMsgHandler : public MessageHandler { 30 public: 31 TcpMsgHandler(AbstractNode *const abstract_node, const std::shared_ptr<core::TcpConnection> &conn, 32 const std::shared_ptr<MessageMeta> &meta, const DataPtr &data, size_t size); 33 ~TcpMsgHandler() override = default; 34 35 void *data() const override; 36 size_t len() const override; 37 bool SendResponse(const void *data, const size_t &len) override; 38 39 private: 40 AbstractNode *abstract_node_; 41 std::shared_ptr<TcpConnection> tcp_conn_; 42 // core::MessageMeta is used for server to get the user command and to find communication peer when responding. 43 std::shared_ptr<MessageMeta> meta_; 44 // We use data of shared_ptr array so that the raw pointer won't be released until the reference is 0. 45 DataPtr data_ptr_; 46 void *data_; 47 size_t len_; 48 }; 49 } // namespace core 50 } // namespace ps 51 } // namespace mindspore 52 #endif // MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_TCP_MSG_HANDLER_H_ 53