<commit_before>#include "stdafx.h"
#include "network_mgr.h"
#include "venus_net/tcp_client.h"

CNetworkMgr::CNetworkMgr()
    : m_pServerAddress(NULL)
    , m_pTcpClient(NULL)
{

}

CNetworkMgr::~CNetworkMgr()
{
    Close();
}

BOOL CNetworkMgr::Connect(LPCSTR lpszIPAddress, unsigned int port)
{
    BOOL bReturn = FALSE;

    if (m_pServerAddress == NULL)
    {
        m_pServerAddress = new Poco::Net::SocketAddress(lpszIPAddress, port);
    }

    if (m_pTcpClient == NULL)
    {
        m_pTcpClient = new TcpClient(m_GameHandler);
    }

    if (!m_pTcpClient->connect(*m_pServerAddress))
    {
        goto Exit;
    }

    bReturn = TRUE;

Exit:
    return bReturn;
}

BOOL CNetworkMgr::SendMessage(GameNetworkMessage* pMessage)
{
    BOOL bReturn = FALSE;

    if (pMessage == NULL)
    {
        goto Exit;
    }

    if (m_pTcpClient == NULL)
    {
        goto Exit;
    }

    m_pTcpClient->sendMessage(pMessage->m_nId, *pMessage);
    bReturn = TRUE;

Exit:
    return bReturn;
}

void CNetworkMgr::Close()
{
    if (m_pTcpClient)
    {
        m_pTcpClient->close();
    }
}<commit_msg>& coeus 修正未连接close 导致的崩溃问题<commit_after>#include "stdafx.h"
#include "network_mgr.h"
#include "venus_net/tcp_client.h"

CNetworkMgr::CNetworkMgr()
    : m_pServerAddress(NULL)
    , m_pTcpClient(NULL)
{

}

CNetworkMgr::~CNetworkMgr()
{
    Close();
}

BOOL CNetworkMgr::Connect(LPCSTR lpszIPAddress, unsigned int port)
{
    BOOL bReturn = FALSE;

    if (m_pServerAddress == NULL)
    {
        m_pServerAddress = new Poco::Net::SocketAddress(lpszIPAddress, port);
    }

    if (m_pTcpClient == NULL)
    {
        m_pTcpClient = new TcpClient(m_GameHandler);
    }

    if (!m_pTcpClient->connect(*m_pServerAddress))
    {
        goto Exit;
    }

    bReturn = TRUE;

Exit:
    return bReturn;
}

BOOL CNetworkMgr::SendMessage(GameNetworkMessage* pMessage)
{
    BOOL bReturn = FALSE;

    if (pMessage == NULL)
    {
        goto Exit;
    }

    if (m_pTcpClient == NULL)
    {
        goto Exit;
    }

    m_pTcpClient->sendMessage(pMessage->m_nId, *pMessage);
    bReturn = TRUE;

Exit:
    return bReturn;
}

void CNetworkMgr::Close()
{
    if (m_pTcpClient
        || m_pTcpClient->connected())
    {
        m_pTcpClient->close();
    }
}
{'fraction_non_alphanumeric': 0.12555456965394854, 'fraction_numerical': 0.0, 'mean_word_length': 2.8415672913117547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '4870432', 'n_tokens_mistral': 883, 'n_tokens_neox': 883, 'n_words': 144}