Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef GUARD_server_h
- #define GUARD_server_h
- #include <string>
- #include <boost/bind.hpp>
- #include <boost/shared_ptr.hpp>
- #include <boost/enable_shared_from_this.hpp>
- #include <boost/asio.hpp>
- using boost::asio::ip::tcp;
- class server {
- public:
- server(int port);
- virtual ~server();
- };
- class tcp_connection: public boost::enable_shared_from_this<tcp_connection> {
- public:
- typedef boost::shared_ptr<tcp_connection> pointer;
- static pointer create(boost::asio::io_service& io_service) {
- return pointer(new tcp_connection(io_service));
- }
- tcp::socket& socket();
- void start();
- private:
- tcp_connection(boost::asio::io_service& io_service) :
- socket_(io_service) {
- }
- void
- handle_write(const boost::system::error_code& /*error*/, size_t /*bytes_transferred*/);
- tcp::socket socket_;
- std::string message_;
- };
- class tcp_server {
- public:
- tcp_server(boost::asio::io_service& io_service, int port);
- private:
- void start_accept();
- void handle_accept(tcp_connection::pointer new_connection,
- const boost::system::error_code& error);
- tcp::acceptor acceptor_;
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement