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
+6 -4
View File
@@ -51,13 +51,15 @@ public:
void AddSession(boost::shared_ptr<SessionData> sessionData); // new Sessions without player data
void AddSession(SessionWrapper session);
void SetSessionPlayerData(SOCKET session, boost::shared_ptr<PlayerData> playerData);
void RemoveSession(SOCKET session);
void SetSessionPlayerData(SessionId session, boost::shared_ptr<PlayerData> playerData);
void RemoveSession(SessionId session);
SessionWrapper Select(unsigned timeoutMsec);
SessionWrapper GetSessionByPlayerName(const std::string playerName) const;
SessionWrapper GetSessionByUniquePlayerId(unsigned uniqueId) const;
bool GetSocketForSession(SessionId session, SOCKET &outSocket);
PlayerDataList GetPlayerDataList() const;
PlayerIdList GetPlayerIdList() const;
bool IsPlayerConnected(const std::string &playerName) const;
@@ -72,11 +74,11 @@ public:
unsigned GetRawSessionCount();
void SendToAllSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionData::State state);
void SendToAllButOneSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SOCKET except, SessionData::State state);
void SendToAllButOneSessions(SenderThread &sender, boost::shared_ptr<NetPacket> packet, SessionId except, SessionData::State state);
protected:
typedef std::map<SOCKET, SessionWrapper> SessionMap;
typedef std::map<SessionId, SessionWrapper> SessionMap;
private: