<commit_before>#include <Bull/Core/Thread/Thread.hpp>
#include <Bull/Core/Time/Clock.hpp>
#include <Bull/Core/Utility/CallOnExit.hpp>

#include <Bull/Network/Address/IpAddressWrapper.hpp>
#include <Bull/Network/Socket/TcpClient.hpp>
#include <Bull/Network/Socket/TcpClientImpl.hpp>

namespace Bull
{
    TcpClient::TcpClient() :
        Socket(SocketType_Tcp)
    {
        /// Nothing
    }

    TcpClient::~TcpClient()
    {
        disconnect();
    }

    bool TcpClient::connect(const IpAddressWrapper& address, NetPort port)
    {
        if(Socket::create(address.getProtocol()))
        {
            m_impl = std::make_unique<prv::TcpClientImpl>(getImpl());

            return m_impl->connect(address, port);
        }

        return false;
    }

    bool TcpClient::connect(const IpAddressWrapper& address, NetPort port, const Time& timeout, const Time& pause)
    {
        Clock clock;
        bool connected;

        clock.start();

        do
        {
            connected = connect(address, port);

            if(!connected)
            {
                Thread::sleep(pause);
            }
        }while(!connected && clock.getElapsedTime() < timeout);

        return connected;
    }

    bool TcpClient::isConnected() const
    {
        return m_impl != nullptr;
    }

    void TcpClient::disconnect()
    {
        close();
        m_impl.reset();
        m_hostPort = NetPort_Any;
        m_hostAddress = IpAddressV4::None;
    }

    bool TcpClient::send(const void* data, std::size_t length, std::size_t& sent)
    {
        if(isConnected())
        {
            return m_impl->send(data, length, sent);
        }

        return false;
    }

    bool TcpClient::receive(void* data, std::size_t length, std::size_t& sent)
    {
        if(isConnected())
        {
            return m_impl->reveive(data, length, sent);<commit_msg>[Network/TcpClient] Add some safety checks<commit_after>#include <Bull/Core/Thread/Thread.hpp>
#include <Bull/Core/Time/Clock.hpp>
#include <Bull/Core/Utility/CallOnExit.hpp>

#include <Bull/Network/Address/IpAddressWrapper.hpp>
#include <Bull/Network/Socket/TcpClient.hpp>
#include <Bull/Network/Socket/TcpClientImpl.hpp>

namespace Bull
{
    TcpClient::TcpClient() :
        Socket(SocketType_Tcp)
    {
        /// Nothing
    }

    TcpClient::~TcpClient()
    {
        disconnect();
    }

    bool TcpClient::connect(const IpAddressWrapper& address, NetPort port)
    {
        if(address.isValid() && port != NetPort_Any && Socket::create(address.getProtocol()))
        {
            m_impl = std::make_unique<prv::TcpClientImpl>(getImpl());

            return m_impl->connect(address, port);
        }

        return false;
    }

    bool TcpClient::connect(const IpAddressWrapper& address, NetPort port, const Time& timeout, const Time& pause)
    {
        bool connected = false;

        if(address.isValid() && port != NetPort_Any)
        {
            Clock clock;
            clock.start();

            do
            {
                connected = connect(address, port);

                if(!connected)
                {
                    Thread::sleep(pause);
                }
            }while(!connected && clock.getElapsedTime() < timeout);

            return connected;
        }

        return connected;
    }

    bool TcpClient::isConnected() const
    {
        return m_impl != nullptr;
    }

    void TcpClient::disconnect()
    {
        close();
        m_impl.reset();
        m_hostPort = NetPort_Any;
        m_hostAddress = IpAddressV4::None;
    }

    bool TcpClient::send(const void* data, std::size_t length, std::size_t& sent)
    {
        if(isConnected() && data && length)
        {
            return m_impl->send(data, length, sent);
        }

        return false;
    }

    bool TcpClient::receive(void* data, std::size_t length, std::size_t& sent)
    {
        if(isConnected() && data && length)
        {
            return m_impl->reveive(data, length, sent);
{'fraction_non_alphanumeric': 0.1249061326658323, 'fraction_numerical': 0.0005006257822277847, 'mean_word_length': 2.1073094867807156, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1543208', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1211, 'n_words': 220}