Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Burton2011-12-05 20:04:26 +0000
committerFelix Burton2011-12-05 22:42:38 +0000
commit7d9df444960e2fa39b3f216492cfa1fb6468a5e5 (patch)
tree1dadd3985091dd70f914500f61d6bac4f55d2459
parentafab780d7c6ad078c3be29236e14a704c5b7c4c7 (diff)
downloadorg.eclipse.tcf.agent-7d9df444960e2fa39b3f216492cfa1fb6468a5e5.tar.gz
org.eclipse.tcf.agent-7d9df444960e2fa39b3f216492cfa1fb6468a5e5.tar.xz
org.eclipse.tcf.agent-7d9df444960e2fa39b3f216492cfa1fb6468a5e5.zip
TCF Agent: added option "-I <idle-seconds>" to automatically shutdown server when there are no connections for the specified time
-rw-r--r--main/main.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/main/main.c b/main/main.c
index be0f7ebe..7f9c2737 100644
--- a/main/main.c
+++ b/main/main.c
@@ -38,6 +38,26 @@
#include <main/server.h>
static const char * progname;
+static unsigned int idle_timeout;
+static unsigned int idle_count;
+
+static void check_idle_timeout(void * args) {
+ if (list_is_empty(&channel_root)) {
+ idle_count++;
+ if (idle_count == idle_timeout) {
+ trace(LOG_ALWAYS, "No connections for %d seconds, shutting down", idle_timeout);
+ discovery_stop();
+ cancel_event_loop();
+ return;
+ }
+ }
+ post_event_with_delay(check_idle_timeout, NULL, 1000000);
+}
+
+static void channel_closed(Channel *c) {
+ /* Reset idle_count if there are short lived connections */
+ idle_count = 0;
+}
static void shutdown_event(void * args) {
discovery_stop();
@@ -175,6 +195,7 @@ int main(int argc, char ** argv) {
print_server_url = 1;
break;
+ case 'I':
case 'l':
case 'L':
case 's':
@@ -189,6 +210,10 @@ int main(int argc, char ** argv) {
s = argv[ind];
}
switch (c) {
+ case 'I':
+ idle_timeout = strtol(s, 0, 0);
+ break;
+
case 'l':
log_mode = strtol(s, 0, 0);
break;
@@ -260,6 +285,11 @@ int main(int argc, char ** argv) {
SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
#endif
+ if (idle_timeout != 0) {
+ add_channel_close_listener(channel_closed);
+ check_idle_timeout(NULL);
+ }
+
/* Process events - must run on the initial thread since ptrace()
* returns ECHILD otherwise, thinking we are not the owner. */
run_event_loop();

Back to the top