Connection.h 787 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef CONNECTION_H
  2. #define CONNECTION_H
  3. #include "Protocol/Protocol.h"
  4. #include "Util/Util.h"
  5. #include <asio.hpp>
  6. #include <string>
  7. namespace MailServer {
  8. class Connection
  9. {
  10. public:
  11. Connection(asio::io_service& ioService, const Util::Context& context);
  12. asio::ip::tcp::socket& Socket();
  13. void Start();
  14. private:
  15. Connection(const Connection&) = delete;
  16. Connection& operator=(const Connection&) = delete;
  17. private:
  18. void StartRead();
  19. void HandleRead(const asio::error_code& ec, std::size_t length);
  20. void StartWrite(const std::string& message);
  21. void HandleWrite(const asio::error_code& ec);
  22. asio::io_service& m_ioService;
  23. asio::ip::tcp::socket m_socket;
  24. std::array<char, 1024> m_data;
  25. Protocol::Protocol m_protocol;
  26. };
  27. } // namespace MailServer
  28. #endif // CONNECTION_H