tcp_client.h 710 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 isConnect();
  25. static bool busy();
  26. private:
  27. TcpClient();
  28. void internalSendMsg(const char* msg);
  29. private:
  30. std::atomic<bool> busy_;
  31. };
  32. #endif /* JNI_NET_TCP_CLIENT_H_ */