cleanup: use constant and add/use isUDP()

This commit is contained in:
Eric House 2013-08-07 21:31:10 -07:00
parent ae21b6f0d8
commit b49486fc3f
5 changed files with 13 additions and 10 deletions

View file

@ -29,6 +29,7 @@
class AddrInfo {
public:
typedef uint32_t ClientToken;
static const ClientToken NULL_TOKEN = 0;
class AddrUnion {
public:
@ -67,7 +68,8 @@ class AddrInfo {
}
void setIsTCP( bool val ) { m_isTCP = val; }
bool isTCP() const { return m_isTCP; } /* later UDP will be here too */
bool isTCP() const { return m_isTCP; }
bool isUDP() const { return !m_isTCP; }
int socket() const { assert(m_isValid); return m_socket; }
ClientToken clientToken() const { assert(m_isValid); return m_clientToken; }
struct in_addr sin_addr() const { return m_saddr.u.addr_in.sin_addr; }

View file

@ -203,7 +203,7 @@ CookieRef::_Connect( int clientVersion, DevID* devID,
}
if ( !connected ) {
bool socketOK = !addr->isTCP();
bool socketOK = addr->isUDP();
if ( !socketOK ) {
socketOK = true;
vector<AddrInfo> addrs = GetAddrs();
@ -917,7 +917,7 @@ CookieRef::increasePlayerCounts( CRefEvent* evt, bool reconn, HostID* hidp,
}
const AddrInfo* addr = &evt->addr;
if ( !!devIDp && !addr->isTCP() ) {
if ( !!devIDp && addr->isUDP() ) {
DevIDType devIDType = evt->u.con.devID->m_devIDType;
// does client support devID
if ( ID_TYPE_NONE != devIDType ) {

View file

@ -715,8 +715,7 @@ DBMgr::TokenFor( const char* const connName, int hid, DevIDRelay* devid,
if ( 1 == PQntuples( result ) ) {
AddrInfo::ClientToken token_tmp = atoi( PQgetvalue( result, 0, 0 ) );
DevIDRelay devid_tmp = atoi( PQgetvalue( result, 0, 1 ) );
if ( 0 != token_tmp // 0 is illegal (legacy/unset) value
&& 0 != devid_tmp ) {
if ( AddrInfo::NULL_TOKEN != token_tmp && 0 != devid_tmp ) {
*token = token_tmp;
*devid = devid_tmp;
found = true;
@ -724,7 +723,6 @@ DBMgr::TokenFor( const char* const connName, int hid, DevIDRelay* devid,
}
PQclear( result );
if ( found ) {
logf( XW_LOGINFO, "%s(%s,%d)=>true (%d, %d)", __func__, connName, hid,
*devid, *token );

View file

@ -104,6 +104,7 @@ UdpQueue::get()
bool
UdpQueue::handle( const AddrInfo* addr, QueueCallback cb )
{
assert( addr->isTCP() );
PartialPacket* packet;
bool success = true;

View file

@ -529,7 +529,7 @@ send_msg_via_udp( const AddrInfo* addr, AddrInfo::ClientToken clientToken,
const unsigned char* buf, const size_t bufLen,
uint32_t* packetIDP )
{
assert( 0 != clientToken );
assert( AddrInfo::NULL_TOKEN != clientToken );
uint32_t asNetTok = htonl(clientToken);
ssize_t nSent = send_via_udp( addr, packetIDP, XWPDEV_MSG, &asNetTok,
sizeof(asNetTok), buf, bufLen, NULL );
@ -1423,7 +1423,7 @@ handle_udp_packet( UdpThreadClosure* utc )
memcpy( &clientToken, ptr, sizeof(clientToken) );
ptr += sizeof(clientToken);
clientToken = ntohl( clientToken );
if ( 0 != clientToken ) {
if ( AddrInfo::NULL_TOKEN != clientToken ) {
AddrInfo addr( g_udpsock, clientToken, utc->saddr() );
(void)processMessage( ptr, end - ptr, &addr );
} else {
@ -1433,7 +1433,8 @@ handle_udp_packet( UdpThreadClosure* utc )
}
case XWPDEV_MSGNOCONN: {
AddrInfo::ClientToken clientToken;
if ( getNetLong( &ptr, end, &clientToken ) && 0 != clientToken ) {
if ( getNetLong( &ptr, end, &clientToken )
&& AddrInfo::NULL_TOKEN != clientToken ) {
HostID hid;
char connName[MAX_CONNNAME_LEN+1];
if ( !parseRelayID( &ptr, end, connName,
@ -1485,7 +1486,8 @@ handle_udp_packet( UdpThreadClosure* utc )
break;
}
AddrInfo::ClientToken clientToken;
if ( getNetLong( &ptr, end, &clientToken ) && 0 != clientToken ) {
if ( getNetLong( &ptr, end, &clientToken )
&& AddrInfo::NULL_TOKEN != clientToken ) {
unsigned short seed;
HostID hid;
string connName;