mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +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 ) {
|
AddrInfo( int socket, const AddrUnion* saddr, bool isTCP ) {
|
||||||
|
assert( -1 != socket );
|
||||||
construct( socket, saddr, isTCP );
|
construct( socket, saddr, isTCP );
|
||||||
}
|
}
|
||||||
|
|
||||||
AddrInfo( int socket, ClientToken clientToken, const AddrUnion* saddr ) {
|
AddrInfo( const AddrUnion* saddr ) {
|
||||||
init( socket, clientToken, saddr );
|
init( -1, 0, saddr );
|
||||||
}
|
}
|
||||||
|
|
||||||
void init( int socket, ClientToken clientToken, const AddrUnion* saddr ) {
|
AddrInfo( ClientToken clientToken, const AddrUnion* saddr ) {
|
||||||
construct( socket, saddr, false );
|
init( -1, clientToken, saddr );
|
||||||
m_clientToken = clientToken;
|
}
|
||||||
|
|
||||||
|
AddrInfo( int socket, ClientToken clientToken, const AddrUnion* saddr ) {
|
||||||
|
assert( -1 != socket );
|
||||||
|
init( socket, clientToken, saddr );
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIsTCP( bool val ) { m_isTCP = val; }
|
void setIsTCP( bool val ) { m_isTCP = val; }
|
||||||
|
@ -68,6 +73,10 @@ class AddrInfo {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void construct( int socket, const AddrUnion* saddr, bool isTCP );
|
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
|
// AddrInfo& operator=(const AddrInfo&); // Prevent assignment
|
||||||
int m_socket;
|
int m_socket;
|
||||||
|
|
|
@ -1176,7 +1176,7 @@ CookieRef::forward_or_store( const CRefEvent* evt )
|
||||||
if ( DBMgr::Get()->TokenFor( ConnName(), dest, &devid, &token ) ) {
|
if ( DBMgr::Get()->TokenFor( ConnName(), dest, &devid, &token ) ) {
|
||||||
const AddrInfo::AddrUnion* saddr = DevMgr::Get()->get( devid );
|
const AddrInfo::AddrUnion* saddr = DevMgr::Get()->get( devid );
|
||||||
if ( !!saddr ) {
|
if ( !!saddr ) {
|
||||||
AddrInfo addr( -1, token, saddr );
|
AddrInfo addr( token, saddr );
|
||||||
postTellHaveMsgs( &addr );
|
postTellHaveMsgs( &addr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1227,7 +1227,7 @@ registerDevice( const DevID* devID, const AddrInfo::AddrUnion* saddr )
|
||||||
if ( dbMgr->updateDevice( relayID, true ) ) {
|
if ( dbMgr->updateDevice( relayID, true ) ) {
|
||||||
int nMsgs = dbMgr->CountStoredMessages( relayID );
|
int nMsgs = dbMgr->CountStoredMessages( relayID );
|
||||||
if ( 0 < nMsgs ) {
|
if ( 0 < nMsgs ) {
|
||||||
AddrInfo addr( -1, -1, saddr );
|
AddrInfo addr( saddr );
|
||||||
send_havemsgs( &addr );
|
send_havemsgs( &addr );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1267,7 +1267,7 @@ retrieveMessages( DevID& devID, const AddrInfo::AddrUnion* saddr )
|
||||||
size_t buflen = sizeof(buf);
|
size_t buflen = sizeof(buf);
|
||||||
AddrInfo::ClientToken clientToken;
|
AddrInfo::ClientToken clientToken;
|
||||||
if ( dbMgr->GetStoredMessage( *iter, buf, &buflen, &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 ) ) {
|
if ( ! send_with_length_unsafe( &addr, buf, buflen ) ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue