File indexing completed on 2025-01-30 10:10:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <sys/socket.h>
0012 #include <unistd.h>
0013 #include <mutex>
0014
0015 #include "gloo/transport/address.h"
0016
0017 namespace gloo {
0018 namespace transport {
0019 namespace tcp {
0020
0021 using sequence_number_t = ssize_t;
0022
0023 class Address : public ::gloo::transport::Address {
0024 public:
0025 static constexpr sequence_number_t kSequenceNumberUnset = -1;
0026
0027 Address() {}
0028
0029 explicit Address(struct sockaddr_storage ss, sequence_number_t seq = -1);
0030
0031 explicit Address(const struct sockaddr* addr, size_t addrlen);
0032
0033 explicit Address(const std::vector<char>&);
0034
0035 Address(const Address& other);
0036
0037 Address& operator=(Address&& other);
0038 Address& operator=(const Address& other);
0039
0040 virtual std::vector<char> bytes() const override;
0041
0042 virtual std::string str() const override;
0043
0044 const struct sockaddr_storage& getSockaddr() const {
0045 return impl_.ss;
0046 }
0047
0048 sequence_number_t getSeq() const {
0049 return impl_.seq;
0050 }
0051
0052 static Address fromSockName(int fd);
0053
0054 static Address fromPeerName(int fd);
0055
0056 protected:
0057
0058
0059 struct Impl {
0060
0061 struct sockaddr_storage ss;
0062
0063
0064
0065
0066
0067 sequence_number_t seq{kSequenceNumberUnset};
0068 };
0069
0070 static_assert(std::is_trivially_copyable<Impl>::value, "!");
0071 static_assert(sizeof(Impl) <= kMaxByteSize, "!");
0072
0073 Impl impl_;
0074 mutable std::mutex m_;
0075 };
0076
0077 }
0078 }
0079 }