Reworked asio sender thread implementation. Optimized it for speed. Some cleanup still needed, but should work.

This commit is contained in:
lotodore
2009-01-31 21:03:34 +00:00
parent 7b853732b5
commit 3f8d3c8d55
2 changed files with 121 additions and 93 deletions
+5 -43
View File
@@ -30,6 +30,7 @@
#include <boost/shared_ptr.hpp>
class SessionData;
class SendDataManager;
#define SENDER_THREAD_TERMINATE_TIMEOUT THREAD_WAIT_INFINITE
class SenderThread : public Thread, public SenderInterface
@@ -48,50 +49,8 @@ public:
boost::shared_ptr<boost::asio::io_service> GetIOService();
protected:
typedef std::list<boost::shared_ptr<NetPacket> > SendDataList;
typedef std::list<unsigned> ChangedSessionList;
class SendDataManager
{
public:
SendDataManager(boost::shared_ptr<SessionData> s)
: session(s), m_writeInProgress(false), m_completed(false)
{
}
void HandleWrite(const boost::system::error_code& error);
bool IsWriteInProgress() const
{
boost::mutex::scoped_lock lock(m_mutex);
return m_writeInProgress;
}
void SetWriteInProgress(bool v)
{
boost::mutex::scoped_lock lock(m_mutex);
m_writeInProgress = v;
}
bool IsCompleted() const
{
boost::mutex::scoped_lock lock(m_mutex);
return m_completed;
}
void SetCompleted(bool v)
{
boost::mutex::scoped_lock lock(m_mutex);
m_completed = v;
}
boost::shared_ptr<SessionData> session;
SendDataList list;
private:
mutable boost::mutex m_mutex;
bool m_writeInProgress;
bool m_completed;
};
typedef std::map<SessionId, boost::shared_ptr<SendDataManager> > SendQueueMap;
// Main function of the thread.
@@ -102,6 +61,9 @@ private:
SendQueueMap m_sendQueueMap;
mutable boost::mutex m_sendQueueMapMutex;
ChangedSessionList m_changedSessions;
mutable boost::mutex m_changedSessionsMutex;
SenderCallback &m_callback;
boost::shared_ptr<boost::asio::io_service> m_ioService;