• 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_CORE_MINDRT_SRC_ACTOR_IOMGR_H
18 #define MINDSPORE_CORE_MINDRT_SRC_ACTOR_IOMGR_H
19 #include <memory>
20 #include <string>
21 #include "actor/aid.h"
22 
23 #include "actor/msg.h"
24 
25 namespace mindspore {
26 
27 class AID;
28 class MessageBase;
29 
30 // Server socket listen backlog.
31 static const int SOCKET_LISTEN_BACKLOG = 2048;
32 
33 static const int SOCKET_KEEPALIVE = 1;
34 
35 // Send first probe after `interval' seconds.
36 static const int SOCKET_KEEPIDLE = 600;
37 
38 // Send next probes after the specified interval.
39 static const int SOCKET_KEEPINTERVAL = 5;
40 
41 // Consider the socket in error state after we send three ACK
42 // probes without getting a reply.
43 static const int SOCKET_KEEPCOUNT = 3;
44 
45 static const char MINDRT_MAGICID[] = "MINDRT0";
46 
47 static const char URL_PROTOCOL_IP_SEPARATOR[] = "://";
48 
49 static const char URL_IP_PORT_SEPARATOR[] = ":";
50 
51 static const char UDP_EVLOOP_THREADNAME[] = "MINDRT_Udp";
52 
53 static const char TCP_RECV_EVLOOP_THREADNAME[] = "MINDRT_TcpR";
54 static const char TCP_SEND_EVLOOP_THREADNAME[] = "MINDRT_TcpS";
55 
56 static const char HTTP_CLIENT_EVLOOP_THREADNAME[] = "MINDRT_Htp";
57 
58 class IOMgr {
59  public:
60   using MsgHandler = void (*)(std::unique_ptr<MessageBase> &&msg);
61   /**
62    * remoteLink and isExactNotRemote are flags to tell us which link should be used. There are several cases:
63    * 1. remoteLink is false and isExactNotRemote is false : callers can reuse remote link when threr are no links
64    * created before.
65    * 2. remoteLink is true and isExactNotRemote is false : callers can only use remote link
66    * 3. remoteLink is true and isExactNotRemote is true : as the same as case 2
67    * 4. remoteLink is false and isExactNotRemote is true : callers can't reuse remote link. if no link,
68    *    we will create a new one for callers.
69    */
70   virtual int Send(std::unique_ptr<MessageBase> &&msg, bool remoteLink = false, bool isExactNotRemote = false) = 0;
71   virtual void Link(const AID &sAid, const AID &dAid) = 0;
72   // close the socket,and send exitedEvent to all linkers.
73   virtual void UnLink(const AID &dAid) = 0;
74   virtual void Reconnect(const AID &sAid, const AID &dAid) = 0;
75   virtual void RegisterMsgHandle(MsgHandler handle) = 0;
76   virtual bool Init() = 0;                                                                  // once
77   virtual void Finish() = 0;                                                                // once
78   virtual bool StartIOServer(const std::string &url, const std::string &advertiseUrl) = 0;  // multicalledable
79   virtual uint64_t GetOutBufSize() = 0;
80   virtual uint64_t GetInBufSize() = 0;
81   virtual void CollectMetrics() = 0;
82   virtual int AddRuleUdp(std::string peer, int recordNum) = 0;
83   virtual void DelRuleUdp(std::string peer, bool outputLog) = 0;
84   virtual void LinkRecycleCheck(int recyclePeroid) = 0;
IOMgr()85   IOMgr() {}
~IOMgr()86   virtual ~IOMgr() {}
87 };
88 
89 };  // namespace mindspore
90 
91 #endif
92