From 7403811408a9d629d05ec1db711a276e61c0e809 Mon Sep 17 00:00:00 2001 From: cyberium Date: Tue, 22 Mar 2016 16:23:03 +0000 Subject: [PATCH] Added Missing function --- src/game/Server/WorldSocket.cpp | 61 +++++++++++++++++++++++++++++++++ src/game/Server/WorldSocket.h | 3 ++ 2 files changed, 64 insertions(+) diff --git a/src/game/Server/WorldSocket.cpp b/src/game/Server/WorldSocket.cpp index c40273ff..df3beac3 100644 --- a/src/game/Server/WorldSocket.cpp +++ b/src/game/Server/WorldSocket.cpp @@ -331,6 +331,67 @@ int WorldSocket::handle_output(ACE_HANDLE) ACE_NOTREACHED(return 0); } +int WorldSocket::handle_output_queue(GuardType& g) +{ + if (msg_queue()->is_empty()) + return cancel_wakeup_output(g); + + ACE_Message_Block* mblk; + + if (msg_queue()->dequeue_head(mblk, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1) + { + sLog.outError("WorldSocket::handle_output_queue dequeue_head"); + return -1; + } + + const size_t send_len = mblk->length(); + +#ifdef MSG_NOSIGNAL + ssize_t n = peer().send(mblk->rd_ptr(), send_len, MSG_NOSIGNAL); +#else + ssize_t n = peer().send(mblk->rd_ptr(), send_len); +#endif // MSG_NOSIGNAL + + if (n == 0) + { + mblk->release(); + + return -1; + } + else if (n == -1) + { + if (errno == EWOULDBLOCK || errno == EAGAIN) + { + msg_queue()->enqueue_head(mblk, (ACE_Time_Value*)&ACE_Time_Value::zero); + return schedule_wakeup_output(g); + } + + mblk->release(); + return -1; + } + else if (n < (ssize_t)send_len) // now n > 0 + { + mblk->rd_ptr(static_cast(n)); + + if (msg_queue()->enqueue_head(mblk, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1) + { + sLog.outError("WorldSocket::handle_output_queue enqueue_head"); + mblk->release(); + return -1; + } + + return schedule_wakeup_output(g); + } + else // now n == send_len + { + mblk->release(); + + return msg_queue()->is_empty() ? cancel_wakeup_output(g) : ACE_Event_Handler::WRITE_MASK; + } + + ACE_NOTREACHED(return -1); +} + int WorldSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask) { // Critical section diff --git a/src/game/Server/WorldSocket.h b/src/game/Server/WorldSocket.h index a2c344df..805dfc61 100644 --- a/src/game/Server/WorldSocket.h +++ b/src/game/Server/WorldSocket.h @@ -147,6 +147,9 @@ class WorldSocket : protected WorldHandler /// Called when the socket can write. virtual int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE) override; + /// Drain the queue if its not empty. + int handle_output_queue(GuardType& g); + /// Called when connection is closed or error happens. virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);