#pragma once

#include <asio.hpp>
#include <mutex>
#include <of_util.h>

#include "util.h"

using namespace ofen;
class CTcpClient : public std::enable_shared_from_this<CTcpClient>
{
public:
    explicit CTcpClient(asio::io_context& io_context);
    ~CTcpClient();

public:
    bool connect(const std::string& host, const std::string& port);
    void disconnect();
    bool send(const char* data, int len);
    void register_func(ExFun_t&& f);
    void async_recv();
    bool is_normal() const;

private:
    asio::io_context& io_context_;
    asio::ip::tcp::socket socket_;
    std::mutex mutex_;
    CMutBuffer buffer_;
    std::array<char, g_BuffSize> tmp_buf_{};
    ExFun_t fun_;
    std::string remote_key_;
    bool is_normal_{true};
};