diff options
| author | jsorg71 <jsorg71> | 2008-03-31 11:28:18 +0000 |
|---|---|---|
| committer | jsorg71 <jsorg71> | 2008-03-31 11:28:18 +0000 |
| commit | 4df6aa909e1c0f8626cf1968a6e188779eef7629 (patch) | |
| tree | dfd0f2f2827c68eb9911122739b14f2bfba2abdf /xrdp/xrdp_listen.c | |
| parent | dab4ae3934dd0afed35887af84c47dfe7e38172e (diff) | |
| download | xrdp-proprietary-4df6aa909e1c0f8626cf1968a6e188779eef7629.tar.gz xrdp-proprietary-4df6aa909e1c0f8626cf1968a6e188779eef7629.zip | |
main loop reorganization
Diffstat (limited to 'xrdp/xrdp_listen.c')
| -rw-r--r-- | xrdp/xrdp_listen.c | 126 |
1 files changed, 74 insertions, 52 deletions
diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index 406f6383..d7e63b7d 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -34,8 +34,9 @@ xrdp_listen_create(void) struct xrdp_listen* self; self = (struct xrdp_listen*)g_malloc(sizeof(struct xrdp_listen), 1); - self->process_list_max = 100; g_process_sem = tc_sem_create(0); + self->pro_done_event = g_create_wait_obj("xrdp_listen_pro_done_event"); + self->process_list = list_create(); return self; } @@ -44,6 +45,8 @@ void APP_CC xrdp_listen_delete(struct xrdp_listen* self) { tc_sem_delete(g_process_sem); + g_destroy_wait_obj(self->pro_done_event); + list_delete(self->process_list); g_free(self); } @@ -52,32 +55,37 @@ static int APP_CC xrdp_listen_term_processes(struct xrdp_listen* self) { int i; + struct xrdp_process* pro; /* tell all xrdp processes to end */ - for (i = 0; i < self->process_list_count; i++) + for (i = self->process_list->count - 1; i >= 0; i--) { - if (self->process_list[i] != 0) + pro = (struct xrdp_process*)list_get_item(self->process_list, i); + if (pro != 0) { - self->process_list[i]->term = 1; + pro->term = 1; } } /* make sure they are done */ - for (i = 0; i < self->process_list_count; i++) + for (i = self->process_list->count - 1; i >= 0; i--) { - if (self->process_list[i] != 0) + pro = (struct xrdp_process*)list_get_item(self->process_list, i); + if (pro != 0) { - while (self->process_list[i]->status > 0) + while (pro->status > 0) { g_sleep(10); } } } /* free them all */ - for (i = 0; i < self->process_list_count; i++) + for (i = self->process_list->count - 1; i >= 0; i--) { - if (self->process_list[i] != 0) + pro = (struct xrdp_process*)list_get_item(self->process_list, i); + if (pro != 0) { - xrdp_process_delete(self->process_list[i]); + xrdp_process_delete(pro); + list_remove_item(self->process_list, i); } } return 0; @@ -88,43 +96,27 @@ xrdp_listen_term_processes(struct xrdp_listen* self) static int APP_CC xrdp_listen_add_pro(struct xrdp_listen* self, struct xrdp_process* process) { - int i; - - for (i = 0; i < self->process_list_max; i++) - { - /* add process in new slot */ - if (self->process_list[i] == 0) - { - self->process_list[i] = process; - self->process_list_count++; - return 0; - } - /* add process in unused slot */ - /* this shouldn't happen */ - if (self->process_list[i]->status < 0) - { - xrdp_process_delete(self->process_list[i]); - self->process_list[i] = process; - return 0; - } - } - return 1; + list_add_item(self->process_list, (tbus)process); + return 0; } /*****************************************************************************/ -int APP_CC -xrdp_listen_delete_pro(struct xrdp_listen* self, struct xrdp_process* pro) +static int APP_CC +xrdp_listen_delete_done_pro(struct xrdp_listen* self) { int i; + struct xrdp_process* pro; - for (i = 0; i < self->process_list_max; i++) + for (i = self->process_list->count - 1; i >= 0; i--) { - if (self->process_list[i] == pro) + pro = (struct xrdp_process*)list_get_item(self->process_list, i); + if (pro != 0) { - DEBUG(("process deleted")); - xrdp_process_delete(pro); - self->process_list[i] = 0; - return 0; + if (pro->status < 0) + { + xrdp_process_delete(pro); + list_remove_item(self->process_list, i); + } } } return 0; @@ -200,9 +192,13 @@ int APP_CC xrdp_listen_main_loop(struct xrdp_listen* self) { int error; + int robjs_count; + int cont; char port[8]; + tbus robjs[4]; self->status = 1; + robjs_count = 0; xrdp_listen_get_port(port, sizeof(port)); self->sck = g_tcp_socket(); g_tcp_set_non_blocking(self->sck); @@ -217,33 +213,59 @@ xrdp_listen_main_loop(struct xrdp_listen* self) error = g_tcp_listen(self->sck); if (error == 0) { - while (!g_is_term() && !self->term) + robjs[0] = g_get_term_event(); + robjs[1] = g_get_sync_event(); + robjs[2] = g_create_wait_obj_from_socket(self->sck, 0); + robjs[3] = self->pro_done_event; + robjs_count = 4; + cont = 1; + while (cont) { - error = g_tcp_accept(self->sck); - if ((error == -1) && g_tcp_last_error_would_block(self->sck)) + if (g_obj_wait(robjs, robjs_count, 0, 0, -1) != 0) { g_sleep(100); - g_loop(); } - else if (error == -1) + if (g_is_wait_obj_set(robjs[0])) /* term */ { break; } - else + if (g_is_wait_obj_set(robjs[1])) /* sync */ { - g_process = xrdp_process_create(self); - if (xrdp_listen_add_pro(self, g_process) == 0) + g_reset_wait_obj(robjs[1]); + g_loop(); + } + if (g_is_wait_obj_set(robjs[2])) /* incomming connection */ + { + error = g_tcp_accept(self->sck); + if ((error == -1) && g_tcp_last_error_would_block(self->sck)) + { + g_sleep(100); + } + else if (error == -1) { - /* start thread */ - g_process->sck = error; - tc_thread_create(xrdp_process_run, 0); - tc_sem_dec(g_process_sem); /* this will wait */ + break; } else { - xrdp_process_delete(g_process); + g_process = xrdp_process_create(self, self->pro_done_event); + if (xrdp_listen_add_pro(self, g_process) == 0) + { + /* start thread */ + g_process->sck = error; + tc_thread_create(xrdp_process_run, 0); + tc_sem_dec(g_process_sem); /* this will wait */ + } + else + { + xrdp_process_delete(g_process); + } } } + if (g_is_wait_obj_set(robjs[3])) /* pro_done_event */ + { + g_reset_wait_obj(robjs[3]); + xrdp_listen_delete_done_pro(self); + } } } else |
