asyn_server.cc 655 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include <boost/foreach.hpp>
  2. #include "base/base.h"
  3. #include "net/asyn_server.h"
  4. #include "net/connection.h"
  5. namespace hainan {
  6. explicit asyn_server::asyn_server(
  7. const string & address, const string & port):
  8. io_service(), acceptor(io_service),
  9. new_connection(new connection())
  10. {
  11. }
  12. void asyn_server::handle_accept(const system::error_code & e)
  13. {
  14. }
  15. void asyn_server::handle_stop()
  16. {
  17. acceptor.close();
  18. foreach(connection_ptr connection, all_connections)
  19. {
  20. connection.stop();
  21. }
  22. }
  23. void asyn_server::start()
  24. {
  25. io_service.run();
  26. }
  27. void asyn_server::stop()
  28. {
  29. io_service.post(bind(&asyn_server::handle_stop(), this));
  30. }
  31. } // namespace hainan