Skip to content

Instantly share code, notes, and snippets.

@ChrisCates
Created November 19, 2018 23:08
Show Gist options
  • Select an option

  • Save ChrisCates/b91b9b5bbaae47e2fb730f178229bc6a to your computer and use it in GitHub Desktop.

Select an option

Save ChrisCates/b91b9b5bbaae47e2fb730f178229bc6a to your computer and use it in GitHub Desktop.
server::server(
asio::io_service& io_service, int port) : io_service(io_service),
acceptor(io_service, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)),
new_conn(connection::create(io_service)
) {
acceptor.async_accept(
new_conn->getSocket(),
bind(
&server::handle_accept,
this,
asio::placeholders::error
)
);
}
void server::handle_accept(const system::error_code& e) {
if (!e) {
boost::thread t(
bind(
&connection::run,
new_conn
)
);
new_conn = connection::create(io_service);
acceptor.async_accept(
new_conn->getSocket(),
boost::bind(
&server::handle_accept,
this,
asio::placeholders::error
)
);
} else {
cout << "Error: " << e << endl;;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment