PlainConnection.h 842 B

123456789101112131415161718192021222324252627282930313233343536
  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 "sys/socket.h"
  9. #include <netdb.h>
  10. #include <unistd.h>
  11. #endif
  12. #include <functional>
  13. #include <vector>
  14. #include <string>
  15. #include <cstdint>
  16. #include "Packet.h"
  17. #include "Utils.h"
  18. typedef std::function<bool()> timeoutCallback;
  19. class PlainConnection
  20. {
  21. public:
  22. PlainConnection();
  23. ~PlainConnection();
  24. int apSock;
  25. void connectToAp(std::string apAddress);
  26. void closeSocket();
  27. timeoutCallback timeoutHandler;
  28. std::vector<uint8_t> sendPrefixPacket(const std::vector<uint8_t> &prefix, const std::vector<uint8_t> &data);
  29. std::vector<uint8_t> recvPacket();
  30. std::vector<uint8_t> readBlock(size_t size);
  31. size_t writeBlock(const std::vector<uint8_t> &data);
  32. };
  33. #endif