tcp_client.h 683 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * tcp_client.h
  3. *
  4. * Created on: 2022年10月5日
  5. * Author: Allen
  6. */
  7. #ifndef JNI_NET_TCP_CLIENT_H_
  8. #define JNI_NET_TCP_CLIENT_H_
  9. #include <atomic>
  10. #include <functional>
  11. #include <thread>
  12. #include "net.h"
  13. #include "service/BusinessConfig.h"
  14. #include "tcp_model.h"
  15. class TcpClient {
  16. public:
  17. virtual ~TcpClient();
  18. static TcpClient* instance();
  19. void startTcp();
  20. void closeTcp();
  21. void sendMsg(const char* msg);
  22. void sendMsgWithCb(const char* msg, TcpCallback callback);
  23. static bool connected();
  24. static bool busy();
  25. private:
  26. TcpClient();
  27. void internalSendMsg(const char* msg);
  28. private:
  29. std::atomic<bool> busy_;
  30. };
  31. #endif /* JNI_NET_TCP_CLIENT_H_ */