• 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 #ifndef MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_HTTP_REQUEST_HANDLER_H_
18 #define MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_HTTP_REQUEST_HANDLER_H_
19 
20 #include <event2/event.h>
21 #include <event2/http.h>
22 #include <event2/http_struct.h>
23 #include <event2/bufferevent.h>
24 #include <event2/bufferevent_ssl.h>
25 
26 #include <string>
27 #include <memory>
28 #include <unordered_map>
29 
30 #include "utils/log_adapter.h"
31 #include "ps/core/communicator/http_message_handler.h"
32 #include "ps/core/communicator/ssl_http.h"
33 #include "ps/constants.h"
34 #include "ps/ps_context.h"
35 
36 namespace mindspore {
37 namespace ps {
38 namespace core {
39 using OnRequestReceive = std::function<void(std::shared_ptr<HttpMessageHandler>)>;
40 
41 /* Each thread corresponds to one HttpRequestHandler, which is used to create one eventbase. All eventbase are listened
42  * on the same fd. Every evhttp_request is executed in one thread.
43  */
44 class HttpRequestHandler {
45  public:
HttpRequestHandler()46   HttpRequestHandler() : evbase_(nullptr) {}
47   virtual ~HttpRequestHandler();
48 
49   bool Initialize(int fd, const std::unordered_map<std::string, OnRequestReceive *> &handlers);
50   void Run();
51   bool Stop();
52   static bufferevent *BuffereventCallback(event_base *base, void *arg);
53 
54  private:
55   struct event_base *evbase_;
56 };
57 }  // namespace core
58 }  // namespace ps
59 }  // namespace mindspore
60 #endif  // MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_HTTP_REQUEST_HANDLER_H_
61