diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c index 3e5bcd0a..41ec3971 100644 --- a/xrdp/xrdp.c +++ b/xrdp/xrdp.c @@ -34,6 +34,8 @@ THREAD_RV THREAD_CC xrdp_listen_run(void* in_val) return 0; } +//#define CLEAN_CLOSE + /*****************************************************************************/ int main(int argc, char** argv) { @@ -42,15 +44,23 @@ int main(int argc, char** argv) g_init_system(); rv = 0; g_listen = xrdp_listen_create(); +#ifdef CLEAN_CLOSE if (g_thread_create(xrdp_listen_run, 0) == 0) { g_getchar(); g_set_term(1); while (g_listen->status > 0) + { g_sleep(100); + } } else + { rv = 1; + } +#else + xrdp_listen_main_loop(g_listen); +#endif xrdp_listen_delete(g_listen); g_exit_system(); return rv; diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index f46cb187..92de0b99 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -139,7 +139,12 @@ int xrdp_listen_main_loop(struct xrdp_listen* self) self->status = 1; self->sck = g_tcp_socket(); g_tcp_set_non_blocking(self->sck); - g_tcp_bind(self->sck, "3389"); + if (g_tcp_bind(self->sck, "3389") != 0) + { + g_printf("bind error in xrdp_listen_main_loop\n\r"); + g_tcp_close(self->sck); + return 1; + } error = g_tcp_listen(self->sck); if (error == 0) { diff --git a/xrdp/xrdp_tcp.c b/xrdp/xrdp_tcp.c index ed08aef7..eed5278e 100644 --- a/xrdp/xrdp_tcp.c +++ b/xrdp/xrdp_tcp.c @@ -54,6 +54,11 @@ int xrdp_tcp_recv(struct xrdp_tcp* self, struct stream* s, int len) { int rcvd; + if (self->sck_closed) + { + DEBUG((" in xrdp_tcp_recv, sck closed\n\r")); + return 1; + } DEBUG((" in xrdp_tcp_recv, gota get %d bytes\n\r", len)); init_stream(s, len); while (len > 0) @@ -78,6 +83,7 @@ int xrdp_tcp_recv(struct xrdp_tcp* self, struct stream* s, int len) } else if (rcvd == 0) { + self->sck_closed = 1; DEBUG((" error = 0 in xrdp_tcp_recv socket %d\n\r", self->sck)); return 1; } @@ -99,6 +105,11 @@ int xrdp_tcp_send(struct xrdp_tcp* self, struct stream* s) int total; int sent; + if (self->sck_closed) + { + DEBUG((" in xrdp_tcp_send, sck closed\n\r")); + return 1; + } len = s->end - s->data; DEBUG((" in xrdp_tcp_send, gota send %d bytes\n\r", len)); total = 0; @@ -123,6 +134,7 @@ int xrdp_tcp_send(struct xrdp_tcp* self, struct stream* s) } else if (sent == 0) { + self->sck_closed = 1; DEBUG((" error = 0 in xrdp_tcp_send socket %d\n\r", self->sck)); return 1; } diff --git a/xrdp/xrdp_types.h b/xrdp/xrdp_types.h index 03fa7a69..2036b154 100644 --- a/xrdp/xrdp_types.h +++ b/xrdp/xrdp_types.h @@ -125,6 +125,7 @@ struct xrdp_pen struct xrdp_tcp { int sck; + int sck_closed; struct xrdp_iso* iso_layer; /* owner */ };