Example #1
0
int32 WorldSocket::SendPacket(const WorldPacket &sendPacket)
{
    if (!m_pSHSocket || m_pSHSocket->disconnected())
        return -1;

    try
    {
        m_pSendHeader->Reset(sendPacket.Size(), sendPacket.getMsgCode());

        size_t len = m_pSendHeader->size() + sendPacket.Size();

        m_sendDataHolder.resize(len);

        memset(&m_sendDataHolder[0], 0, len);
        memcpy(&m_sendDataHolder[0], m_pSendHeader->header(), m_pSendHeader->size());
        memcpy(&m_sendDataHolder[m_pSendHeader->size()], sendPacket.Contents(), sendPacket.Size());

        m_pSHSocket->Send(&m_sendDataHolder[0], len);

        m_sendDataHolder.clear();

        return 1;
    }
    catch (SHException e)
    {
        cout << e.what() << endl;
        return 0;
    }
}