rcpp_framework/libs/brynet/net/detail/IOLoopData.hpp

60 lines
1.3 KiB
C++
Raw Normal View History

2020-11-24 15:41:18 +01:00
#pragma once
#include <brynet/base/NonCopyable.hpp>
#include <brynet/net/EventLoop.hpp>
2021-04-30 16:10:14 +02:00
#include <memory>
#include <thread>
2020-11-24 15:41:18 +01:00
2021-05-14 17:16:45 +02:00
namespace brynet {
namespace net {
namespace detail {
2020-11-24 15:41:18 +01:00
2021-04-30 16:10:14 +02:00
class TcpServiceDetail;
2020-11-24 15:41:18 +01:00
2021-04-30 16:10:14 +02:00
class IOLoopData : public brynet::base::NonCopyable,
2021-05-14 17:16:45 +02:00
public std::enable_shared_from_this<IOLoopData> {
2021-04-30 16:10:14 +02:00
public:
2021-05-14 17:16:45 +02:00
using Ptr = std::shared_ptr<IOLoopData>;
static Ptr Create(EventLoop::Ptr eventLoop,
std::shared_ptr<std::thread> ioThread) {
class make_shared_enabler : public IOLoopData {
public:
make_shared_enabler(EventLoop::Ptr eventLoop,
std::shared_ptr<std::thread> ioThread) :
IOLoopData(std::move(eventLoop), std::move(ioThread)) {}
};
return std::make_shared<make_shared_enabler>(std::move(eventLoop),
std::move(ioThread));
}
const EventLoop::Ptr &getEventLoop() const {
return mEventLoop;
}
2020-11-24 15:41:18 +01:00
2021-04-30 16:10:14 +02:00
protected:
2021-05-14 17:16:45 +02:00
const std::shared_ptr<std::thread> &getIOThread() const {
return mIOThread;
}
2020-11-24 15:41:18 +01:00
2021-05-14 17:16:45 +02:00
IOLoopData(EventLoop::Ptr eventLoop,
std::shared_ptr<std::thread> ioThread) :
mEventLoop(std::move(eventLoop)),
mIOThread(std::move(ioThread)) {}
virtual ~IOLoopData() = default;
2020-11-24 15:41:18 +01:00
2021-05-14 17:16:45 +02:00
const EventLoop::Ptr mEventLoop;
2020-11-24 15:41:18 +01:00
2021-04-30 16:10:14 +02:00
private:
2021-05-14 17:16:45 +02:00
std::shared_ptr<std::thread> mIOThread;
2020-11-24 15:41:18 +01:00
2021-05-14 17:16:45 +02:00
friend class TcpServiceDetail;
2021-04-30 16:10:14 +02:00
};
2020-11-24 15:41:18 +01:00
2021-04-30 16:10:14 +02:00
using IOLoopDataPtr = std::shared_ptr<IOLoopData>;
2020-11-24 15:41:18 +01:00
2021-05-14 17:16:45 +02:00
} // namespace detail
} // namespace net
} // namespace brynet