chansrv: added timeout callback

ulab-next
Jay Sorg 11 years ago
parent 1a6483f0ab
commit d22b8b5ed0

@ -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) */
}

@ -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);

Loading…
Cancel
Save