diff options
author | jsorg71 <jsorg71> | 2010-05-04 09:24:24 +0000 |
---|---|---|
committer | jsorg71 <jsorg71> | 2010-05-04 09:24:24 +0000 |
commit | 574355f3e3a24ad7f0c27bc4c7fd2248ed89e99e (patch) | |
tree | d70599f6a8d101c6d92f1fa4aa23d929ac392342 /xrdp | |
parent | 27e097663f6b70801268e53d24a8fa45517367e9 (diff) | |
download | xrdp-proprietary-574355f3e3a24ad7f0c27bc4c7fd2248ed89e99e.tar.gz xrdp-proprietary-574355f3e3a24ad7f0c27bc4c7fd2248ed89e99e.zip |
use trans
Diffstat (limited to 'xrdp')
-rw-r--r-- | xrdp/xrdp.h | 2 | ||||
-rw-r--r-- | xrdp/xrdp_listen.c | 100 | ||||
-rw-r--r-- | xrdp/xrdp_mm.c | 8 | ||||
-rw-r--r-- | xrdp/xrdp_process.c | 38 | ||||
-rw-r--r-- | xrdp/xrdp_types.h | 6 |
5 files changed, 87 insertions, 67 deletions
diff --git a/xrdp/xrdp.h b/xrdp/xrdp.h index 4cec5931..1ff1afc3 100644 --- a/xrdp/xrdp.h +++ b/xrdp/xrdp.h @@ -26,6 +26,7 @@ #endif #include "arch.h" #include "parse.h" +#include "trans.h" #include "libxrdpinc.h" #include "xrdp_types.h" #include "xrdp_constants.h" @@ -36,7 +37,6 @@ #include "list.h" #include "file.h" #include "file_loc.h" -#include "trans.h" /* xrdp.c */ long APP_CC diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index a596eba0..1d3b3de1 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2004-2009 + Copyright (C) Jay Sorg 2004-2010 listen for incoming connection @@ -44,6 +44,11 @@ xrdp_listen_create(void) { g_process_sem = tc_sem_create(0); } + self->listen_trans = trans_create(TRANS_MODE_TCP, 16, 16); + if (self->listen_trans == 0) + { + g_writeln("xrdp_listen_main_loop: trans_create failed"); + } return self; } @@ -51,6 +56,10 @@ xrdp_listen_create(void) void APP_CC xrdp_listen_delete(struct xrdp_listen* self) { + if (self->listen_trans != 0) + { + trans_delete(self->listen_trans); + } if (g_process_sem != 0) { tc_sem_delete(g_process_sem); @@ -159,6 +168,32 @@ xrdp_listen_get_port(char* port, int port_bytes) } /*****************************************************************************/ +/* a new connection is coming in */ +int DEFAULT_CC +xrdp_listen_conn_in(struct trans* self, struct trans* new_self) +{ + struct xrdp_process* process; + struct xrdp_listen* lis; + + g_writeln("hello"); + lis = (struct xrdp_listen*)(self->callback_data); + process = xrdp_process_create(lis, lis->pro_done_event); + if (xrdp_listen_add_pro(lis, process) == 0) + { + /* start thread */ + process->server_trans = new_self; + g_process = process; + tc_thread_create(xrdp_process_run, 0); + tc_sem_dec(g_process_sem); /* this will wait */ + } + else + { + xrdp_process_delete(process); + } + return 0; +} + +/*****************************************************************************/ /* wait for incoming connections */ int APP_CC xrdp_listen_main_loop(struct xrdp_listen* self) @@ -166,32 +201,28 @@ xrdp_listen_main_loop(struct xrdp_listen* self) int error; int robjs_count; int cont; + int timeout; char port[8]; tbus robjs[8]; tbus term_obj; tbus sync_obj; tbus sck_obj; tbus done_obj; - struct xrdp_process* process; self->status = 1; - xrdp_listen_get_port(port, sizeof(port)); - self->sck = g_tcp_socket(); - g_tcp_set_non_blocking(self->sck); - error = g_tcp_bind(self->sck, port); - if (error != 0) + if (xrdp_listen_get_port(port, sizeof(port)) != 0) { - g_writeln("bind error in xrdp_listen_main_loop"); - g_tcp_close(self->sck); + g_writeln("xrdp_listen_main_loop: xrdp_listen_get_port failed"); self->status = -1; return 1; } - error = g_tcp_listen(self->sck); + error = trans_listen(self->listen_trans, port); if (error == 0) { + self->listen_trans->trans_conn_in = xrdp_listen_conn_in; + self->listen_trans->callback_data = self; term_obj = g_get_term_event(); sync_obj = g_get_sync_event(); - sck_obj = g_create_wait_obj_from_socket(self->sck, 0); done_obj = self->pro_done_event; cont = 1; while (cont) @@ -200,10 +231,15 @@ xrdp_listen_main_loop(struct xrdp_listen* self) robjs_count = 0; robjs[robjs_count++] = term_obj; robjs[robjs_count++] = sync_obj; - robjs[robjs_count++] = sck_obj; robjs[robjs_count++] = done_obj; + timeout = -1; + if (trans_get_wait_objs(self->listen_trans, robjs, &robjs_count, + &timeout) != 0) + { + break; + } /* wait */ - if (g_obj_wait(robjs, robjs_count, 0, 0, -1) != 0) + if (g_obj_wait(robjs, robjs_count, 0, 0, timeout) != 0) { /* error, should not get here */ g_sleep(100); @@ -217,45 +253,19 @@ xrdp_listen_main_loop(struct xrdp_listen* self) g_reset_wait_obj(sync_obj); g_loop(); } - if (g_is_wait_obj_set(sck_obj)) /* incomming connection */ - { - error = g_tcp_accept(self->sck); - if ((error == -1) && g_tcp_last_error_would_block(self->sck)) - { - /* should not get here */ - g_sleep(100); - } - else if (error == -1) - { - /* error, should not get here */ - break; - } - else - { - process = xrdp_process_create(self, self->pro_done_event); - if (xrdp_listen_add_pro(self, process) == 0) - { - /* start thread */ - process->sck = error; - g_process = process; - tc_thread_create(xrdp_process_run, 0); - tc_sem_dec(g_process_sem); /* this will wait */ - } - else - { - xrdp_process_delete(process); - } - } - } if (g_is_wait_obj_set(done_obj)) /* pro_done_event */ { g_reset_wait_obj(done_obj); xrdp_listen_delete_done_pro(self); } + if (trans_check_wait_objs(self->listen_trans) != 0) + { + break; + } } /* stop listening */ - g_delete_wait_obj_from_socket(sck_obj); - g_tcp_close(self->sck); + trans_delete(self->listen_trans); + self->listen_trans = 0; /* second loop to wait for all process threads to close */ cont = 1; while (cont) diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c index f3327767..f4cb6d5d 100644 --- a/xrdp/xrdp_mm.c +++ b/xrdp/xrdp_mm.c @@ -14,7 +14,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. xrdp: A Remote Desktop Protocol server. - Copyright (C) Jay Sorg 2004-2009 + Copyright (C) Jay Sorg 2004-2010 module manager @@ -660,13 +660,13 @@ xrdp_mm_process_login_response(struct xrdp_mm* self, struct stream* s) if (strcmp(ip, "127.0.0.1") == 0) { /* unix socket */ - self->chan_trans = trans_create(2, 8192, 8192); + self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192); g_snprintf(port, 255, "/tmp/xrdp_chansrv_socket_%d", 7200 + display); } else { /* tcp */ - self->chan_trans = trans_create(1, 8192, 8192); + self->chan_trans = trans_create(TRANS_MODE_TCP, 8192, 8192); g_snprintf(port, 255, "%d", 7200 + display); } self->chan_trans->trans_data_in = xrdp_mm_chan_data_in; @@ -896,7 +896,7 @@ xrdp_mm_connect(struct xrdp_mm* self) ok = 0; errstr[0] = 0; trans_delete(self->sesman_trans); - self->sesman_trans = trans_create(1, 8192, 8192); + self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192); xrdp_mm_get_sesman_port(port, sizeof(port)); g_snprintf(text, 255, "connecting to sesman ip %s port %s", ip, port); xrdp_wm_log_msg(self->wm, text); diff --git a/xrdp/xrdp_process.c b/xrdp/xrdp_process.c index 8deb1ba2..c5eab510 100644 --- a/xrdp/xrdp_process.c +++ b/xrdp/xrdp_process.c @@ -56,6 +56,7 @@ xrdp_process_delete(struct xrdp_process* self) g_delete_wait_obj(self->self_term_event); libxrdp_exit(self->session); xrdp_wm_delete(self->wm); + trans_delete(self->server_trans); g_free(self); } @@ -111,6 +112,21 @@ xrdp_process_mod_end(struct xrdp_process* self) } /*****************************************************************************/ +static int DEFAULT_CC +xrdp_process_data_in(struct trans* self) +{ + struct xrdp_process* pro; + + DEBUG(("xrdp_process_data_in")); + pro = (struct xrdp_process*)(self->callback_data); + if (xrdp_process_loop(pro) != 0) + { + return 1; + } + return 0; +} + +/*****************************************************************************/ int APP_CC xrdp_process_main_loop(struct xrdp_process* self) { @@ -121,20 +137,19 @@ xrdp_process_main_loop(struct xrdp_process* self) tbus robjs[32]; tbus wobjs[32]; tbus term_obj; - tbus sck_obj; + DEBUG(("xrdp_process_main_loop")); self->status = 1; - self->session = libxrdp_init((long)self, self->sck); + self->server_trans->trans_data_in = xrdp_process_data_in; + self->server_trans->callback_data = self; + self->session = libxrdp_init((tbus)self, self->server_trans); /* this callback function is in xrdp_wm.c */ self->session->callback = callback; /* this function is just above */ self->session->is_term = xrdp_is_term; - g_tcp_set_non_blocking(self->sck); - g_tcp_set_no_delay(self->sck); if (libxrdp_process_incomming(self->session) == 0) { term_obj = g_get_term_event(); - sck_obj = g_create_wait_obj_from_socket(self->sck, 0); cont = 1; while (cont) { @@ -143,10 +158,10 @@ xrdp_process_main_loop(struct xrdp_process* self) robjs_count = 0; wobjs_count = 0; robjs[robjs_count++] = term_obj; - robjs[robjs_count++] = sck_obj; robjs[robjs_count++] = self->self_term_event; xrdp_wm_get_wait_objs(self->wm, robjs, &robjs_count, wobjs, &wobjs_count, &timeout); + trans_get_wait_objs(self->server_trans, robjs, &robjs_count, &timeout); /* wait */ if (g_obj_wait(robjs, robjs_count, wobjs, wobjs_count, timeout) != 0) { @@ -161,25 +176,20 @@ xrdp_process_main_loop(struct xrdp_process* self) { break; } - if (g_is_wait_obj_set(sck_obj)) /* incomming client data */ + if (xrdp_wm_check_wait_objs(self->wm) != 0) { - if (xrdp_process_loop(self) != 0) - { - break; - } + break; } - if (xrdp_wm_check_wait_objs(self->wm) != 0) + if (trans_check_wait_objs(self->server_trans) != 0) { break; } } - g_delete_wait_obj_from_socket(sck_obj); libxrdp_disconnect(self->session); } xrdp_process_mod_end(self); libxrdp_exit(self->session); self->session = 0; - g_tcp_close(self->sck); self->status = -1; g_set_wait_obj(self->done_event); return 0; diff --git a/xrdp/xrdp_types.h b/xrdp/xrdp_types.h index 33dc2795..0e1d6b32 100644 --- a/xrdp/xrdp_types.h +++ b/xrdp/xrdp_types.h @@ -269,13 +269,13 @@ struct xrdp_wm struct xrdp_process { int status; - int sck; + struct trans* server_trans; /* in tcp server mode */ tbus self_term_event; struct xrdp_listen* lis_layer; /* owner */ struct xrdp_session* session; /* create these when up and running */ struct xrdp_wm* wm; - int app_sck; + //int app_sck; tbus done_event; int session_id; }; @@ -284,7 +284,7 @@ struct xrdp_process struct xrdp_listen { int status; - int sck; + struct trans* listen_trans; /* in tcp listen mode */ struct list* process_list; tbus pro_done_event; }; |