File indexing completed on 2025-01-30 10:10:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <list>
0012 #include <unordered_map>
0013
0014 #include <gloo/transport/tcp/address.h>
0015 #include <gloo/transport/tcp/attr.h>
0016 #include <gloo/transport/tcp/error.h>
0017 #include <gloo/transport/tcp/loop.h>
0018 #include <gloo/transport/tcp/socket.h>
0019
0020 namespace gloo {
0021 namespace transport {
0022 namespace tcp {
0023
0024
0025
0026
0027
0028
0029
0030 class Listener final : public Handler {
0031 public:
0032 using connect_callback_t =
0033 std::function<void(std::shared_ptr<Socket> socket, Error error)>;
0034
0035 static constexpr int kBacklog = -1;
0036
0037 Listener(std::shared_ptr<Loop> loop, const attr& attr);
0038
0039 ~Listener() override;
0040
0041 void handleEvents(int events) override;
0042
0043 Address nextAddress();
0044
0045
0046
0047
0048 void waitForConnection(sequence_number_t seq, connect_callback_t fn);
0049
0050 private:
0051 std::mutex mutex_;
0052 std::shared_ptr<Loop> loop_;
0053 std::shared_ptr<Socket> listener_;
0054
0055
0056
0057
0058
0059 Address addr_;
0060 sequence_number_t seq_{0};
0061
0062
0063 void haveConnection(std::shared_ptr<Socket> socket, sequence_number_t seq);
0064
0065
0066 std::unordered_map<sequence_number_t, connect_callback_t> seqToCallback_;
0067
0068
0069 std::unordered_map<sequence_number_t, std::shared_ptr<Socket>> seqToSocket_;
0070 };
0071
0072 }
0073 }
0074 }