mirror of
https://github.com/mikage-emu/mikage-dev.git
synced 2025-01-09 15:01:00 +01:00
26 lines
668 B
C++
26 lines
668 B
C++
|
#include "simple_tcp.hpp"
|
||
|
|
||
|
#include <boost/asio.hpp>
|
||
|
|
||
|
void SimpleTCPServer::SetupAsyncAccept() {
|
||
|
acceptor.async_accept([&](boost::system::error_code ec, boost::asio::ip::tcp::socket socket) {
|
||
|
if (!ec) {
|
||
|
OnClientConnected(std::move(socket));
|
||
|
}
|
||
|
SetupAsyncAccept();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
SimpleTCPServer::SimpleTCPServer(uint16_t port)
|
||
|
: acceptor(io_context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port)) {
|
||
|
SetupAsyncAccept();
|
||
|
}
|
||
|
|
||
|
void SimpleTCPServer::RunTCPServer() {
|
||
|
while (io_context.run()) {}
|
||
|
}
|
||
|
|
||
|
void SimpleTCPServer::StopTCPServer() {
|
||
|
boost::asio::post(io_context, [this]() { io_context.stop(); });
|
||
|
}
|