#pragma once #include #include #include #include #include #include enum class SocketState { Invalid, Connected, Disconnected, Closed }; class TCPSocket { private: std::atomic socket_fd_; std::atomic state_; protected: virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len) { return false; } virtual void setOptions(int socket_fd); bool setup(std::string &host, int port); void close(); public: TCPSocket(); virtual ~TCPSocket(); SocketState getState() { return state_; } int getSocketFD() { return socket_fd_; } bool setSocketFD(int socket_fd); bool read(uint8_t* buf, size_t buf_len, size_t &read); bool write(const uint8_t* buf, size_t buf_len, size_t &written); };