New boost::asio based sender thread. Does not work on windows yet, because the completion routine is never called. No idea why not.

This commit is contained in:
lotodore
2009-01-25 20:19:09 +00:00
parent cb3f0856c1
commit 17377f5a6b
5 changed files with 116 additions and 157 deletions
+52 -7
View File
@@ -28,6 +28,7 @@
#include <list>
#include <boost/shared_ptr.hpp>
#include <boost/asio.hpp>
class SessionData;
#define SENDER_THREAD_TERMINATE_TIMEOUT THREAD_WAIT_INFINITE
@@ -48,19 +49,63 @@ public:
protected:
typedef std::list<boost::shared_ptr<NetPacket> > SendDataList;
class SendDataManager
{
public:
SendDataManager(boost::shared_ptr<SessionData> s, boost::asio::io_service &ioService)
: session(s), m_writeInProgress(false), m_completed(false)
{
socket.reset(new boost::asio::ip::tcp::socket(
ioService, boost::asio::ip::tcp::v6(), s->GetSocket()));
}
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;
boost::shared_ptr<boost::asio::ip::tcp::socket> socket;
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.
virtual void Main();
private:
SendDataList m_sendQueue;
mutable boost::mutex m_sendQueueMutex;
boost::asio::io_service m_ioService;
SendQueueMap m_sendQueueMap;
mutable boost::mutex m_sendQueueMapMutex;
mutable boost::mutex m_sessionDataMutex;
SOCKET m_sessionSocket;
unsigned m_sessionId;
boost::shared_ptr<NetPacket> m_curPacket;
unsigned m_bytesSent;
SenderCallback &m_callback;
};