2020-11-24 15:41:18 +01:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <brynet/net/detail/TCPServiceDetail.hpp>
|
|
|
|
|
|
2021-05-14 17:16:45 +02:00
|
|
|
|
namespace brynet {
|
|
|
|
|
namespace net {
|
2020-11-24 15:41:18 +01:00
|
|
|
|
|
2021-04-30 16:10:14 +02:00
|
|
|
|
using ConnectionOption = detail::ConnectionOption;
|
|
|
|
|
class TcpService : public detail::TcpServiceDetail,
|
2021-05-14 17:16:45 +02:00
|
|
|
|
public std::enable_shared_from_this<TcpService> {
|
2021-04-30 16:10:14 +02:00
|
|
|
|
public:
|
2021-05-14 17:16:45 +02:00
|
|
|
|
using Ptr = std::shared_ptr<TcpService>;
|
|
|
|
|
using FrameCallback = detail::TcpServiceDetail::FrameCallback;
|
2021-04-30 16:10:14 +02:00
|
|
|
|
|
|
|
|
|
public:
|
2021-05-14 17:16:45 +02:00
|
|
|
|
static Ptr Create() {
|
|
|
|
|
struct make_shared_enabler : public TcpService {
|
|
|
|
|
};
|
|
|
|
|
return std::make_shared<make_shared_enabler>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startWorkerThread(size_t threadNum,
|
|
|
|
|
FrameCallback callback = nullptr) {
|
|
|
|
|
detail::TcpServiceDetail::startWorkerThread(threadNum, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stopWorkerThread() {
|
|
|
|
|
detail::TcpServiceDetail::stopWorkerThread();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool addTcpConnection(TcpSocket::Ptr socket, ConnectionOption options) {
|
|
|
|
|
return detail::TcpServiceDetail::addTcpConnection(std::move(socket), options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventLoop::Ptr getRandomEventLoop() {
|
|
|
|
|
return detail::TcpServiceDetail::getRandomEventLoop();
|
|
|
|
|
}
|
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
|
|
|
|
TcpService() = default;
|
2021-04-30 16:10:14 +02:00
|
|
|
|
};
|
2020-11-24 15:41:18 +01:00
|
|
|
|
|
2021-05-14 17:16:45 +02:00
|
|
|
|
} // namespace net
|
|
|
|
|
} // namespace brynet
|