• 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 
20 namespace mindspore {
21 namespace ps {
22 namespace core {
TcpMsgHandler(AbstractNode * const abstract_node,const std::shared_ptr<core::TcpConnection> & conn,const std::shared_ptr<MessageMeta> & meta,const DataPtr & data,size_t size)23 TcpMsgHandler::TcpMsgHandler(AbstractNode *const abstract_node, const std::shared_ptr<core::TcpConnection> &conn,
24                              const std::shared_ptr<MessageMeta> &meta, const DataPtr &data, size_t size)
25     : abstract_node_(abstract_node), tcp_conn_(conn), meta_(meta), data_ptr_(data), data_(nullptr), len_(size) {
26   if (data_ptr_ != nullptr) {
27     data_ = data_ptr_.get();
28   }
29 }
30 
data() const31 void *TcpMsgHandler::data() const {
32   MS_ERROR_IF_NULL_W_RET_VAL(data_, nullptr);
33   return data_;
34 }
35 
len() const36 size_t TcpMsgHandler::len() const { return len_; }
37 
SendResponse(const void * data,const size_t & len)38 bool TcpMsgHandler::SendResponse(const void *data, const size_t &len) {
39   MS_ERROR_IF_NULL_W_RET_VAL(tcp_conn_, false);
40   MS_ERROR_IF_NULL_W_RET_VAL(meta_, false);
41   MS_ERROR_IF_NULL_W_RET_VAL(data, false);
42   MS_ERROR_IF_NULL_W_RET_VAL(abstract_node_, false);
43   abstract_node_->Response(tcp_conn_, meta_, const_cast<void *>(data), len);
44   return true;
45 }
46 }  // namespace core
47 }  // namespace ps
48 }  // namespace mindspore
49