Skip to content
Snippets Groups Projects
Commit 65cba384 authored by Travis Glenn Hansen's avatar Travis Glenn Hansen
Browse files

adding LICENSE

removing multiplier and simply resetting counters
parent 282c093d
No related branches found
No related tags found
No related merge requests found
LICENSE 0 → 100644
MIT License
Copyright (c) 2011-2012 Travis Glenn Hansen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
/* A simple server in the internet domain using TCP /*
The port number is passed as an argument A simple server in the internet domain using TCP
https://github.com/hbons/fanout.node.js/blob/master/fanout.js*/ MIT Licensed
*/
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
...@@ -85,27 +86,21 @@ long server_start_time; ...@@ -85,27 +86,21 @@ long server_start_time;
//announcement stats //announcement stats
unsigned long long announcements_count =0; unsigned long long announcements_count =0;
unsigned long long announcements_count_multiplier = 0;
//messages stats //messages stats
unsigned long long messages_count =0; unsigned long long messages_count =0;
unsigned long long messages_count_multiplier = 0;
//subscription stats //subscription stats
unsigned long long subscriptions_count =0; unsigned long long subscriptions_count =0;
unsigned long long subscriptions_count_multiplier = 0;
//unsubscription stats //unsubscription stats
unsigned long long unsubscriptions_count =0; unsigned long long unsubscriptions_count =0;
unsigned long long unsubscriptions_count_multiplier = 0;
//ping stats //ping stats
unsigned long long pings_count =0; unsigned long long pings_count =0;
unsigned long long pings_count_multiplier = 0;
//connection/client stats //connection/client stats
unsigned long long clients_count =0; unsigned long long clients_count =0;
unsigned long long clients_count_multiplier = 0;
static int daemonize = 0; static int daemonize = 0;
...@@ -322,7 +317,7 @@ int main (int argc, char *argv[]) ...@@ -322,7 +317,7 @@ int main (int argc, char *argv[])
//stats //stats
if (clients_count == ULLONG_MAX) { if (clients_count == ULLONG_MAX) {
clients_count_multiplier++; fanout_debug (1, "wow, you've accepted alot of connections..resetting counter\n");
clients_count = 0; clients_count = 0;
} }
clients_count++; clients_count++;
...@@ -546,7 +541,7 @@ struct client *get_client (int fd) ...@@ -546,7 +541,7 @@ struct client *get_client (int fd)
return client_i; return client_i;
client_i = client_i->next; client_i = client_i->next;
} }
fanout_error ("client does not exist"); return NULL;
} }
...@@ -633,7 +628,7 @@ void client_process_input_buffer (struct client *c) ...@@ -633,7 +628,7 @@ void client_process_input_buffer (struct client *c)
free (message); free (message);
message = NULL; message = NULL;
if (pings_count == ULLONG_MAX) { if (pings_count == ULLONG_MAX) {
pings_count_multiplier++; fanout_debug (1, "wow, you've pinged alot..resetting counter\n");
pings_count = 0; pings_count = 0;
} }
pings_count++; pings_count++;
...@@ -659,6 +654,8 @@ void client_process_input_buffer (struct client *c) ...@@ -659,6 +654,8 @@ void client_process_input_buffer (struct client *c)
//uptime //uptime
long uptime = (long)time (NULL) - server_start_time; long uptime = (long)time (NULL) - server_start_time;
//averages
asprintf (&message, asprintf (&message,
"uptime: %ldd %ldh %ldm %lds\n\ "uptime: %ldd %ldh %ldm %lds\n\
max connections: %d\n\ max connections: %d\n\
...@@ -666,27 +663,20 @@ current connections: %d\n\ ...@@ -666,27 +663,20 @@ current connections: %d\n\
current channels: %d\n\ current channels: %d\n\
current subscriptions: %d\n\ current subscriptions: %d\n\
user-requested subscriptions: %d\n\ user-requested subscriptions: %d\n\
total connections: %llu + (%llu * %llu)\n\ total connections: %llu\n\
total announcements: %llu + (%llu * %llu)\n\ total announcements: %llu\n\
total messages: %llu + (%llu * %llu)\n\ total messages: %llu\n\
total subscribes: %llu + (%llu * %llu)\n\ total subscribes: %llu\n\
total unsubscribes: %llu + (%llu * %llu)\n\ total unsubscribes: %llu\n\
total pings: %llu + (%llu * %llu)\ total pings: %llu\
\n", uptime/3600/24, uptime/3600%24, \n", uptime/3600/24, uptime/3600%24,
uptime/60%60, uptime%60, uptime/60%60, uptime%60,
max_connection_count, max_connection_count,
current_client_count, current_channel_count, current_client_count, current_channel_count,
current_subscription_count, current_subscription_count,
current_requested_subscriptions, clients_count, current_requested_subscriptions, clients_count,
ULLONG_MAX, clients_count_multiplier, announcements_count, messages_count, subscriptions_count,
announcements_count, ULLONG_MAX, unsubscriptions_count, pings_count);
announcements_count_multiplier,
messages_count, ULLONG_MAX, messages_count_multiplier,
subscriptions_count, ULLONG_MAX,
subscriptions_count_multiplier,
unsubscriptions_count, ULLONG_MAX,
unsubscriptions_count_multiplier, pings_count,
ULLONG_MAX, pings_count_multiplier);
client_write (c, message); client_write (c, message);
free (message); free (message);
message = NULL; message = NULL;
...@@ -750,6 +740,7 @@ struct subscription *get_subscription (struct client *c, ...@@ -750,6 +740,7 @@ struct subscription *get_subscription (struct client *c,
return subscription_i; return subscription_i;
subscription_i = subscription_i->next; subscription_i = subscription_i->next;
} }
return NULL;
} }
...@@ -803,7 +794,7 @@ void announce (const char *channel, const char *message) ...@@ -803,7 +794,7 @@ void announce (const char *channel, const char *message)
client_write (subscription_i->client, s); client_write (subscription_i->client, s);
//message stats //message stats
if (messages_count == ULLONG_MAX) { if (messages_count == ULLONG_MAX) {
messages_count_multiplier++; fanout_debug (1, "wow, you've sent a lot of messages..resetting counter\n");
messages_count = 0; messages_count = 0;
} }
messages_count++; messages_count++;
...@@ -812,7 +803,7 @@ void announce (const char *channel, const char *message) ...@@ -812,7 +803,7 @@ void announce (const char *channel, const char *message)
} }
fanout_debug (2, "announced messge %s", s); fanout_debug (2, "announced messge %s", s);
if (announcements_count == ULLONG_MAX) { if (announcements_count == ULLONG_MAX) {
announcements_count_multiplier++; fanout_debug (1, "wow, you've announced alot..resetting counter\n");
announcements_count = 0; announcements_count = 0;
} }
announcements_count++; announcements_count++;
...@@ -843,7 +834,7 @@ void subscribe (struct client *c, const char *channel_name) ...@@ -843,7 +834,7 @@ void subscribe (struct client *c, const char *channel_name)
subscription_i->channel->name); subscription_i->channel->name);
if (subscriptions_count == ULLONG_MAX) { if (subscriptions_count == ULLONG_MAX) {
subscriptions_count_multiplier++; fanout_debug (1, "wow, you've subscribed alot..resetting counter\n");
subscriptions_count = 0; subscriptions_count = 0;
} }
subscriptions_count++; subscriptions_count++;
...@@ -873,7 +864,7 @@ void unsubscribe (struct client *c, const char *channel_name) ...@@ -873,7 +864,7 @@ void unsubscribe (struct client *c, const char *channel_name)
channel->subscription_count--; channel->subscription_count--;
if (unsubscriptions_count == ULLONG_MAX) { if (unsubscriptions_count == ULLONG_MAX) {
unsubscriptions_count_multiplier++; fanout_debug (1, "wow, you've unsubscribed alot..resetting counter\n");
unsubscriptions_count = 0; unsubscriptions_count = 0;
} }
unsubscriptions_count++; unsubscriptions_count++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment