PlainConnection.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef PLAINCONNECTION_H
  2. #define PLAINCONNECTION_H
  3. #ifdef _WIN32
  4. #include <winsock2.h>
  5. #include <ws2tcpip.h>
  6. #include "win32shim.h"
  7. #else
  8. #include <netdb.h>
  9. #include <unistd.h>
  10. #include "sys/socket.h"
  11. #include <netinet/in.h>
  12. #endif
  13. #include <cstdint>
  14. #include <functional>
  15. #include <string>
  16. #include <vector>
  17. #include "Packet.h"
  18. #include "Utils.h"
  19. typedef std::function<bool()> timeoutCallback;
  20. namespace cspot {
  21. class PlainConnection {
  22. public:
  23. PlainConnection();
  24. ~PlainConnection();
  25. /**
  26. * @brief Connect to the given AP address
  27. *
  28. * @param apAddress The AP url to connect to
  29. */
  30. void connect(const std::string& apAddress);
  31. void close();
  32. timeoutCallback timeoutHandler;
  33. std::vector<uint8_t> sendPrefixPacket(const std::vector<uint8_t>& prefix,
  34. const std::vector<uint8_t>& data);
  35. std::vector<uint8_t> recvPacket();
  36. void readBlock(const uint8_t* dst, size_t size);
  37. size_t writeBlock(const std::vector<uint8_t>& data);
  38. private:
  39. int apSock;
  40. };
  41. } // namespace cspot
  42. #endif