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