rcpp_framework/libs/brynet/net/TcpService.hpp

39 lines
956 B
C++
Raw Normal View History

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