void Sharedmemory_init( int bindport, int bindport6 )\r
{\r
\r
- int server_max_clients = getIntConf(MAX_CLIENTS);\r
- int shmtotal_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients);\r
-\r
- if( !bindport )\r
- {\r
- bindport = getIntConf(BINDPORT);\r
- }\r
-\r
- sprintf( shm_file_name, "/umurmurd:%i", bindport );\r
- Log_info("SHM_API: shm_fd=\"%s\"", shm_file_name );\r
-\r
- shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0660 );\r
- if(shm_fd == -1)\r
- {\r
- Log_fatal( "SHM_API: Open failed:%s\n", strerror(errno));\r
- exit(EXIT_FAILURE);\r
- }\r
-\r
- if( ftruncate( shm_fd, shmtotal_size ) == -1 )\r
- {\r
- Sharedmemory_deinit();\r
- Log_fatal( "SHM_API: ftruncate : %s\n", strerror(errno));\r
- exit(EXIT_FAILURE);\r
- }\r
-\r
- shmptr = mmap( 0, shmtotal_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0 );\r
- if (shmptr == MAP_FAILED)\r
- {\r
- Log_fatal( "SHM_API: mmap failed : %s\n", strerror(errno));\r
- exit(EXIT_FAILURE);\r
- }\r
-\r
- memset( shmptr, 0, shmtotal_size );\r
-\r
- shmptr->umurmurd_pid = getpid();\r
- shmptr->server_max_clients = server_max_clients;\r
- shmptr->shmtotal_size = shmtotal_size;\r
- shmptr->shmclient_size = sizeof( shmclient_t ) * shmptr->server_max_clients;\r
+ int server_max_clients = getIntConf(MAX_CLIENTS);\r
+ int shmtotal_size = sizeof( shm_t ) + (sizeof( shmclient_t ) * server_max_clients);\r
+\r
+ if( !bindport )\r
+ {\r
+ bindport = getIntConf(BINDPORT);\r
+ }\r
+\r
+ sprintf( shm_file_name, "/umurmurd:%i", bindport );\r
+ Log_info("SHM_API: shm_fd=\"%s\"", shm_file_name );\r
+\r
+ shm_fd = shm_open( shm_file_name, O_CREAT | O_RDWR, 0660 );\r
+ if(shm_fd == -1)\r
+ {\r
+ Log_fatal( "SHM_API: Open failed:%s\n", strerror(errno));\r
+ exit(EXIT_FAILURE);\r
+ }\r
+\r
+ if( ftruncate( shm_fd, shmtotal_size ) == -1 )\r
+ {\r
+ Sharedmemory_deinit();\r
+ Log_fatal( "SHM_API: ftruncate : %s\n", strerror(errno));\r
+ exit(EXIT_FAILURE);\r
+ }\r
+\r
+ shmptr = mmap( 0, shmtotal_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0 );\r
+ if (shmptr == MAP_FAILED)\r
+ {\r
+ Log_fatal( "SHM_API: mmap failed : %s\n", strerror(errno));\r
+ exit(EXIT_FAILURE);\r
+ }\r
+\r
+ memset( shmptr, 0, shmtotal_size );\r
+\r
+ shmptr->umurmurd_pid = getpid();\r
+ shmptr->server_max_clients = server_max_clients;\r
+ shmptr->shmtotal_size = shmtotal_size;\r
+ shmptr->shmclient_size = sizeof( shmclient_t ) * shmptr->server_max_clients;\r
\r
}\r
\r
void Sharedmemory_update(void)\r
{\r
\r
- uint64_t now;\r
- unsigned int cc = 0;\r
- client_t *client_itr = NULL;\r
+ uint64_t now;\r
+ unsigned int cc = 0;\r
+ client_t *client_itr = NULL;\r
\r
- memset( &shmptr->client[0], 0, shmptr->shmclient_size );\r
- shmptr->clientcount = Client_count();\r
+ memset( &shmptr->client[0], 0, shmptr->shmclient_size );\r
+ shmptr->clientcount = Client_count();\r
\r
- if( shmptr->clientcount )\r
- {\r
- Timer_init( &now );\r
- while( Client_iterate(&client_itr) != NULL )\r
- {\r
- if( client_itr->authenticated )\r
- {\r
- channel_t *channel = client_itr->channel;\r
+ if( shmptr->clientcount )\r
+ {\r
+ Timer_init( &now );\r
+ while( Client_iterate(&client_itr) != NULL )\r
+ {\r
+ if( client_itr->authenticated )\r
+ {\r
+ channel_t *channel = client_itr->channel;\r
\r
char* clientAddressString = Util_clientAddressToString( client_itr );\r
\r
- strncpy( shmptr->client[cc].username, client_itr->username, 120 );\r
- strncpy( shmptr->client[cc].ipaddress, clientAddressString, INET6_ADDRSTRLEN - 1 );\r
- strncpy( shmptr->client[cc].channel, channel->name, 120 );\r
+ strncpy( shmptr->client[cc].username, client_itr->username, 120 );\r
+ strncpy( shmptr->client[cc].ipaddress, clientAddressString, INET6_ADDRSTRLEN - 1 );\r
+ strncpy( shmptr->client[cc].channel, channel->name, 120 );\r
\r
- strncpy( shmptr->client[cc].os, client_itr->os, 120 );\r
- strncpy( shmptr->client[cc].release, client_itr->release, 120 );\r
- strncpy( shmptr->client[cc].os_version, client_itr->os_version, 120 );\r
+ strncpy( shmptr->client[cc].os, client_itr->os, 120 );\r
+ strncpy( shmptr->client[cc].release, client_itr->release, 120 );\r
+ strncpy( shmptr->client[cc].os_version, client_itr->os_version, 120 );\r
\r
- shmptr->client[cc].tcp_port = Util_clientAddressToPortTCP( client_itr );\r
- shmptr->client[cc].udp_port = Util_clientAddressToPortUDP( client_itr );\r
+ shmptr->client[cc].tcp_port = Util_clientAddressToPortTCP( client_itr );\r
+ shmptr->client[cc].udp_port = Util_clientAddressToPortUDP( client_itr );\r
\r
- shmptr->client[cc].online_secs = ( now - client_itr->connectTime ) / 1000000LL;\r
- shmptr->client[cc].idle_secs = ( now - client_itr->idleTime ) / 1000000LL;\r
+ shmptr->client[cc].online_secs = ( now - client_itr->connectTime ) / 1000000LL;\r
+ shmptr->client[cc].idle_secs = ( now - client_itr->idleTime ) / 1000000LL;\r
\r
- shmptr->client[cc].bUDP = client_itr->bUDP;\r
- shmptr->client[cc].deaf = client_itr->deaf;\r
- shmptr->client[cc].mute = client_itr->mute;\r
- shmptr->client[cc].bOpus = client_itr->bOpus;\r
- shmptr->client[cc].self_deaf = client_itr->self_deaf;\r
- shmptr->client[cc].self_mute = client_itr->self_mute;\r
- shmptr->client[cc].recording = client_itr->recording;\r
- shmptr->client[cc].authenticated = client_itr->authenticated;\r
+ shmptr->client[cc].bUDP = client_itr->bUDP;\r
+ shmptr->client[cc].deaf = client_itr->deaf;\r
+ shmptr->client[cc].mute = client_itr->mute;\r
+ shmptr->client[cc].bOpus = client_itr->bOpus;\r
+ shmptr->client[cc].self_deaf = client_itr->self_deaf;\r
+ shmptr->client[cc].self_mute = client_itr->self_mute;\r
+ shmptr->client[cc].recording = client_itr->recording;\r
+ shmptr->client[cc].authenticated = client_itr->authenticated;\r
\r
- shmptr->client[cc].availableBandwidth = client_itr->availableBandwidth;\r
+ shmptr->client[cc].availableBandwidth = client_itr->availableBandwidth;\r
\r
- shmptr->client[cc].UDPPingAvg = client_itr->UDPPingAvg;\r
- shmptr->client[cc].UDPPingVar = client_itr->UDPPingVar;\r
- shmptr->client[cc].TCPPingAvg = client_itr->TCPPingAvg;\r
- shmptr->client[cc].TCPPingVar = client_itr->TCPPingVar;\r
+ shmptr->client[cc].UDPPingAvg = client_itr->UDPPingAvg;\r
+ shmptr->client[cc].UDPPingVar = client_itr->UDPPingVar;\r
+ shmptr->client[cc].TCPPingAvg = client_itr->TCPPingAvg;\r
+ shmptr->client[cc].TCPPingVar = client_itr->TCPPingVar;\r
\r
- shmptr->client[cc].isAdmin = client_itr->isAdmin;\r
- shmptr->client[cc].isSuppressed = client_itr->isSuppressed;\r
+ shmptr->client[cc].isAdmin = client_itr->isAdmin;\r
+ shmptr->client[cc].isSuppressed = client_itr->isSuppressed;\r
\r
- shmptr->client[cc].UDPPackets = client_itr->UDPPackets;\r
- shmptr->client[cc].TCPPackets = client_itr->TCPPackets;\r
+ shmptr->client[cc].UDPPackets = client_itr->UDPPackets;\r
+ shmptr->client[cc].TCPPackets = client_itr->TCPPackets;\r
\r
free(clientAddressString);\r
- }\r
- cc++;\r
- }\r
- }\r
+ }\r
+ cc++;\r
+ }\r
+ }\r
}\r
void Sharedmemory_alivetick(void)\r
{\r
- shmptr->alive++;\r
+ shmptr->alive++;\r
}\r
\r
void Sharedmemory_deinit(void)\r
{\r
- close( shm_fd );\r
- shm_unlink( shm_file_name );\r
- shmptr->umurmurd_pid = 0;\r
+ close( shm_fd );\r
+ shm_unlink( shm_file_name );\r
+ shmptr->umurmurd_pid = 0;\r
}\r