connection.cc 610 B

12345678910111213141516171819202122232425262728293031
  1. #include <vector>
  2. #include <boost/bind.hpp>
  3. #include "net/connection.h"
  4. namespace hainan {
  5. connection::connection(boost::asio::io_service& io_service,
  6. connection_set& manager):
  7. socket_(io_service), connections_(manager)
  8. {
  9. }
  10. boost::asio::ip::tcp::socket& connection::socket()
  11. {
  12. return socket_;
  13. }
  14. void connection::start()
  15. {
  16. socket_.async_read_some(boost::asio::buffer(buffer_),
  17. boost::bind(&connection::handle_read, shared_from_this(),
  18. boost::asio::placeholders::error,
  19. boost::asio::placeholders::bytes_transferred));
  20. }
  21. void connection::stop()
  22. {
  23. socket_.close();
  24. }
  25. } // namespace hainan