summaryrefslogtreecommitdiffstats
path: root/sesman
diff options
context:
space:
mode:
authorJay Sorg <jay.sorg@gmail.com>2013-09-07 23:54:36 -0700
committerJay Sorg <jay.sorg@gmail.com>2013-09-07 23:54:36 -0700
commitd22b8b5ed0868adf21a6b96a8f119dda5b96c25a (patch)
treea1c78eacf60c5153c63bdecb85c3e9c6f9788969 /sesman
parent1a6483f0abe666ef68c040f7c03fd3cf2c2d138f (diff)
downloadxrdp-proprietary-d22b8b5ed0868adf21a6b96a8f119dda5b96c25a.tar.gz
xrdp-proprietary-d22b8b5ed0868adf21a6b96a8f119dda5b96c25a.zip
chansrv: added timeout callback
Diffstat (limited to 'sesman')
-rw-r--r--sesman/chansrv/chansrv.c139
-rw-r--r--sesman/chansrv/chansrv.h5
2 files changed, 142 insertions, 2 deletions
diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c
index d81c488d..c3d1aa79 100644
--- a/sesman/chansrv/chansrv.c
+++ b/sesman/chansrv/chansrv.c
@@ -76,6 +76,143 @@ int g_exec_pid = 0;
/* this variable gets bumped up once per DVC we create */
tui32 g_dvc_chan_id = 100;
+struct timeout_obj
+{
+ tui32 mstime;
+ void* data;
+ void (*callback)(void* data);
+ struct timeout_obj* next;
+};
+
+static struct timeout_obj *g_timeout_head = 0;
+static struct timeout_obj *g_timeout_tail = 0;
+
+/*****************************************************************************/
+int APP_CC
+add_timeout(int msoffset, void (*callback)(void *data), void *data)
+{
+ struct timeout_obj *tobj;
+ tui32 now;
+
+ LOG(10, ("add_timeout:"));
+ now = g_time3();
+ tobj = g_malloc(sizeof(struct timeout_obj), 1);
+ tobj->mstime = now + msoffset;
+ tobj->callback = callback;
+ tobj->data = data;
+ if (g_timeout_tail == 0)
+ {
+ g_timeout_head = tobj;
+ g_timeout_tail = tobj;
+ }
+ else
+ {
+ g_timeout_tail->next = tobj;
+ g_timeout_tail = tobj;
+ }
+ return 0;
+}
+
+/*****************************************************************************/
+static int APP_CC
+get_timeout(int *timeout)
+{
+ struct timeout_obj *tobj;
+ tui32 now;
+ int ltimeout;
+
+ LOG(10, ("get_timeout:"));
+ ltimeout = *timeout;
+ if (ltimeout < 1)
+ {
+ ltimeout = 0;
+ }
+ tobj = g_timeout_head;
+ if (tobj != 0)
+ {
+ now = g_time3();
+ while (tobj != 0)
+ {
+ LOG(10, (" now %u tobj->mstime %u", now, tobj->mstime));
+ if (now < tobj->mstime)
+ {
+ ltimeout = tobj->mstime - now;
+ }
+ tobj = tobj->next;
+ }
+ }
+ if (ltimeout > 0)
+ {
+ LOG(10, (" ltimeout %d", ltimeout));
+ if (*timeout < 1)
+ {
+ *timeout = ltimeout;
+ }
+ else
+ {
+ if (*timeout > ltimeout)
+ {
+ *timeout = ltimeout;
+ }
+ }
+ }
+ return 0;
+}
+
+/*****************************************************************************/
+static int APP_CC
+check_timeout(void)
+{
+ struct timeout_obj *tobj;
+ struct timeout_obj *last_tobj;
+ struct timeout_obj *temp_tobj;
+ int count;
+ tui32 now;
+
+ LOG(10, ("check_timeout:"));
+ count = 0;
+ tobj = g_timeout_head;
+ if (tobj != 0)
+ {
+ last_tobj = 0;
+ while (tobj != 0)
+ {
+ count++;
+ now = g_time3();
+ if (now >= tobj->mstime)
+ {
+ tobj->callback(tobj->data);
+ if (last_tobj == 0)
+ {
+ g_timeout_head = tobj->next;
+ if (g_timeout_head == 0)
+ {
+ g_timeout_tail = 0;
+ }
+ }
+ else
+ {
+ last_tobj->next = tobj->next;
+ if (g_timeout_tail == tobj)
+ {
+ g_timeout_tail = last_tobj;
+ }
+ }
+ temp_tobj = tobj;
+ tobj = tobj->next;
+ g_free(temp_tobj);
+ }
+ else
+ {
+ last_tobj = tobj;
+ tobj = tobj->next;
+ }
+ }
+ }
+ LOG(10, (" count %d", count));
+ return 0;
+}
+
/*****************************************************************************/
int DEFAULT_CC
g_is_term(void)
@@ -925,6 +1062,7 @@ channel_thread_loop(void *in_val)
while (g_obj_wait(objs, num_objs, 0, 0, timeout) == 0)
{
+ check_timeout();
if (g_is_wait_obj_set(g_term_event))
{
LOGM((LOG_LEVEL_INFO, "channel_thread_loop: g_term_event set"));
@@ -1007,6 +1145,7 @@ channel_thread_loop(void *in_val)
sound_get_wait_objs(objs, &num_objs, &timeout);
dev_redir_get_wait_objs(objs, &num_objs, &timeout);
xfuse_get_wait_objs(objs, &num_objs, &timeout);
+ get_timeout(&timeout);
} /* end while (g_obj_wait(objs, num_objs, 0, 0, timeout) == 0) */
}
diff --git a/sesman/chansrv/chansrv.h b/sesman/chansrv/chansrv.h
index 12162dd1..06ecdc07 100644
--- a/sesman/chansrv/chansrv.h
+++ b/sesman/chansrv/chansrv.h
@@ -1,8 +1,8 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
- * Copyright (C) Jay Sorg 2009-2012
- * Copyright (C) Laxmikant Rashinkar 2009-2012
+ * Copyright (C) Jay Sorg 2009-2013
+ * Copyright (C) Laxmikant Rashinkar 2009-2013
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,6 +59,7 @@ g_is_term(void);
int APP_CC send_channel_data(int chan_id, char *data, int size);
int APP_CC main_cleanup(void);
+int APP_CC add_timeout(int msoffset, void (*callback)(void* data), void* data);
int APP_CC find_empty_slot_in_dvc_channels();
struct xrdp_api_data * APP_CC struct_from_dvc_chan_id(tui32 dvc_chan_id);
int remove_struct_with_chan_id(tui32 dvc_chan_id);