aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaz Brown <iamparadox@netscape.net>2009-09-27 17:28:57 -0400
committerChaz Brown <iamparadox@netscape.net>2009-09-27 17:28:57 -0400
commitf9a9bbed7b4678cd9f09212e2ff56ffd49c1e101 (patch)
tree5a81b5a4867e93fb40bd8f5864d2f6e2987ad999
parenta635bdd0ccdf77c56c45ee1a6d456b3a2ef43ff3 (diff)
Backed out changeset 5da05b39c3eb
Causes crashes on Linux. --HG-- branch : trunk
-rw-r--r--src/game/WorldSocket.cpp87
-rw-r--r--src/game/WorldSocket.h4
2 files changed, 9 insertions, 82 deletions
diff --git a/src/game/WorldSocket.cpp b/src/game/WorldSocket.cpp
index d1cf5f91822..1b63ec01421 100644
--- a/src/game/WorldSocket.cpp
+++ b/src/game/WorldSocket.cpp
@@ -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)
- {
- // some bytes were written
- haveone = true;
- }
-
- if (result <= 0)
+ if (iSendPacket (*pct) == -1)
{
- 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;
}
}
diff --git a/src/game/WorldSocket.h b/src/game/WorldSocket.h
index 9b012ee23d3..94f57d8d636 100644
--- a/src/game/WorldSocket.h
+++ b/src/game/WorldSocket.h
@@ -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