18 #ifndef __ASYNCACCEPT_H_
19 #define __ASYNCACCEPT_H_
22 #include <boost/asio.hpp>
26 using boost::asio::ip::tcp;
34 _acceptor(ioService, tcp::endpoint(
boost::asio::ip::address::from_string(bindIp), port)),
42 template<AcceptCallback acceptCallback>
48 _acceptor.async_accept(*socket, [
this, socket, threadIndex](boost::system::error_code error)
54 socket->non_blocking(
true);
56 acceptCallback(std::move(*socket), threadIndex);
58 catch (boost::system::system_error
const& err)
60 TC_LOG_INFO(
"network",
"Failed to initialize client's socket %s", err.what());
65 this->AsyncAcceptWithCallback<acceptCallback>();
74 boost::system::error_code err;
99 std::make_shared<T>(std::move(this->
_socket))->Start();
101 catch (boost::system::system_error
const& err)
103 TC_LOG_INFO(
"network",
"Failed to retrieve client's remote address %s", err.what());
109 this->AsyncAccept<T>();
Definition: AsyncAcceptor.h:28
std::function< std::pair< tcp::socket *, uint32 >)> _socketFactory
Definition: AsyncAcceptor.h:86
void Close()
Definition: AsyncAcceptor.h:69
tcp::socket _socket
Definition: AsyncAcceptor.h:84
#define false
Definition: CascPort.h:18
tcp::acceptor _acceptor
Definition: AsyncAcceptor.h:83
void SetSocketFactory(std::function< std::pair< tcp::socket *, uint32 >()> func)
Definition: AsyncAcceptor.h:78
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
AsyncAcceptor(boost::asio::io_service &ioService, std::string const &bindIp, uint16 port)
Definition: AsyncAcceptor.h:33
void AsyncAcceptWithCallback()
Definition: AsyncAcceptor.h:43
std::pair< tcp::socket *, uint32 > DefeaultSocketFactory()
Definition: AsyncAcceptor.h:81
void AsyncAccept()
Definition: AsyncAcceptor.h:90
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
void(* AcceptCallback)(tcp::socket &&newSocket, uint32 threadIndex)
Definition: AsyncAcceptor.h:31
std::atomic< bool > _closed
Definition: AsyncAcceptor.h:85