--- /dev/null
+#include "sharedmemory.h"\r
+\r
+void Sharedmemory_init(void) \r
+{\r
+\r
+ key_t key = 0x53021d79;\r
+ int server_max_clients = getIntConf(MAX_CLIENTS); \r
+ int shmptr_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients);\r
+ \r
+ //key = ftok( ".", 'S' ); //MJP BUG this needs fixing.. also how to handle multi copys of umurmur bound to diff ports or IPs option to pass key on cmdline? \r
+ shmid = shmget( key, shmptr_size, IPC_CREAT | 0666 ); \r
+\r
+ Log_info("SHM_KEY: 0x%x", key );\r
+\r
+ if( ( shmptr = ( shm_t *) shmat( shmid, 0, 0 ) ) == (shm_t *) (-1) )\r
+ {\r
+ perror("shmat");\r
+ exit(1); //MJP BUG should report error and just not use shm dont exit\r
+ }\r
+ memset( shmptr, 0, shmptr_size ); \r
+ shmptr->umurmurd_pid = getpid();\r
+ shmptr->server_max_clients = server_max_clients; \r
+}\r
+\r
+void Sharedmemory_update(void) \r
+{\r
+\r
+ static size_t bt_end = sizeof( bool_t ) * 8, //compute once\r
+ et_end = sizeof( etimer_t ) * 3,\r
+ pa_end = sizeof( float ) * 4,\r
+ pc_end = sizeof( uint32_t ) * 2;\r
+ \r
+ unsigned int cc = 0;\r
+ client_t *client_itr = NULL;\r
+ \r
+ memset( &shmptr->client[0], 0, sizeof( shmclient_t ) * shmptr->server_max_clients );\r
+ shmptr->clientcount = Client_count();\r
+ \r
+ \r
+ \r
+ while( Client_iterate(&client_itr) != NULL ) {\r
+ \r
+\r
+ \r
+ if( client_itr->authenticated )\r
+ {\r
+ \r
+ channel_t *channel = client_itr->channel;\r
+ \r
+ strncpy( shmptr->client[cc].username, client_itr->username, 120 );\r
+ strncpy( shmptr->client[cc].ipaddress, Util_clientAddressToString( client_itr ) , 45 );\r
+ shmptr->client[cc].tcp_port = Util_clientAddressToPortTCP( client_itr );\r
+ shmptr->client[cc].udp_port = Util_clientAddressToPortUDP( client_itr );\r
+ strncpy( shmptr->client[cc].channel, channel->name, 120 );\r
+ memcpy( &shmptr->client[cc].bUDP, &client_itr->bUDP, bt_end );\r
+ memcpy( &shmptr->client[cc].lastActivity, &client_itr->lastActivity, et_end );\r
+ memcpy( &shmptr->client[cc].UDPPingAvg, &client_itr->UDPPingAvg, pa_end );\r
+ memcpy( &shmptr->client[cc].UDPPackets, &client_itr->UDPPackets, pc_end );\r
+ } \r
+ cc++;\r
+ \r
+ }\r
+ \r
+}\r
+\r
+void Sharedmemory_deinit(void) \r
+{\r
+ shmctl( shmid, IPC_RMID, 0 ); //Mark shmid for removal.\r
+ shmdt( shmptr );\r
+}
\ No newline at end of file
--- /dev/null
+typedef struct\r
+{\r
+ char username[121];\r
+ char ipaddress[46];\r
+ int tcp_port, udp_port;\r
+ char channel[121];\r
+ bool_t bUDP, authenticated, deaf, mute, self_deaf, self_mute, recording, bOpus;\r
+ etimer_t lastActivity, connectTime, idleTime;\r
+ float UDPPingAvg, UDPPingVar, TCPPingAvg, TCPPingVar;\r
+ uint32_t UDPPackets, TCPPackets;\r
+\r
+}shmclient_t;\r
+\r
+typedef struct\r
+{\r
+\r
+ int clientcount, server_max_clients;\r
+ unsigned int umurmurd_pid; //Use this to make sure umurmurd is still running so I can allow more than one connection.\r
+ shmclient_t client[]; //MJP BUG: Use max usersetting from conf file\r
+ \r
+}shm_t;
\ No newline at end of file