#include <booster/shared_ptr.h>
#include <booster/enable_shared_from_this.h>
#include <booster/aio/io_service.h>
#include <booster/aio/buffer.h>
#include <booster/aio/endpoint.h>
#include <booster/aio/acceptor.h>
#include <booster/aio/stream_socket.h>
#include <iostream>
#include <functional>
public:
{
}
void run()
{
socket_.async_read_some(
std::bind(&echo_session::on_read,shared_from_this(),
std::placeholders::_1,
std::placeholders::_2));
}
{
if(e) return;
std::bind(&echo_session::on_written,shared_from_this(),std::placeholders::_1));
}
{
if(e) return;
run();
}
private:
friend class echo_acceptor;
char buffer_[1024];
};
class echo_acceptor {
public:
{
acceptor_.open(ep.family());
acceptor_.set_option(booster::aio::acceptor::reuse_address,true);
acceptor_.bind(ep);
acceptor_.listen(10);
}
void run()
{
new_session_.reset(new echo_session(acceptor_.get_io_service()));
acceptor_.async_accept(new_session_->socket_,
std::bind(&echo_acceptor::on_accepted,this,std::placeholders::_1));
}
{
if(e) {
std::cout << e.
message() << std::endl;
run();
}
else {
new_session_->run();
run();
}
}
private:
};
int main()
{
try {
#if !defined(_WIN32) && !defined(__CYGWIN__)
stdin_device.attach(0);
std::cout << "Press any key to stop" << std::endl;
#endif
echo_acceptor acc(srv);
acc.run();
}
catch(std::exception const &e) {
std::cerr<<e.what()<<std::endl;
}
}