mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +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. */
|
||||
void Associate( int socket, HostID srcID );
|
||||
short GetHeartbeat() { return 60; }
|
||||
short GetConnID() { return m_connectionID; }
|
||||
CookieID GetCookieID() { return m_connectionID; }
|
||||
int SocketForHost( HostID dest );
|
||||
void Remove( int socket );
|
||||
int CountSockets() { return m_hostSockets.size(); }
|
||||
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 );
|
||||
/* Nuke an existing */
|
||||
static void Delete( CookieID id );
|
||||
static void Delete( const char* name );
|
||||
|
||||
private:
|
||||
CookieRef( string s );
|
||||
|
||||
map<HostID,int> m_hostSockets;
|
||||
pthread_mutex_t m_mutex;
|
||||
pthread_rwlock_t m_sockets_rwlock;
|
||||
CookieID m_connectionID;
|
||||
string m_name;
|
||||
int m_totalSent;
|
||||
|
||||
static CookieID ms_nextConnectionID;
|
||||
};
|
||||
|
@ -51,15 +64,39 @@ class CookieMapIterator {
|
|||
public:
|
||||
CookieMapIterator();
|
||||
~CookieMapIterator() {}
|
||||
const char* Next();
|
||||
CookieID Next();
|
||||
private:
|
||||
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 );
|
||||
void Associate( int socket, CookieRef* cref );
|
||||
void RemoveSocketRefs( int socket );
|
||||
pthread_mutex_t* GetWriteMutexForSocket( int socket );
|
||||
CookieID CookieIdForName( const char* name );
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue