NetworkConnection.h 920 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * NetworkConnection.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "NetworkDefines.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class DLL_LINKAGE NetworkConnection : boost::noncopyable
  14. {
  15. static const int messageHeaderSize = sizeof(uint32_t);
  16. static const int messageMaxSize = 1024;
  17. std::shared_ptr<NetworkSocket> socket;
  18. NetworkBuffer readBuffer;
  19. void onHeaderReceived(const boost::system::error_code & ec);
  20. void onPacketReceived(const boost::system::error_code & ec, uint32_t expectedPacketSize);
  21. uint32_t readPacketSize(const boost::system::error_code & ec);
  22. public:
  23. NetworkConnection(const std::shared_ptr<NetworkSocket> & socket);
  24. void start();
  25. void sendPacket(const std::vector<uint8_t> & message);
  26. };
  27. VCMI_LIB_NAMESPACE_END