From 38d77b3cbee831144dcfdb2b79c93bc6d494f7fe Mon Sep 17 00:00:00 2001 From: "Michael J. Pounders" Date: Sat, 22 Nov 2014 21:55:01 -0500 Subject: [PATCH] rework Sharedmemory_update() to not use memcpy (requested by fatbob) --- shm_utils/mon-umurmurd/CHANGES | 4 ++ shm_utils/mon-umurmurd/mon-umurmurd.c | 88 +++++++++++++++------------ src/sharedmemory.c | 50 ++++++++++----- src/sharedmemory_struct.h | 6 +- 4 files changed, 94 insertions(+), 54 deletions(-) diff --git a/shm_utils/mon-umurmurd/CHANGES b/shm_utils/mon-umurmurd/CHANGES index 2432255..8ba9821 100644 --- a/shm_utils/mon-umurmurd/CHANGES +++ b/shm_utils/mon-umurmurd/CHANGES @@ -1,3 +1,7 @@ +* Added more client data 99% of the useful client data shown +* removed memcpys (requested by fatbob) + + * Using a more modern unix sharedmemory API. this requires linking with librt.so (requested by fatbob) * Added away to know if umurmurd is not connected/updateing the shm_t struct. I use 8bit timer with rollover protection see check_serverTick() and where I use the function near bottum of mon-umurmurd.c diff --git a/shm_utils/mon-umurmurd/mon-umurmurd.c b/shm_utils/mon-umurmurd/mon-umurmurd.c index 7a1a5b2..2944599 100644 --- a/shm_utils/mon-umurmurd/mon-umurmurd.c +++ b/shm_utils/mon-umurmurd/mon-umurmurd.c @@ -21,9 +21,9 @@ int main(int argc, char **argv) while ( (opt = getopt(argc, argv, "w")) != -1 ) - { + { switch(opt) - { + { case 'w': wait = 1; break; @@ -84,8 +84,8 @@ int main(int argc, char **argv) uint8_t check_serverTick(void) { last = shmptr->alive; - sleep( 1 ); // Sleep for 1 sec - return(shmptr->alive - last); + sleep( 1 ); // Sleep for 1 sec + return(shmptr->alive - last); } void run_shm(void) @@ -93,49 +93,61 @@ void run_shm(void) int cc; - printf( "\033[2J\033[H" ); //clear screen VT100 + printf( "\033[2J\033[H" ); //clear screen VT100 - for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ ) + for( cc = 0 ; cc < shmptr->server_max_clients ; cc++ ) { if( !shmptr->client[cc].authenticated ) continue; - printf( "%s@%s:%i in channel: %s\n\ - \tOnline(secs): %lu Idle(secs): %lu\n\ - \tusingUDP=%i\n\ - \tdeaf=%i, mute=%i\n\ - \tself_deaf=%i, self_mute=%i\n\ - \trecording=%i\n\ - \tbOpus=%i\n\ - \tUDP_Avg/Var: %3.2f/%3.2f \n\ - \tTCP_Avg/Var: %3.2f/%3.2f \n\ - \tUDP_C/TCP_C: %lu/%lu\n", - shmptr->client[cc].username, - shmptr->client[cc].ipaddress, - shmptr->client[cc].udp_port, - shmptr->client[cc].channel, - shmptr->client[cc].online_secs, - shmptr->client[cc].idle_secs, + printf( "%s@%s:%i in channel: %s\n\ + \tclient_OS: %s %s\n\ + \tclient_info: %s\n\ + \tavailableBandwidth: %i\n\ + \tOnline(secs): %lu Idle(secs): %lu\n\ + \tusingUDP=%i\n\ + \tdeaf=%i, mute=%i\n\ + \tself_deaf=%i, self_mute=%i\n\ + \trecording=%i\n\ + \tbOpus=%i\n\ + \tisAdmin=%i\n\ + \tisSuppressed=%i\n\ + \tUDP_Avg/Var: %3.2f/%3.2f\n\ + \tTCP_Avg/Var: %3.2f/%3.2f\n\ + \tUDP_C/TCP_C: %lu/%lu\n", + shmptr->client[cc].username, + shmptr->client[cc].ipaddress, + shmptr->client[cc].udp_port, + shmptr->client[cc].channel, + shmptr->client[cc].os, + shmptr->client[cc].os_version, + shmptr->client[cc].release, + shmptr->client[cc].availableBandwidth, + shmptr->client[cc].online_secs, + shmptr->client[cc].idle_secs, - shmptr->client[cc].bUDP, - shmptr->client[cc].deaf, - shmptr->client[cc].mute, - shmptr->client[cc].self_deaf, - shmptr->client[cc].self_mute, - shmptr->client[cc].recording, - shmptr->client[cc].bOpus, + shmptr->client[cc].bUDP, + shmptr->client[cc].deaf, + shmptr->client[cc].mute, + shmptr->client[cc].self_deaf, + shmptr->client[cc].self_mute, + shmptr->client[cc].recording, + shmptr->client[cc].bOpus, + + shmptr->client[cc].isAdmin, + shmptr->client[cc].isSuppressed, - shmptr->client[cc].UDPPingAvg, - shmptr->client[cc].UDPPingVar, - shmptr->client[cc].TCPPingAvg, - shmptr->client[cc].TCPPingVar, - shmptr->client[cc].UDPPackets, - shmptr->client[cc].TCPPackets ); fflush(stdout); // fflush need because of sleep() call + shmptr->client[cc].UDPPingAvg, + shmptr->client[cc].UDPPingVar, + shmptr->client[cc].TCPPingAvg, + shmptr->client[cc].TCPPingVar, + shmptr->client[cc].UDPPackets, + shmptr->client[cc].TCPPackets ); fflush(stdout); // fflush need because of sleep() call } - if( !check_serverTick() ) + if( !check_serverTick() ) { - exit(EXIT_FAILURE); //You dont have to exit you could just report the fact that the data is not valid - } + exit(EXIT_FAILURE); //You dont have to exit you could just report the fact that the data is not valid + } } \ No newline at end of file diff --git a/src/sharedmemory.c b/src/sharedmemory.c index 6af3f75..46cdc45 100644 --- a/src/sharedmemory.c +++ b/src/sharedmemory.c @@ -4,13 +4,13 @@ void Sharedmemory_init(void) { - int bindport = getIntConf(BINDPORT); //MJP BUG commandline option for address and port dont work this way going to have + int bindport = getIntConf(BINDPORT); //MJP BUG commandline option for address and port dont work this way going to have int server_max_clients = getIntConf(MAX_CLIENTS); //to bring them across as prameters to Sharedmemory_init(void) int shmptr_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients); - sprintf( shm_file_name, "umurmurd:%i", bindport ); + sprintf( shm_file_name, "umurmurd:%i", bindport ); Log_info("SHM_FD: %s", shm_file_name ); @@ -29,14 +29,14 @@ if( ftruncate( shm_fd, shmptr_size ) == -1 ) shmptr = mmap(0, shmptr_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); if (shmptr == (void *) -1) - { + { fprintf(stderr, "mmap failed : %s\n", strerror(errno)); //MJP BUG make this Log_ calls once I get this working exit(1); } memset( shmptr, 0, shmptr_size ); - + shmptr->umurmurd_pid = getpid(); shmptr->server_max_clients = server_max_clients; } @@ -47,11 +47,7 @@ void Sharedmemory_update(void) uint64_t now; unsigned int cc = 0; client_t *client_itr = NULL; - static size_t bt_end = sizeof( bool_t ) * 8, //compute once - pa_end = sizeof( float ) * 4, - pc_end = sizeof( uint32_t ) * 2; - - + memset( &shmptr->client[0], 0, sizeof( shmclient_t ) * shmptr->server_max_clients ); shmptr->clientcount = Client_count(); @@ -66,16 +62,40 @@ void Sharedmemory_update(void) strncpy( shmptr->client[cc].username, client_itr->username, 120 ); strncpy( shmptr->client[cc].ipaddress, Util_clientAddressToString( client_itr ), 45 ); - shmptr->client[cc].tcp_port = Util_clientAddressToPortTCP( client_itr ); - shmptr->client[cc].udp_port = Util_clientAddressToPortUDP( client_itr ); strncpy( shmptr->client[cc].channel, channel->name, 120 ); + + strncpy( shmptr->client[cc].os, client_itr->os, 120 ); + strncpy( shmptr->client[cc].release, client_itr->release, 120 ); + strncpy( shmptr->client[cc].os_version, client_itr->os_version, 120 ); + + shmptr->client[cc].tcp_port = Util_clientAddressToPortTCP( client_itr ); + shmptr->client[cc].udp_port = Util_clientAddressToPortUDP( client_itr ); shmptr->client[cc].online_secs = ( now - client_itr->connectTime ) / 1000000LL; shmptr->client[cc].idle_secs = ( now - client_itr->idleTime ) / 1000000LL; - - memcpy( &shmptr->client[cc].bUDP, &client_itr->bUDP, bt_end ); - memcpy( &shmptr->client[cc].UDPPingAvg, &client_itr->UDPPingAvg, pa_end ); - memcpy( &shmptr->client[cc].UDPPackets, &client_itr->UDPPackets, pc_end ); + + shmptr->client[cc].bUDP = client_itr->bUDP; + shmptr->client[cc].deaf = client_itr->deaf; + shmptr->client[cc].mute = client_itr->mute; + shmptr->client[cc].bOpus = client_itr->bOpus; + shmptr->client[cc].self_deaf = client_itr->self_deaf; + shmptr->client[cc].self_mute = client_itr->self_mute; + shmptr->client[cc].recording = client_itr->recording; + shmptr->client[cc].authenticated = client_itr->authenticated; + + shmptr->client[cc].availableBandwidth = client_itr->availableBandwidth; + + shmptr->client[cc].UDPPingAvg = client_itr->UDPPingAvg; + shmptr->client[cc].UDPPingVar = client_itr->UDPPingVar; + shmptr->client[cc].TCPPingAvg = client_itr->TCPPingAvg; + shmptr->client[cc].TCPPingVar = client_itr->TCPPingVar; + + shmptr->client[cc].isAdmin = client_itr->isAdmin; + shmptr->client[cc].isSuppressed = client_itr->isSuppressed; + + shmptr->client[cc].UDPPackets = client_itr->UDPPackets; + shmptr->client[cc].TCPPackets = client_itr->TCPPackets; + } cc++; } diff --git a/src/sharedmemory_struct.h b/src/sharedmemory_struct.h index 61d6488..d1453fb 100644 --- a/src/sharedmemory_struct.h +++ b/src/sharedmemory_struct.h @@ -3,10 +3,14 @@ typedef struct char username[121]; char ipaddress[46]; - int tcp_port, udp_port; char channel[121]; + char os[121], release[121], os_version[121]; + int tcp_port, udp_port; bool_t bUDP, authenticated, deaf, mute, self_deaf, self_mute, recording, bOpus; + int availableBandwidth; uint32_t online_secs, idle_secs; + bool_t isAdmin; + bool_t isSuppressed; float UDPPingAvg, UDPPingVar, TCPPingAvg, TCPPingVar; uint32_t UDPPackets, TCPPackets; -- 2.30.2