mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
improve API: hide special numbers inside implementation
This commit is contained in:
parent
ab1ae7c9ad
commit
b5714e9d14
3 changed files with 17 additions and 8 deletions
|
@ -42,16 +42,21 @@ class AddrInfo {
|
|||
}
|
||||
|
||||
AddrInfo( int socket, const AddrUnion* saddr, bool isTCP ) {
|
||||
assert( -1 != socket );
|
||||
construct( socket, saddr, isTCP );
|
||||
}
|
||||
|
||||
AddrInfo( int socket, ClientToken clientToken, const AddrUnion* saddr ) {
|
||||
init( socket, clientToken, saddr );
|
||||
AddrInfo( const AddrUnion* saddr ) {
|
||||
init( -1, 0, saddr );
|
||||
}
|
||||
|
||||
void init( int socket, ClientToken clientToken, const AddrUnion* saddr ) {
|
||||
construct( socket, saddr, false );
|
||||
m_clientToken = clientToken;
|
||||
AddrInfo( ClientToken clientToken, const AddrUnion* saddr ) {
|
||||
init( -1, clientToken, saddr );
|
||||
}
|
||||
|
||||
AddrInfo( int socket, ClientToken clientToken, const AddrUnion* saddr ) {
|
||||
assert( -1 != socket );
|
||||
init( socket, clientToken, saddr );
|
||||
}
|
||||
|
||||
void setIsTCP( bool val ) { m_isTCP = val; }
|
||||
|
@ -68,6 +73,10 @@ class AddrInfo {
|
|||
|
||||
private:
|
||||
void construct( int socket, const AddrUnion* saddr, bool isTCP );
|
||||
void init( int socket, ClientToken clientToken, const AddrUnion* saddr ) {
|
||||
construct( socket, saddr, false );
|
||||
m_clientToken = clientToken;
|
||||
}
|
||||
|
||||
// AddrInfo& operator=(const AddrInfo&); // Prevent assignment
|
||||
int m_socket;
|
||||
|
|
|
@ -1176,7 +1176,7 @@ CookieRef::forward_or_store( const CRefEvent* evt )
|
|||
if ( DBMgr::Get()->TokenFor( ConnName(), dest, &devid, &token ) ) {
|
||||
const AddrInfo::AddrUnion* saddr = DevMgr::Get()->get( devid );
|
||||
if ( !!saddr ) {
|
||||
AddrInfo addr( -1, token, saddr );
|
||||
AddrInfo addr( token, saddr );
|
||||
postTellHaveMsgs( &addr );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1227,7 +1227,7 @@ registerDevice( const DevID* devID, const AddrInfo::AddrUnion* saddr )
|
|||
if ( dbMgr->updateDevice( relayID, true ) ) {
|
||||
int nMsgs = dbMgr->CountStoredMessages( relayID );
|
||||
if ( 0 < nMsgs ) {
|
||||
AddrInfo addr( -1, -1, saddr );
|
||||
AddrInfo addr( saddr );
|
||||
send_havemsgs( &addr );
|
||||
}
|
||||
} else {
|
||||
|
@ -1267,7 +1267,7 @@ retrieveMessages( DevID& devID, const AddrInfo::AddrUnion* saddr )
|
|||
size_t buflen = sizeof(buf);
|
||||
AddrInfo::ClientToken clientToken;
|
||||
if ( dbMgr->GetStoredMessage( *iter, buf, &buflen, &clientToken ) ) {
|
||||
AddrInfo addr( -1, clientToken, saddr );
|
||||
AddrInfo addr( clientToken, saddr );
|
||||
if ( ! send_with_length_unsafe( &addr, buf, buflen ) ) {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue