diff --git a/xwords4/relay/Makefile b/xwords4/relay/Makefile index d465f3b65..06d8a8c73 100644 --- a/xwords4/relay/Makefile +++ b/xwords4/relay/Makefile @@ -45,6 +45,7 @@ OBJ = $(patsubst %.cpp,%.o,$(SRC)) LDFLAGS += -pthread -g $(STATIC) LDFLAGS += -L$(shell pg_config --libdir) LDFLAGS += $(shell pkg-config --libs glib-2.0) +LDFLAGS += -lrt CPPFLAGS += -DSPAWN_SELF -g -Wall CPPFLAGS += -I $(shell pg_config --includedir) diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index c5fd9805e..106d5f57c 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -857,21 +857,19 @@ void CookieRef::send_stored_messages( HostID dest, const AddrInfo* addr ) { logf( XW_LOGVERBOSE0, "%s(dest=%d)", __func__, dest ); - assert( dest > 0 && dest <= 4 ); - if ( addr->isCurrent() ) { - DBMgr* dbmgr = DBMgr::Get(); - const char* cname = ConnName(); - for ( ; ; ) { - unsigned char buf[MAX_MSG_LEN]; - size_t buflen = sizeof(buf); - int msgID; - if ( !dbmgr->GetStoredMessage( cname, dest, buf, &buflen, &msgID ) - || ! send_with_length( addr, dest, buf, buflen, true ) ) { - break; - } - dbmgr->RemoveStoredMessages( &msgID, 1 ); - } + + DBMgr* dbmgr = DBMgr::Get(); + const char* cname = ConnName(); + while ( addr->isCurrent() ) { + unsigned char buf[MAX_MSG_LEN]; + size_t buflen = sizeof(buf); + int msgID; + if ( !dbmgr->GetStoredMessage( cname, dest, buf, &buflen, &msgID ) + || ! send_with_length( addr, dest, buf, buflen, true ) ) { + break; + } + dbmgr->RemoveStoredMessages( &msgID, 1 ); } } /* send_stored_messages */ diff --git a/xwords4/relay/dbmgr.cpp b/xwords4/relay/dbmgr.cpp index ae080075d..2eafc4517 100644 --- a/xwords4/relay/dbmgr.cpp +++ b/xwords4/relay/dbmgr.cpp @@ -65,6 +65,7 @@ DBMgr::DBMgr() int tmp; RelayConfigs::GetConfigs()->GetValueFor( "USE_B64", &tmp ); m_useB64 = tmp != 0; + logf( XW_LOGINFO, "%s: m_useB64=%d", __func__, m_useB64 ); pthread_key_create( &m_conn_key, destr_function ); @@ -1099,7 +1100,6 @@ DBMgr::getCountWhere( const char* table, string& test ) assert( 1 == PQntuples( result ) ); int count = atoi( PQgetvalue( result, 0, 0 ) ); PQclear( result ); - logf( XW_LOGINFO, "%s(%s)=>%d", __func__, query.c_str(), count ); return count; } diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index d6572102c..b7993707d 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -203,13 +203,24 @@ parseRelayID( const unsigned char** const inp, const unsigned char* const end, if ( ok ) { strncpy( buf, (char*)*inp, connNameLen ); buf[connNameLen] = '\0'; - *hid = atoi( hidp+1 ); char* endptr; *hid = strtol( hidp + 1, &endptr, 10 ); - if ( '\n' == *endptr ) { - ++endptr; - } - *inp = (unsigned char*)endptr; + + if ( *hid >= 0 && *hid <= 4 ) { + if ( '\n' == *endptr ) { + ++endptr; + } + *inp = (unsigned char*)endptr; + } else { + ok = false; + + int len = end - *inp; + char buf[len+1]; + memcpy( buf, *inp, len); + buf[len] = '\0'; + logf( XW_LOGERROR, "%s: got bad hid %d from str \"%s\"", __func__, + *hid, buf ); + } } if ( !ok ) { logf( XW_LOGERROR, "%s failed", __func__ );