• 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/http_msg_handler.h"
18 #include <memory>
19 
20 namespace mindspore {
21 namespace ps {
22 namespace core {
HttpMsgHandler(const std::shared_ptr<HttpMessageHandler> & http_msg)23 HttpMsgHandler::HttpMsgHandler(const std::shared_ptr<HttpMessageHandler> &http_msg)
24     : http_msg_(http_msg), data_(nullptr), len_(0) {
25   if (http_msg != nullptr) {
26     len_ = http_msg_->GetPostMsg(&data_);
27   }
28 }
29 
data() const30 void *HttpMsgHandler::data() const {
31   MS_ERROR_IF_NULL_W_RET_VAL(data_, nullptr);
32   return data_;
33 }
34 
len() const35 size_t HttpMsgHandler::len() const { return len_; }
36 
SendResponse(const void * data,const size_t & len)37 bool HttpMsgHandler::SendResponse(const void *data, const size_t &len) {
38   MS_ERROR_IF_NULL_W_RET_VAL(data, false);
39   http_msg_->QuickResponse(kHttpSuccess, reinterpret_cast<unsigned char *>(const_cast<void *>(data)), len);
40   return true;
41 }
42 }  // namespace core
43 }  // namespace ps
44 }  // namespace mindspore
45