File indexing completed on 2025-01-30 10:10:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <array>
0012 #include <atomic>
0013 #include <condition_variable>
0014 #include <memory>
0015 #include <mutex>
0016 #include <thread>
0017
0018 #include <gloo/transport/device.h>
0019 #include <gloo/transport/tcp/attr.h>
0020 #include <gloo/transport/tcp/error.h>
0021 #include <gloo/transport/tcp/listener.h>
0022 #include <gloo/transport/tcp/loop.h>
0023 #include <gloo/transport/tcp/socket.h>
0024
0025 namespace gloo {
0026 namespace transport {
0027 namespace tcp {
0028
0029 struct attr CreateDeviceAttr(const struct attr& src);
0030
0031 std::shared_ptr<::gloo::transport::Device> CreateDevice(
0032 const struct attr&);
0033
0034
0035 class Pair;
0036 class Buffer;
0037
0038 class Device : public ::gloo::transport::Device,
0039 public std::enable_shared_from_this<Device> {
0040 public:
0041 explicit Device(const struct attr& attr);
0042 virtual ~Device();
0043
0044 virtual std::string str() const override;
0045
0046 virtual const std::string& getPCIBusID() const override;
0047
0048 virtual int getInterfaceSpeed() const override;
0049
0050 virtual std::shared_ptr<::gloo::transport::Context> createContext(
0051 int rank, int size) override;
0052
0053 void registerDescriptor(int fd, int events, Handler* h);
0054 void unregisterDescriptor(int fd, Handler* h);
0055
0056
0057
0058 bool isInitiator(
0059 const Address& local,
0060 const Address& remote) const;
0061
0062 protected:
0063 const struct attr attr_;
0064
0065
0066
0067
0068
0069
0070
0071 Address nextAddress();
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 using connect_callback_t =
0087 std::function<void(std::shared_ptr<Socket> socket, Error error)>;
0088
0089 void connect(
0090 const Address& local,
0091 const Address& remote,
0092 std::chrono::milliseconds timeout,
0093 connect_callback_t fn);
0094
0095 void connectAsListener(
0096 const Address& local,
0097 std::chrono::milliseconds timeout,
0098 connect_callback_t fn);
0099
0100 void connectAsInitiator(
0101 const Address& remote,
0102 std::chrono::milliseconds timeout,
0103 connect_callback_t fn);
0104
0105 friend class Pair;
0106 friend class Buffer;
0107
0108 private:
0109 std::shared_ptr<Loop> loop_;
0110 std::shared_ptr<Listener> listener_;
0111
0112 std::string interfaceName_;
0113 int interfaceSpeedMbps_;
0114 std::string pciBusID_;
0115 };
0116
0117 }
0118 }
0119 }