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:
+13
-4
@@ -26,17 +26,26 @@
|
||||
#include <string>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#define SESSION_ID_INIT 0
|
||||
#define INVALID_SESSION 0
|
||||
#define SESSION_ID_INIT INVALID_SESSION
|
||||
#define SESSION_ID_GENERIC 0xFFFFFFFF
|
||||
|
||||
typedef unsigned SessionId;
|
||||
/*struct SessionId
|
||||
{
|
||||
unsigned id;
|
||||
};*/
|
||||
|
||||
|
||||
class SessionData
|
||||
{
|
||||
public:
|
||||
enum State { Init, ReceivingAvatar, Established, Game };
|
||||
|
||||
SessionData(SOCKET sockfd, unsigned id);
|
||||
SessionData(SOCKET sockfd, SessionId id);
|
||||
~SessionData();
|
||||
|
||||
unsigned GetId() const;
|
||||
SessionId GetId() const;
|
||||
State GetState() const;
|
||||
void SetState(State state);
|
||||
|
||||
@@ -53,7 +62,7 @@ public:
|
||||
|
||||
private:
|
||||
SOCKET m_sockfd;
|
||||
const unsigned m_id;
|
||||
const SessionId m_id;
|
||||
State m_state;
|
||||
std::string m_clientAddr;
|
||||
ReceiveBuffer m_receiveBuffer;
|
||||
|
||||
Reference in New Issue
Block a user