mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-14 04:57:21 +01:00
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <brynet/base/NonCopyable.hpp>
|
|
#include <brynet/net/EventLoop.hpp>
|
|
#include <memory>
|
|
#include <thread>
|
|
|
|
class TcpServiceDetail;
|
|
|
|
class IOLoopData : public NonCopyable,
|
|
public std::enable_shared_from_this<IOLoopData> {
|
|
public:
|
|
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;
|
|
}
|
|
|
|
protected:
|
|
const std::shared_ptr<std::thread> &getIOThread() const {
|
|
return mIOThread;
|
|
}
|
|
|
|
IOLoopData(EventLoop::Ptr eventLoop,
|
|
std::shared_ptr<std::thread> ioThread) :
|
|
mEventLoop(std::move(eventLoop)),
|
|
mIOThread(std::move(ioThread)) {}
|
|
virtual ~IOLoopData() = default;
|
|
|
|
const EventLoop::Ptr mEventLoop;
|
|
|
|
private:
|
|
std::shared_ptr<std::thread> mIOThread;
|
|
|
|
friend class TcpServiceDetail;
|
|
};
|
|
|
|
using IOLoopDataPtr = std::shared_ptr<IOLoopData>;
|