mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 17:27:36 +01:00
Backed out changeset 5da05b39c3eb
Causes crashes on Linux. --HG-- branch : trunk
This commit is contained in:
@@ -188,8 +188,7 @@ int WorldSocket::SendPacket (const WorldPacket& pct)
|
||||
sWorldLog.outLog ("\n");
|
||||
}
|
||||
|
||||
// don't try to send the packet if there are packets on the queue
|
||||
if (!m_PacketQueue.is_empty() || iSendPacket(pct) == -1)
|
||||
if (iSendPacket (pct) == -1)
|
||||
{
|
||||
WorldPacket* npct;
|
||||
|
||||
@@ -203,12 +202,6 @@ int WorldSocket::SendPacket (const WorldPacket& pct)
|
||||
sLog.outError ("WorldSocket::SendPacket: m_PacketQueue.enqueue_tail failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// iSendPacket may fail if the packet is larger than the buffer (even in the buffer is empty)
|
||||
// So we must try to flush so the packet may be sent partially
|
||||
// don't cancel_wakeup_output here
|
||||
if (iFlushPacketQueue())
|
||||
return schedule_wakeup_output(Guard);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -328,15 +321,10 @@ int WorldSocket::handle_output (ACE_HANDLE)
|
||||
if (closing_)
|
||||
return -1;
|
||||
|
||||
size_t send_len = m_OutBuffer->length();
|
||||
const size_t send_len = m_OutBuffer->length ();
|
||||
|
||||
if (send_len == 0)
|
||||
{
|
||||
if (!iFlushPacketQueue())
|
||||
return cancel_wakeup_output(Guard);
|
||||
|
||||
send_len = m_OutBuffer->length ();
|
||||
}
|
||||
return cancel_wakeup_output (Guard);
|
||||
|
||||
#ifdef MSG_NOSIGNAL
|
||||
ssize_t n = peer ().send (m_OutBuffer->rd_ptr (), send_len, MSG_NOSIGNAL);
|
||||
@@ -972,7 +960,7 @@ int WorldSocket::HandlePing (WorldPacket& recvPacket)
|
||||
int WorldSocket::iSendPacket (const WorldPacket& pct)
|
||||
{
|
||||
ServerPktHeader header(pct.size()+2, pct.GetOpcode());
|
||||
if (m_OutBuffer->space() < pct.size () + header.getHeaderLength())
|
||||
if (m_OutBuffer->space () < pct.size () + header.getHeaderLength())
|
||||
{
|
||||
errno = ENOBUFS;
|
||||
return -1;
|
||||
@@ -991,73 +979,16 @@ int WorldSocket::iSendPacket (const WorldPacket& pct)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Return 1 if some bytes written and packet completed
|
||||
/// Return 0 if no byte written, but still remaining data
|
||||
/// Return -1 if some bytes written and still remaining data
|
||||
int WorldSocket::iSendPartialPacket(WorldPacket& pct)
|
||||
{
|
||||
size_t remainingLen = pct.size() - pct.rpos();
|
||||
|
||||
if (pct.rpos() == 0) // nothing sent yet => send header
|
||||
{
|
||||
ServerPktHeader header(pct.size()+2, pct.GetOpcode());
|
||||
|
||||
if (m_OutBuffer->space () < pct.size () + header.getHeaderLength())
|
||||
{
|
||||
// be sure to send big packet (otherwise, they would stay in the queue)
|
||||
// So for packet larger than 1K, just check if there are some usefull space
|
||||
if (pct.size() > 1024 && m_OutBuffer->space () < header.getHeaderLength() + 1024)
|
||||
{
|
||||
return 0; // nothing written, still remaining data => 0
|
||||
}
|
||||
}
|
||||
|
||||
m_Crypt.EncryptSend ( header.header, header.getHeaderLength());
|
||||
|
||||
if (m_OutBuffer->copy ((char*) header.header, header.getHeaderLength()) == -1)
|
||||
ACE_ASSERT (false);
|
||||
|
||||
if (remainingLen == 0)
|
||||
{
|
||||
return 1; // header written, nothing else => 1
|
||||
}
|
||||
}
|
||||
|
||||
if ((m_OutBuffer->space()) < remainingLen) {
|
||||
size_t len = m_OutBuffer->space();
|
||||
|
||||
if (m_OutBuffer->copy ((char*) (pct.contents() + pct.rpos()), len) == -1)
|
||||
ACE_ASSERT (false);
|
||||
|
||||
pct.read_skip(len);
|
||||
return -1; // packet will be pushed back on the queue
|
||||
}
|
||||
|
||||
if (m_OutBuffer->copy ((char*) (pct.contents() + pct.rpos()), remainingLen) == -1)
|
||||
ACE_ASSERT (false);
|
||||
|
||||
return 1; // some byte written and packet completed
|
||||
}
|
||||
|
||||
|
||||
bool WorldSocket::iFlushPacketQueue()
|
||||
bool WorldSocket::iFlushPacketQueue ()
|
||||
{
|
||||
WorldPacket *pct;
|
||||
bool haveone = false;
|
||||
|
||||
while (m_PacketQueue.dequeue_head(pct) == 0)
|
||||
while (m_PacketQueue.dequeue_head (pct) == 0)
|
||||
{
|
||||
int result = iSendPartialPacket(*pct);
|
||||
|
||||
if (result != 0)
|
||||
if (iSendPacket (*pct) == -1)
|
||||
{
|
||||
// some bytes were written
|
||||
haveone = true;
|
||||
}
|
||||
|
||||
if (result <= 0)
|
||||
{
|
||||
if (m_PacketQueue.enqueue_head(pct) == -1)
|
||||
if (m_PacketQueue.enqueue_head (pct) == -1)
|
||||
{
|
||||
delete pct;
|
||||
sLog.outError ("WorldSocket::iFlushPacketQueue m_PacketQueue->enqueue_head");
|
||||
@@ -1068,7 +999,7 @@ bool WorldSocket::iFlushPacketQueue()
|
||||
}
|
||||
else
|
||||
{
|
||||
// packet completed
|
||||
haveone = true;
|
||||
delete pct;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,10 +175,6 @@ class WorldSocket : protected WorldHandler
|
||||
/// Need to be called with m_OutBufferLock lock held
|
||||
int iSendPacket (const WorldPacket& pct);
|
||||
|
||||
/// Try to write WorldPacket to m_OutBuffer even partially,
|
||||
/// Need to be called with m_OutBufferLock lock held
|
||||
int iSendPartialPacket(WorldPacket& pct);
|
||||
|
||||
/// Flush m_PacketQueue if there are packets in it
|
||||
/// Need to be called with m_OutBufferLock lock held
|
||||
/// @return true if it wrote to the buffer ( AKA you need
|
||||
|
||||
Reference in New Issue
Block a user