• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ps/core/communicator/tcp_msg_handler.h"
18 #include <memory>
19 #include <utility>
20 
21 namespace mindspore {
22 namespace ps {
23 namespace core {
TcpMsgHandler(AbstractNode * abstract_node,const std::shared_ptr<core::TcpConnection> & conn,const std::shared_ptr<MessageMeta> & meta,DataPtr data,size_t size)24 TcpMsgHandler::TcpMsgHandler(AbstractNode *abstract_node, const std::shared_ptr<core::TcpConnection> &conn,
25                              const std::shared_ptr<MessageMeta> &meta, DataPtr data, size_t size)
26     : abstract_node_(abstract_node), tcp_conn_(conn), meta_(meta), data_(nullptr), len_(size) {
27   data_ptr_ = std::move(data);
28   if (data_ptr_ != nullptr) {
29     data_ = data_ptr_.get();
30   }
31 }
32 
data() const33 void *TcpMsgHandler::data() const {
34   MS_ERROR_IF_NULL_W_RET_VAL(data_, nullptr);
35   return data_;
36 }
37 
len() const38 size_t TcpMsgHandler::len() const { return len_; }
39 
SendResponse(const void * data,const size_t & len)40 bool TcpMsgHandler::SendResponse(const void *data, const size_t &len) {
41   MS_ERROR_IF_NULL_W_RET_VAL(tcp_conn_, false);
42   MS_ERROR_IF_NULL_W_RET_VAL(meta_, false);
43   MS_ERROR_IF_NULL_W_RET_VAL(data, false);
44   MS_ERROR_IF_NULL_W_RET_VAL(abstract_node_, false);
45   abstract_node_->Response(tcp_conn_, meta_, const_cast<void *>(data), len);
46   return true;
47 }
48 }  // namespace core
49 }  // namespace ps
50 }  // namespace mindspore
51