mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
reorganize; support ctrl functions
This commit is contained in:
parent
d885af5386
commit
df17fe4f1e
1 changed files with 45 additions and 8 deletions
|
@ -25,22 +25,35 @@ class CookieRef {
|
||||||
If the hostID is HOST_ID_SERVER, it's the server. */
|
If the hostID is HOST_ID_SERVER, it's the server. */
|
||||||
void Associate( int socket, HostID srcID );
|
void Associate( int socket, HostID srcID );
|
||||||
short GetHeartbeat() { return 60; }
|
short GetHeartbeat() { return 60; }
|
||||||
short GetConnID() { return m_connectionID; }
|
CookieID GetCookieID() { return m_connectionID; }
|
||||||
int SocketForHost( HostID dest );
|
int SocketForHost( HostID dest );
|
||||||
void Remove( int socket );
|
void Remove( int socket );
|
||||||
int CountSockets() { return m_hostSockets.size(); }
|
int CountSockets() { return m_hostSockets.size(); }
|
||||||
string Name() { return m_name; }
|
string Name() { return m_name; }
|
||||||
|
|
||||||
static CookieMapIterator GetCookieNameIterator();
|
void RecordSent( int nBytes, int socket ) {
|
||||||
|
/* This really needs a lock.... */
|
||||||
|
m_totalSent += nBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* for console */
|
||||||
|
void PrintCookieInfo( string& out );
|
||||||
|
void PrintSocketInfo( string& out, int socket );
|
||||||
|
|
||||||
|
static CookieMapIterator GetCookieIterator();
|
||||||
static CookieRef* AddNew( string s );
|
static CookieRef* AddNew( string s );
|
||||||
|
/* Nuke an existing */
|
||||||
|
static void Delete( CookieID id );
|
||||||
|
static void Delete( const char* name );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CookieRef( string s );
|
CookieRef( string s );
|
||||||
|
|
||||||
map<HostID,int> m_hostSockets;
|
map<HostID,int> m_hostSockets;
|
||||||
pthread_mutex_t m_mutex;
|
pthread_rwlock_t m_sockets_rwlock;
|
||||||
CookieID m_connectionID;
|
CookieID m_connectionID;
|
||||||
string m_name;
|
string m_name;
|
||||||
|
int m_totalSent;
|
||||||
|
|
||||||
static CookieID ms_nextConnectionID;
|
static CookieID ms_nextConnectionID;
|
||||||
};
|
};
|
||||||
|
@ -51,15 +64,39 @@ class CookieMapIterator {
|
||||||
public:
|
public:
|
||||||
CookieMapIterator();
|
CookieMapIterator();
|
||||||
~CookieMapIterator() {}
|
~CookieMapIterator() {}
|
||||||
const char* Next();
|
CookieID Next();
|
||||||
private:
|
private:
|
||||||
CookieMap::const_iterator _iter;
|
CookieMap::const_iterator _iter;
|
||||||
};
|
};
|
||||||
|
|
||||||
CookieRef* get_make_cookieRef( char* cookie, CookieID connID );
|
CookieRef* get_make_cookieRef( const char* cookie, CookieID connID );
|
||||||
CookieRef* get_cookieRef( unsigned short cookieID );
|
CookieRef* get_cookieRef( unsigned short cookieID );
|
||||||
void Associate( int socket, CookieRef* cref );
|
CookieID CookieIdForName( const char* name );
|
||||||
void RemoveSocketRefs( int socket );
|
|
||||||
pthread_mutex_t* GetWriteMutexForSocket( int socket );
|
class SocketStuff;
|
||||||
|
typedef map< int, SocketStuff* > SocketMap;
|
||||||
|
|
||||||
|
class SocketsIterator {
|
||||||
|
public:
|
||||||
|
SocketsIterator( SocketMap::iterator iter );
|
||||||
|
int Next();
|
||||||
|
private:
|
||||||
|
SocketMap::iterator m_iter;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SocketMgr {
|
||||||
|
public:
|
||||||
|
static void Associate( int socket, CookieRef* cref );
|
||||||
|
static pthread_mutex_t* GetWriteMutexForSocket( int socket );
|
||||||
|
static void RemoveSocketRefs( int socket );
|
||||||
|
static void PrintSocketInfo( int socket, string& out );
|
||||||
|
static SocketsIterator MakeSocketsIterator();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static CookieRef* CookieRefForSocket( int socket );
|
||||||
|
static SocketMap ms_SocketStuff;
|
||||||
|
static pthread_mutex_t ms_SocketStuffMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue