mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
Toward resurrecting ctrl feature to give runtime info about stuff that
isn't in the DB. Step one: comment out the stuff that doesn't compile and add ability to print all registered devices with their ages.
This commit is contained in:
parent
06f0b7e411
commit
62f0819a82
6 changed files with 78 additions and 22 deletions
|
@ -19,22 +19,23 @@
|
||||||
CXX = g++
|
CXX = g++
|
||||||
CC=$(CXX)
|
CC=$(CXX)
|
||||||
SRC = \
|
SRC = \
|
||||||
|
addrinfo.cpp \
|
||||||
|
cidlock.cpp \
|
||||||
configs.cpp \
|
configs.cpp \
|
||||||
cref.cpp \
|
cref.cpp \
|
||||||
crefmgr.cpp \
|
crefmgr.cpp \
|
||||||
|
ctrl.cpp \
|
||||||
dbmgr.cpp \
|
dbmgr.cpp \
|
||||||
|
devmgr.cpp \
|
||||||
http.cpp \
|
http.cpp \
|
||||||
lstnrmgr.cpp \
|
lstnrmgr.cpp \
|
||||||
permid.cpp \
|
permid.cpp \
|
||||||
states.cpp \
|
states.cpp \
|
||||||
timermgr.cpp \
|
timermgr.cpp \
|
||||||
tpool.cpp \
|
tpool.cpp \
|
||||||
cidlock.cpp \
|
|
||||||
addrinfo.cpp \
|
|
||||||
devmgr.cpp \
|
|
||||||
udpqueue.cpp \
|
|
||||||
udpack.cpp \
|
udpack.cpp \
|
||||||
udpager.cpp \
|
udpager.cpp \
|
||||||
|
udpqueue.cpp \
|
||||||
xwrelay.cpp \
|
xwrelay.cpp \
|
||||||
|
|
||||||
# STATIC ?= -static
|
# STATIC ?= -static
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "configs.h"
|
#include "configs.h"
|
||||||
#include "lstnrmgr.h"
|
#include "lstnrmgr.h"
|
||||||
#include "tpool.h"
|
#include "tpool.h"
|
||||||
|
#include "devmgr.h"
|
||||||
|
|
||||||
#define MAX_ARGS 10
|
#define MAX_ARGS 10
|
||||||
|
|
||||||
|
@ -67,11 +68,11 @@ pthread_mutex_t g_ctrlSocksMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static bool cmd_quit( int socket, const char** args );
|
static bool cmd_quit( int socket, const char** args );
|
||||||
static bool cmd_print( int socket, const char** args );
|
static bool cmd_print( int socket, const char** args );
|
||||||
static bool cmd_lock( int socket, const char** args );
|
/* static bool cmd_lock( int socket, const char** args ); */
|
||||||
static bool cmd_help( int socket, const char** args );
|
static bool cmd_help( int socket, const char** args );
|
||||||
static bool cmd_start( int socket, const char** args );
|
static bool cmd_start( int socket, const char** args );
|
||||||
static bool cmd_stop( int socket, const char** args );
|
static bool cmd_stop( int socket, const char** args );
|
||||||
static bool cmd_kill_eject( int socket, const char** args );
|
/* static bool cmd_kill_eject( int socket, const char** args ); */
|
||||||
static bool cmd_get( int socket, const char** args );
|
static bool cmd_get( int socket, const char** args );
|
||||||
static bool cmd_set( int socket, const char** args );
|
static bool cmd_set( int socket, const char** args );
|
||||||
static bool cmd_shutdown( int socket, const char** args );
|
static bool cmd_shutdown( int socket, const char** args );
|
||||||
|
@ -123,11 +124,11 @@ print_to_sock( int sock, bool addCR, const char* what, ... )
|
||||||
static const FuncRec gFuncs[] = {
|
static const FuncRec gFuncs[] = {
|
||||||
{ "?", cmd_help },
|
{ "?", cmd_help },
|
||||||
{ "crash", cmd_crash },
|
{ "crash", cmd_crash },
|
||||||
{ "eject", cmd_kill_eject },
|
/* { "eject", cmd_kill_eject }, */
|
||||||
{ "get", cmd_get },
|
{ "get", cmd_get },
|
||||||
{ "help", cmd_help },
|
{ "help", cmd_help },
|
||||||
{ "kill", cmd_kill_eject },
|
/* { "kill", cmd_kill_eject }, */
|
||||||
{ "lock", cmd_lock },
|
/* { "lock", cmd_lock }, */
|
||||||
{ "print", cmd_print },
|
{ "print", cmd_print },
|
||||||
{ "quit", cmd_quit },
|
{ "quit", cmd_quit },
|
||||||
{ "rev", cmd_rev },
|
{ "rev", cmd_rev },
|
||||||
|
@ -182,6 +183,7 @@ cmd_stop( int socket, const char** args )
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static bool
|
static bool
|
||||||
cmd_kill_eject( int socket, const char** args )
|
cmd_kill_eject( int socket, const char** args )
|
||||||
{
|
{
|
||||||
|
@ -226,6 +228,7 @@ cmd_kill_eject( int socket, const char** args )
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} /* cmd_kill_eject */
|
} /* cmd_kill_eject */
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
cmd_get( int socket, const char** args )
|
cmd_get( int socket, const char** args )
|
||||||
|
@ -441,6 +444,7 @@ print_cookies( int socket, const char* cookie, const char* connName )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static void
|
static void
|
||||||
print_socket_info( int out, int which )
|
print_socket_info( int out, int which )
|
||||||
{
|
{
|
||||||
|
@ -448,17 +452,18 @@ print_socket_info( int out, int which )
|
||||||
CRefMgr::Get()->PrintSocketInfo( which, s );
|
CRefMgr::Get()->PrintSocketInfo( which, s );
|
||||||
print_to_sock( out, 1, s.c_str() );
|
print_to_sock( out, 1, s.c_str() );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_sockets( int out, int sought )
|
print_sockets( int out, int sought )
|
||||||
{
|
{
|
||||||
SocketsIterator iter = CRefMgr::Get()->MakeSocketsIterator();
|
/* SocketsIterator iter = CRefMgr::Get()->MakeSocketsIterator(); */
|
||||||
int sock;
|
/* int sock; */
|
||||||
while ( (sock = iter.Next()) != 0 ) {
|
/* while ( (sock = iter.Next()) != 0 ) { */
|
||||||
if ( sought == 0 || sought == sock ) {
|
/* if ( sought == 0 || sought == sock ) { */
|
||||||
print_socket_info( out, sock );
|
/* print_socket_info( out, sock ); */
|
||||||
}
|
/* } */
|
||||||
}
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -488,6 +493,13 @@ cmd_print( int socket, const char** args )
|
||||||
print_sockets( socket, atoi(args[3]) );
|
print_sockets( socket, atoi(args[3]) );
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
} else if ( 0 == strcmp( "dev", args[1] ) ) {
|
||||||
|
if ( 0 == strcmp( "all", args[2] ) ) {
|
||||||
|
string str;
|
||||||
|
DevMgr::Get()->printDevices( str );
|
||||||
|
print_to_sock( socket, true, str.c_str() );
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !found ) {
|
if ( !found ) {
|
||||||
|
@ -496,14 +508,16 @@ cmd_print( int socket, const char** args )
|
||||||
" %s cref name <name>\n"
|
" %s cref name <name>\n"
|
||||||
" %s cref connName <name>\n"
|
" %s cref connName <name>\n"
|
||||||
" %s cref id <id>\n"
|
" %s cref id <id>\n"
|
||||||
|
" %s dev all -- list all known devices (by how recently connected)\n"
|
||||||
" %s socket all\n"
|
" %s socket all\n"
|
||||||
" %s socket <num> -- print info about crefs and sockets";
|
" %s socket <num> -- print info about crefs and sockets";
|
||||||
print_to_sock( socket, true, str,
|
print_to_sock( socket, true, str, args[0], args[0], args[0],
|
||||||
args[0], args[0], args[0], args[0], args[0], args[0] );
|
args[0], args[0], args[0], args[0] );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} /* cmd_print */
|
} /* cmd_print */
|
||||||
|
|
||||||
|
#if 0
|
||||||
static bool
|
static bool
|
||||||
cmd_lock( int socket, const char** args )
|
cmd_lock( int socket, const char** args )
|
||||||
{
|
{
|
||||||
|
@ -519,6 +533,7 @@ cmd_lock( int socket, const char** args )
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} /* cmd_lock */
|
} /* cmd_lock */
|
||||||
|
#endif
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
cmd_help( int socket, const char** args )
|
cmd_help( int socket, const char** args )
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "devmgr.h"
|
#include "devmgr.h"
|
||||||
#include "mlock.h"
|
#include "mlock.h"
|
||||||
|
@ -60,6 +61,7 @@ DevMgr::Remember( DevIDRelay devid, const AddrInfo::AddrUnion* saddr )
|
||||||
result.first->second = rec;
|
result.first->second = rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't think we need m_addrDevMap anymore
|
||||||
map<AddrInfo::AddrUnion, DevIDRelay>::iterator iter =
|
map<AddrInfo::AddrUnion, DevIDRelay>::iterator iter =
|
||||||
m_addrDevMap.find(*saddr);
|
m_addrDevMap.find(*saddr);
|
||||||
if ( m_addrDevMap.end() != iter && devid != iter->second ) {
|
if ( m_addrDevMap.end() != iter && devid != iter->second ) {
|
||||||
|
@ -100,3 +102,40 @@ DevMgr::get( DevIDRelay devid )
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print info about every device, ordered by how old they are (how long since
|
||||||
|
// last remembered). Build a separate array with the mutex held, then release
|
||||||
|
// it, so that as much work as possible is done on the calling thread without
|
||||||
|
// holding up more important stuff.
|
||||||
|
void
|
||||||
|
DevMgr::printDevices( string& str )
|
||||||
|
{
|
||||||
|
map<uint32_t, DevIDRelay> agedDevs;
|
||||||
|
{
|
||||||
|
MutexLock ml( &m_mapLock );
|
||||||
|
map<DevIDRelay,UDPAddrRec>::const_iterator iter;
|
||||||
|
for ( iter = m_devAddrMap.begin(); iter != m_devAddrMap.end(); ++iter ) {
|
||||||
|
DevIDRelay devid = iter->first;
|
||||||
|
uint32_t added = iter->second.m_added;
|
||||||
|
agedDevs.insert( pair<uint32_t, DevIDRelay>(added, devid) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now sort by age and print
|
||||||
|
vector<uint32_t> keys;
|
||||||
|
map<uint32_t, DevIDRelay>::const_iterator iter1;
|
||||||
|
for ( iter1 = agedDevs.begin(); agedDevs.end() != iter1; ++iter1 ) {
|
||||||
|
keys.push_back( iter1->first );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort( keys.begin(), keys.end() );
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
vector<uint32_t>::const_iterator keysIter;
|
||||||
|
for ( keysIter = keys.begin(); keys.end() != keysIter; ++keysIter ) {
|
||||||
|
uint32_t age = *keysIter;
|
||||||
|
DevIDRelay devid = agedDevs.find( age )->second;
|
||||||
|
age = now - age;
|
||||||
|
string_printf( str, "devid: %d; age: %d seconds\n", devid, age );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@ class DevMgr {
|
||||||
void Remember( DevIDRelay devid, const AddrInfo* addr );
|
void Remember( DevIDRelay devid, const AddrInfo* addr );
|
||||||
const AddrInfo::AddrUnion* get( DevIDRelay devid );
|
const AddrInfo::AddrUnion* get( DevIDRelay devid );
|
||||||
|
|
||||||
|
void printDevices( string& str );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DevMgr() { pthread_mutex_init( &m_mapLock, NULL ); }
|
DevMgr() { pthread_mutex_init( &m_mapLock, NULL ); }
|
||||||
/* destructor's never called....
|
/* destructor's never called....
|
||||||
|
|
|
@ -1537,7 +1537,7 @@ read_udp_packet( int udpsock )
|
||||||
|
|
||||||
/* From stack overflow, toward a snprintf with an expanding buffer.
|
/* From stack overflow, toward a snprintf with an expanding buffer.
|
||||||
*/
|
*/
|
||||||
void
|
string&
|
||||||
string_printf( string& str, const char* fmt, ... )
|
string_printf( string& str, const char* fmt, ... )
|
||||||
{
|
{
|
||||||
const int origsiz = str.size();
|
const int origsiz = str.size();
|
||||||
|
@ -2042,8 +2042,7 @@ main( int argc, char** argv )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( FD_ISSET( g_control, &rfds ) ) {
|
if ( FD_ISSET( g_control, &rfds ) ) {
|
||||||
assert(0); // not working; don't use until fixed
|
run_ctrl_thread( g_control );
|
||||||
// run_ctrl_thread( g_control );
|
|
||||||
--retval;
|
--retval;
|
||||||
}
|
}
|
||||||
if ( -1 != g_udpsock && FD_ISSET( g_udpsock, &rfds ) ) {
|
if ( -1 != g_udpsock && FD_ISSET( g_udpsock, &rfds ) ) {
|
||||||
|
|
|
@ -58,7 +58,7 @@ int GetNSpawns(void);
|
||||||
|
|
||||||
int make_socket( unsigned long addr, unsigned short port );
|
int make_socket( unsigned long addr, unsigned short port );
|
||||||
|
|
||||||
void string_printf( std::string& str, const char* fmt, ... );
|
std::string& string_printf( std::string& str, const char* fmt, ... );
|
||||||
|
|
||||||
int read_packet( int sock, unsigned char* buf, int buflen );
|
int read_packet( int sock, unsigned char* buf, int buflen );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue