Fixed a very nasty bug concerning the sender thread. SOCKETs were assumed to be kind of unique, but Windows tends to return the socket number of a socket which was just closed as new socket number in accept. This led to very strange behavior when the server was flooded with inits, because the sender thread still had entries for this socket number (which were not removed because they should just fail).

No longer use socket as key in maps, instead, use the session id. Only use the session id in the sender thread, "resolve" it to the socket only in the moment when it is needed. Outstanding requests will be detected to have an invalid session id then.
Also, as side effect, fixed an issue with two callback classes which were named the same and caused unexpected behavior.
This commit is contained in:
lotodore
2007-10-28 12:53:54 +00:00
parent 2fa888062f
commit fa7af40a49
20 changed files with 223 additions and 166 deletions
+9 -8
View File
@@ -23,6 +23,7 @@
#include <core/thread.h>
#include <net/socket_helper.h>
#include <net/sessiondata.h>
#include <net/netpacket.h>
#include <net/sendercallback.h>
@@ -40,25 +41,25 @@ public:
SenderThread(SenderCallback &cb);
virtual ~SenderThread();
void Send(SOCKET sock, boost::shared_ptr<NetPacket> packet);
void Send(SOCKET sock, const NetPacketList &packetList);
void Send(SessionId session, boost::shared_ptr<NetPacket> packet);
void Send(SessionId session, const NetPacketList &packetList);
void SendLowPrio(SOCKET sock, boost::shared_ptr<NetPacket> packet);
void SendLowPrio(SOCKET sock, const NetPacketList &packetList);
void SendLowPrio(SessionId session, boost::shared_ptr<NetPacket> packet);
void SendLowPrio(SessionId session, const NetPacketList &packetList);
protected:
typedef std::pair<boost::shared_ptr<NetPacket>, SOCKET> SendData;
typedef std::pair<boost::shared_ptr<NetPacket>, SessionId> SendData;
typedef std::deque<SendData> SendDataDeque;
// Main function of the thread.
virtual void Main();
void InternalStore(SendDataDeque &sendQueue, unsigned maxQueueSize, SOCKET sock, boost::shared_ptr<NetPacket> packet);
void InternalStore(SendDataDeque &sendQueue, unsigned maxQueueSize, SOCKET sock, const NetPacketList &packetList);
void InternalStore(SendDataDeque &sendQueue, unsigned maxQueueSize, SessionId session, boost::shared_ptr<NetPacket> packet);
void InternalStore(SendDataDeque &sendQueue, unsigned maxQueueSize, SessionId session, const NetPacketList &packetList);
private:
SOCKET m_curSocket;
SessionId m_curSession;
std::deque<SendData> m_outBuf;
mutable boost::mutex m_outBufMutex;