if sck is closed, don't write or read it again, other small fixes

This commit is contained in:
jsorg71 2005-02-04 03:35:12 +00:00
parent 0aff0efb52
commit 63c49195a6
4 changed files with 29 additions and 1 deletions

View File

@ -34,6 +34,8 @@ THREAD_RV THREAD_CC xrdp_listen_run(void* in_val)
return 0; return 0;
} }
//#define CLEAN_CLOSE
/*****************************************************************************/ /*****************************************************************************/
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -42,15 +44,23 @@ int main(int argc, char** argv)
g_init_system(); g_init_system();
rv = 0; rv = 0;
g_listen = xrdp_listen_create(); g_listen = xrdp_listen_create();
#ifdef CLEAN_CLOSE
if (g_thread_create(xrdp_listen_run, 0) == 0) if (g_thread_create(xrdp_listen_run, 0) == 0)
{ {
g_getchar(); g_getchar();
g_set_term(1); g_set_term(1);
while (g_listen->status > 0) while (g_listen->status > 0)
{
g_sleep(100); g_sleep(100);
}
} }
else else
{
rv = 1; rv = 1;
}
#else
xrdp_listen_main_loop(g_listen);
#endif
xrdp_listen_delete(g_listen); xrdp_listen_delete(g_listen);
g_exit_system(); g_exit_system();
return rv; return rv;

View File

@ -139,7 +139,12 @@ int xrdp_listen_main_loop(struct xrdp_listen* self)
self->status = 1; self->status = 1;
self->sck = g_tcp_socket(); self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck); 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); error = g_tcp_listen(self->sck);
if (error == 0) if (error == 0)
{ {

View File

@ -54,6 +54,11 @@ int xrdp_tcp_recv(struct xrdp_tcp* self, struct stream* s, int len)
{ {
int rcvd; 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)); DEBUG((" in xrdp_tcp_recv, gota get %d bytes\n\r", len));
init_stream(s, len); init_stream(s, len);
while (len > 0) while (len > 0)
@ -78,6 +83,7 @@ int xrdp_tcp_recv(struct xrdp_tcp* self, struct stream* s, int len)
} }
else if (rcvd == 0) else if (rcvd == 0)
{ {
self->sck_closed = 1;
DEBUG((" error = 0 in xrdp_tcp_recv socket %d\n\r", self->sck)); DEBUG((" error = 0 in xrdp_tcp_recv socket %d\n\r", self->sck));
return 1; return 1;
} }
@ -99,6 +105,11 @@ int xrdp_tcp_send(struct xrdp_tcp* self, struct stream* s)
int total; int total;
int sent; int sent;
if (self->sck_closed)
{
DEBUG((" in xrdp_tcp_send, sck closed\n\r"));
return 1;
}
len = s->end - s->data; len = s->end - s->data;
DEBUG((" in xrdp_tcp_send, gota send %d bytes\n\r", len)); DEBUG((" in xrdp_tcp_send, gota send %d bytes\n\r", len));
total = 0; total = 0;
@ -123,6 +134,7 @@ int xrdp_tcp_send(struct xrdp_tcp* self, struct stream* s)
} }
else if (sent == 0) else if (sent == 0)
{ {
self->sck_closed = 1;
DEBUG((" error = 0 in xrdp_tcp_send socket %d\n\r", self->sck)); DEBUG((" error = 0 in xrdp_tcp_send socket %d\n\r", self->sck));
return 1; return 1;
} }

View File

@ -125,6 +125,7 @@ struct xrdp_pen
struct xrdp_tcp struct xrdp_tcp
{ {
int sck; int sck;
int sck_closed;
struct xrdp_iso* iso_layer; /* owner */ struct xrdp_iso* iso_layer; /* owner */
}; };