#pragma once

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

using namespace ofen;
class CTcpClient : public std::enable_shared_from_this<CTcpClient>
{
public:
    CTcpClient(asio::io_context& io_context, const std::shared_ptr<spdlog::logger>& logger);
    ~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();

private:
    std::shared_ptr<spdlog::logger> logger_;
    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};
};