common: transport aware when app is terminating

This commit is contained in:
Jay Sorg 2013-08-17 13:32:53 -07:00
parent ee98f1cdd4
commit e602a28d5c
10 changed files with 52 additions and 8 deletions

View File

@ -142,6 +142,7 @@ trans_check_wait_objs(struct trans *self)
in_trans->sck = in_sck; in_trans->sck = in_sck;
in_trans->type1 = TRANS_TYPE_SERVER; in_trans->type1 = TRANS_TYPE_SERVER;
in_trans->status = TRANS_STATUS_UP; in_trans->status = TRANS_STATUS_UP;
in_trans->is_term = self->is_term;
if (self->trans_conn_in(self, in_trans) != 0) if (self->trans_conn_in(self, in_trans) != 0)
{ {
@ -226,9 +227,18 @@ trans_force_read_s(struct trans *self, struct stream *in_s, int size)
{ {
if (g_tcp_last_error_would_block(self->sck)) if (g_tcp_last_error_would_block(self->sck))
{ {
if (!g_tcp_can_recv(self->sck, 10)) if (!g_tcp_can_recv(self->sck, 100))
{ {
/* check for term here */ /* check for term here */
if (self->is_term != 0)
{
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
} }
} }
else else
@ -285,9 +295,18 @@ trans_force_write_s(struct trans *self, struct stream *out_s)
{ {
if (g_tcp_last_error_would_block(self->sck)) if (g_tcp_last_error_would_block(self->sck))
{ {
if (!g_tcp_can_send(self->sck, 10)) if (!g_tcp_can_send(self->sck, 100))
{ {
/* check for term here */ /* check for term here */
if (self->is_term != 0)
{
if (self->is_term())
{
/* term */
self->status = TRANS_STATUS_DOWN;
return 1;
}
}
} }
} }
else else

View File

@ -38,6 +38,7 @@ struct trans; /* forward declaration */
typedef int (*ttrans_data_in)(struct trans* self); typedef int (*ttrans_data_in)(struct trans* self);
typedef int (*ttrans_conn_in)(struct trans* self, struct trans* new_self); typedef int (*ttrans_conn_in)(struct trans* self, struct trans* new_self);
typedef int (*tis_term)(void);
struct trans struct trans
{ {
@ -52,6 +53,7 @@ struct trans
struct stream* in_s; struct stream* in_s;
struct stream* out_s; struct stream* out_s;
char* listen_filename; char* listen_filename;
tis_term is_term; /* used to test for exit */
}; };
struct trans* APP_CC struct trans* APP_CC

View File

@ -76,6 +76,13 @@ int g_exec_pid = 0;
/* this variable gets bumped up once per DVC we create */ /* this variable gets bumped up once per DVC we create */
tui32 g_dvc_chan_id = 100; tui32 g_dvc_chan_id = 100;
/*****************************************************************************/
int DEFAULT_CC
g_is_term(void)
{
return g_is_wait_obj_set(g_term_event);
}
/*****************************************************************************/ /*****************************************************************************/
/* add data to chan_item, on its way to the client */ /* add data to chan_item, on its way to the client */
/* returns error */ /* returns error */
@ -844,13 +851,15 @@ setup_listen(void)
if (g_use_unix_socket) if (g_use_unix_socket)
{ {
g_lis_trans = trans_create(2, 8192, 8192); g_lis_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
g_lis_trans->is_term = g_is_term;
g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d",
7200 + g_display_num); 7200 + g_display_num);
} }
else else
{ {
g_lis_trans = trans_create(1, 8192, 8192); g_lis_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
g_lis_trans->is_term = g_is_term;
g_snprintf(port, 255, "%d", 7200 + g_display_num); g_snprintf(port, 255, "%d", 7200 + g_display_num);
} }
@ -875,6 +884,7 @@ setup_api_listen(void)
int error = 0; int error = 0;
g_api_lis_trans = trans_create(TRANS_MODE_UNIX, 8192 * 4, 8192 * 4); g_api_lis_trans = trans_create(TRANS_MODE_UNIX, 8192 * 4, 8192 * 4);
g_api_lis_trans->is_term = g_is_term;
g_snprintf(port, 255, "/tmp/.xrdp/xrdpapi_%d", g_display_num); g_snprintf(port, 255, "/tmp/.xrdp/xrdpapi_%d", g_display_num);
g_api_lis_trans->trans_conn_in = my_api_trans_conn_in; g_api_lis_trans->trans_conn_in = my_api_trans_conn_in;
error = trans_listen(g_api_lis_trans, port); error = trans_listen(g_api_lis_trans, port);

View File

@ -54,6 +54,9 @@ struct xrdp_api_data
int is_connected; int is_connected;
}; };
int DEFAULT_CC
g_is_term(void);
int APP_CC send_channel_data(int chan_id, char *data, int size); int APP_CC send_channel_data(int chan_id, char *data, int size);
int APP_CC main_cleanup(void); int APP_CC main_cleanup(void);
int APP_CC find_empty_slot_in_dvc_channels(); int APP_CC find_empty_slot_in_dvc_channels();

View File

@ -24,6 +24,7 @@
#define PCSC_STANDIN 1 #define PCSC_STANDIN 1
#include "chansrv.h"
#include "os_calls.h" #include "os_calls.h"
#include "smartcard.h" #include "smartcard.h"
#include "log.h" #include "log.h"
@ -258,7 +259,8 @@ scard_pcsc_init(void)
if (g_lis == 0) if (g_lis == 0)
{ {
g_lis = trans_create(2, 8192, 8192); g_lis = trans_create(TRANS_MODE_UNIX, 8192, 8192);
g_lis->is_term = g_is_term;
g_snprintf(g_pcsc_directory, 255, "/tmp/.xrdp/pcsc%d", g_display_num); g_snprintf(g_pcsc_directory, 255, "/tmp/.xrdp/pcsc%d", g_display_num);
if (g_directory_exist(g_pcsc_directory)) if (g_directory_exist(g_pcsc_directory))
{ {

View File

@ -551,7 +551,8 @@ sound_init(void)
LOG(0, ("sound_init:")); LOG(0, ("sound_init:"));
sound_send_server_formats(); sound_send_server_formats();
g_audio_l_trans = trans_create(2, 128 * 1024, 8192); g_audio_l_trans = trans_create(TRANS_MODE_UNIX, 128 * 1024, 8192);
g_audio_l_trans->is_term = g_is_term;
g_snprintf(port, 255, CHANSRV_PORT_STR, g_display_num); g_snprintf(port, 255, CHANSRV_PORT_STR, g_display_num);
g_audio_l_trans->trans_conn_in = sound_trans_audio_conn_in; g_audio_l_trans->trans_conn_in = sound_trans_audio_conn_in;
error = trans_listen(g_audio_l_trans, port); error = trans_listen(g_audio_l_trans, port);

View File

@ -138,7 +138,7 @@ xrdp_child_fork(void)
} }
/*****************************************************************************/ /*****************************************************************************/
int APP_CC int DEFAULT_CC
g_is_term(void) g_is_term(void)
{ {
return g_is_wait_obj_set(g_term_event); return g_is_wait_obj_set(g_term_event);

View File

@ -41,7 +41,7 @@
long APP_CC long APP_CC
g_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1, g_xrdp_sync(long (*sync_func)(long param1, long param2), long sync_param1,
long sync_param2); long sync_param2);
int APP_CC int DEFAULT_CC
g_is_term(void); g_is_term(void);
void APP_CC void APP_CC
g_set_term(int in_val); g_set_term(int in_val);

View File

@ -66,6 +66,10 @@ xrdp_listen_create(void)
{ {
log_message(LOG_LEVEL_ERROR,"xrdp_listen_create: trans_create failed"); log_message(LOG_LEVEL_ERROR,"xrdp_listen_create: trans_create failed");
} }
else
{
self->listen_trans->is_term = g_is_term;
}
return self; return self;
} }

View File

@ -797,11 +797,13 @@ xrdp_mm_connect_chansrv(struct xrdp_mm *self, char *ip, char *port)
{ {
/* unix socket */ /* unix socket */
self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192); self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
self->chan_trans->is_term = g_is_term;
} }
else else
{ {
/* tcp */ /* tcp */
self->chan_trans = trans_create(TRANS_MODE_TCP, 8192, 8192); self->chan_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
self->chan_trans->is_term = g_is_term;
} }
self->chan_trans->trans_data_in = xrdp_mm_chan_data_in; self->chan_trans->trans_data_in = xrdp_mm_chan_data_in;
@ -1486,6 +1488,7 @@ xrdp_mm_connect(struct xrdp_mm *self)
ok = 0; ok = 0;
trans_delete(self->sesman_trans); trans_delete(self->sesman_trans);
self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192); self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
self->sesman_trans->is_term = g_is_term;
xrdp_mm_get_sesman_port(port, sizeof(port)); xrdp_mm_get_sesman_port(port, sizeof(port));
g_snprintf(text, 255, "connecting to sesman ip %s port %s", ip, port); g_snprintf(text, 255, "connecting to sesman ip %s port %s", ip, port);
xrdp_wm_log_msg(self->wm, text); xrdp_wm_log_msg(self->wm, text);