mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
cleanup: use constant and add/use isUDP()
This commit is contained in:
parent
ae21b6f0d8
commit
b49486fc3f
5 changed files with 13 additions and 10 deletions
|
@ -29,6 +29,7 @@
|
||||||
class AddrInfo {
|
class AddrInfo {
|
||||||
public:
|
public:
|
||||||
typedef uint32_t ClientToken;
|
typedef uint32_t ClientToken;
|
||||||
|
static const ClientToken NULL_TOKEN = 0;
|
||||||
|
|
||||||
class AddrUnion {
|
class AddrUnion {
|
||||||
public:
|
public:
|
||||||
|
@ -67,7 +68,8 @@ class AddrInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIsTCP( bool val ) { m_isTCP = val; }
|
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; }
|
int socket() const { assert(m_isValid); return m_socket; }
|
||||||
ClientToken clientToken() const { assert(m_isValid); return m_clientToken; }
|
ClientToken clientToken() const { assert(m_isValid); return m_clientToken; }
|
||||||
struct in_addr sin_addr() const { return m_saddr.u.addr_in.sin_addr; }
|
struct in_addr sin_addr() const { return m_saddr.u.addr_in.sin_addr; }
|
||||||
|
|
|
@ -203,7 +203,7 @@ CookieRef::_Connect( int clientVersion, DevID* devID,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !connected ) {
|
if ( !connected ) {
|
||||||
bool socketOK = !addr->isTCP();
|
bool socketOK = addr->isUDP();
|
||||||
if ( !socketOK ) {
|
if ( !socketOK ) {
|
||||||
socketOK = true;
|
socketOK = true;
|
||||||
vector<AddrInfo> addrs = GetAddrs();
|
vector<AddrInfo> addrs = GetAddrs();
|
||||||
|
@ -917,7 +917,7 @@ CookieRef::increasePlayerCounts( CRefEvent* evt, bool reconn, HostID* hidp,
|
||||||
}
|
}
|
||||||
|
|
||||||
const AddrInfo* addr = &evt->addr;
|
const AddrInfo* addr = &evt->addr;
|
||||||
if ( !!devIDp && !addr->isTCP() ) {
|
if ( !!devIDp && addr->isUDP() ) {
|
||||||
DevIDType devIDType = evt->u.con.devID->m_devIDType;
|
DevIDType devIDType = evt->u.con.devID->m_devIDType;
|
||||||
// does client support devID
|
// does client support devID
|
||||||
if ( ID_TYPE_NONE != devIDType ) {
|
if ( ID_TYPE_NONE != devIDType ) {
|
||||||
|
|
|
@ -715,8 +715,7 @@ DBMgr::TokenFor( const char* const connName, int hid, DevIDRelay* devid,
|
||||||
if ( 1 == PQntuples( result ) ) {
|
if ( 1 == PQntuples( result ) ) {
|
||||||
AddrInfo::ClientToken token_tmp = atoi( PQgetvalue( result, 0, 0 ) );
|
AddrInfo::ClientToken token_tmp = atoi( PQgetvalue( result, 0, 0 ) );
|
||||||
DevIDRelay devid_tmp = atoi( PQgetvalue( result, 0, 1 ) );
|
DevIDRelay devid_tmp = atoi( PQgetvalue( result, 0, 1 ) );
|
||||||
if ( 0 != token_tmp // 0 is illegal (legacy/unset) value
|
if ( AddrInfo::NULL_TOKEN != token_tmp && 0 != devid_tmp ) {
|
||||||
&& 0 != devid_tmp ) {
|
|
||||||
*token = token_tmp;
|
*token = token_tmp;
|
||||||
*devid = devid_tmp;
|
*devid = devid_tmp;
|
||||||
found = true;
|
found = true;
|
||||||
|
@ -724,7 +723,6 @@ DBMgr::TokenFor( const char* const connName, int hid, DevIDRelay* devid,
|
||||||
}
|
}
|
||||||
PQclear( result );
|
PQclear( result );
|
||||||
|
|
||||||
|
|
||||||
if ( found ) {
|
if ( found ) {
|
||||||
logf( XW_LOGINFO, "%s(%s,%d)=>true (%d, %d)", __func__, connName, hid,
|
logf( XW_LOGINFO, "%s(%s,%d)=>true (%d, %d)", __func__, connName, hid,
|
||||||
*devid, *token );
|
*devid, *token );
|
||||||
|
|
|
@ -104,6 +104,7 @@ UdpQueue::get()
|
||||||
bool
|
bool
|
||||||
UdpQueue::handle( const AddrInfo* addr, QueueCallback cb )
|
UdpQueue::handle( const AddrInfo* addr, QueueCallback cb )
|
||||||
{
|
{
|
||||||
|
assert( addr->isTCP() );
|
||||||
PartialPacket* packet;
|
PartialPacket* packet;
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
|
|
|
@ -529,7 +529,7 @@ send_msg_via_udp( const AddrInfo* addr, AddrInfo::ClientToken clientToken,
|
||||||
const unsigned char* buf, const size_t bufLen,
|
const unsigned char* buf, const size_t bufLen,
|
||||||
uint32_t* packetIDP )
|
uint32_t* packetIDP )
|
||||||
{
|
{
|
||||||
assert( 0 != clientToken );
|
assert( AddrInfo::NULL_TOKEN != clientToken );
|
||||||
uint32_t asNetTok = htonl(clientToken);
|
uint32_t asNetTok = htonl(clientToken);
|
||||||
ssize_t nSent = send_via_udp( addr, packetIDP, XWPDEV_MSG, &asNetTok,
|
ssize_t nSent = send_via_udp( addr, packetIDP, XWPDEV_MSG, &asNetTok,
|
||||||
sizeof(asNetTok), buf, bufLen, NULL );
|
sizeof(asNetTok), buf, bufLen, NULL );
|
||||||
|
@ -1423,7 +1423,7 @@ handle_udp_packet( UdpThreadClosure* utc )
|
||||||
memcpy( &clientToken, ptr, sizeof(clientToken) );
|
memcpy( &clientToken, ptr, sizeof(clientToken) );
|
||||||
ptr += sizeof(clientToken);
|
ptr += sizeof(clientToken);
|
||||||
clientToken = ntohl( clientToken );
|
clientToken = ntohl( clientToken );
|
||||||
if ( 0 != clientToken ) {
|
if ( AddrInfo::NULL_TOKEN != clientToken ) {
|
||||||
AddrInfo addr( g_udpsock, clientToken, utc->saddr() );
|
AddrInfo addr( g_udpsock, clientToken, utc->saddr() );
|
||||||
(void)processMessage( ptr, end - ptr, &addr );
|
(void)processMessage( ptr, end - ptr, &addr );
|
||||||
} else {
|
} else {
|
||||||
|
@ -1433,7 +1433,8 @@ handle_udp_packet( UdpThreadClosure* utc )
|
||||||
}
|
}
|
||||||
case XWPDEV_MSGNOCONN: {
|
case XWPDEV_MSGNOCONN: {
|
||||||
AddrInfo::ClientToken clientToken;
|
AddrInfo::ClientToken clientToken;
|
||||||
if ( getNetLong( &ptr, end, &clientToken ) && 0 != clientToken ) {
|
if ( getNetLong( &ptr, end, &clientToken )
|
||||||
|
&& AddrInfo::NULL_TOKEN != clientToken ) {
|
||||||
HostID hid;
|
HostID hid;
|
||||||
char connName[MAX_CONNNAME_LEN+1];
|
char connName[MAX_CONNNAME_LEN+1];
|
||||||
if ( !parseRelayID( &ptr, end, connName,
|
if ( !parseRelayID( &ptr, end, connName,
|
||||||
|
@ -1485,7 +1486,8 @@ handle_udp_packet( UdpThreadClosure* utc )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
AddrInfo::ClientToken clientToken;
|
AddrInfo::ClientToken clientToken;
|
||||||
if ( getNetLong( &ptr, end, &clientToken ) && 0 != clientToken ) {
|
if ( getNetLong( &ptr, end, &clientToken )
|
||||||
|
&& AddrInfo::NULL_TOKEN != clientToken ) {
|
||||||
unsigned short seed;
|
unsigned short seed;
|
||||||
HostID hid;
|
HostID hid;
|
||||||
string connName;
|
string connName;
|
||||||
|
|
Loading…
Add table
Reference in a new issue