Advertisement
Guest User

Untitled

a guest
Mar 25th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #ifndef GUARD_server_h
  2. #define GUARD_server_h
  3.  
  4. #include <string>
  5. #include <boost/bind.hpp>
  6. #include <boost/shared_ptr.hpp>
  7. #include <boost/enable_shared_from_this.hpp>
  8. #include <boost/asio.hpp>
  9.  
  10. using boost::asio::ip::tcp;
  11.  
  12. class server {
  13. public:
  14.     server(int port);
  15.     virtual ~server();
  16. };
  17.  
  18. class tcp_connection: public boost::enable_shared_from_this<tcp_connection> {
  19. public:
  20.     typedef boost::shared_ptr<tcp_connection> pointer;
  21.  
  22.     static pointer create(boost::asio::io_service& io_service) {
  23.         return pointer(new tcp_connection(io_service));
  24.     }
  25.  
  26.     tcp::socket& socket();
  27.  
  28.     void start();
  29.  
  30. private:
  31.     tcp_connection(boost::asio::io_service& io_service) :
  32.         socket_(io_service) {
  33.     }
  34.  
  35.     void
  36.             handle_write(const boost::system::error_code& /*error*/, size_t /*bytes_transferred*/);
  37.  
  38.     tcp::socket socket_;
  39.     std::string message_;
  40. };
  41.  
  42. class tcp_server {
  43.  
  44. public:
  45.     tcp_server(boost::asio::io_service& io_service, int port);
  46.  
  47. private:
  48.     void start_accept();
  49.  
  50.     void handle_accept(tcp_connection::pointer new_connection,
  51.             const boost::system::error_code& error);
  52.  
  53.     tcp::acceptor acceptor_;
  54. };
  55.  
  56. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement