FairMQ  1.4.33
C++ Message Queuing Library and Framework
Context.h
1 /********************************************************************************
2  * Copyright (C) 2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #ifndef FAIR_MQ_OFI_CONTEXT_H
10 #define FAIR_MQ_OFI_CONTEXT_H
11 
12 #include <FairMQLogger.h>
13 #include <FairMQTransportFactory.h>
14 
15 #include <asiofi/domain.hpp>
16 #include <asiofi/fabric.hpp>
17 #include <asiofi/info.hpp>
18 #include <boost/asio/io_context.hpp>
19 #include <memory>
20 #include <netinet/in.h>
21 #include <ostream>
22 #include <stdexcept>
23 #include <string>
24 #include <thread>
25 #include <vector>
26 
27 namespace fair::mq::ofi
28 {
29 
30 enum class ConnectionType : bool { Bind, Connect };
31 
32 struct Address {
33  std::string Protocol;
34  std::string Ip;
35  unsigned int Port;
36  friend auto operator<<(std::ostream& os, const Address& a) -> std::ostream&
37  {
38  return os << a.Protocol << "://" << a.Ip << ":" << a.Port;
39  }
40  friend auto operator==(const Address& lhs, const Address& rhs) -> bool
41  {
42  return (lhs.Protocol == rhs.Protocol) && (lhs.Ip == rhs.Ip) && (lhs.Port == rhs.Port);
43  }
44 };
45 
52 class Context
53 {
54  public:
55  Context(FairMQTransportFactory& sendFactory,
56  FairMQTransportFactory& receiveFactory,
57  int numberIoThreads = 1);
58  ~Context();
59 
60  auto GetAsiofiVersion() const -> std::string;
61  auto GetIoContext() -> boost::asio::io_context& { return fIoContext; }
62  static auto ConvertAddress(std::string address) -> Address;
63  static auto ConvertAddress(Address address) -> sockaddr_in;
64  static auto ConvertAddress(sockaddr_in address) -> Address;
65  static auto VerifyAddress(const std::string& address) -> Address;
66  auto Interrupt() -> void { LOG(debug) << "OFI transport: Interrupted (NOOP - not implemented)."; }
67  auto Resume() -> void { LOG(debug) << "OFI transport: Resumed (NOOP - not implemented)."; }
68  auto Reset() -> void;
69  auto MakeReceiveMessage(size_t size) -> MessagePtr;
70  auto MakeSendMessage(size_t size) -> MessagePtr;
71  auto GetSizeHint() -> size_t { return fSizeHint; }
72  auto SetSizeHint(size_t size) -> void { fSizeHint = size; }
73 
74  private:
75  boost::asio::io_context fIoContext;
76  boost::asio::io_context::work fIoWork;
77  std::vector<std::thread> fThreadPool;
78  FairMQTransportFactory& fReceiveFactory;
79  FairMQTransportFactory& fSendFactory;
80  size_t fSizeHint;
81 
82  auto InitThreadPool(int numberIoThreads) -> void;
83 }; /* class Context */
84 
85 struct ContextError : std::runtime_error { using std::runtime_error::runtime_error; };
86 
87 } // namespace fair::mq::ofi
88 
89 #endif /* FAIR_MQ_OFI_CONTEXT_H */
fair::mq::ofi::Context
Transport-wide context.
Definition: Context.h:59
fair::mq::ofi::Address
Definition: Context.h:38
FairMQTransportFactory
Definition: FairMQTransportFactory.h:30

privacy