From f9e6578ed9332c3bb0fab40d703058ad11988b83 Mon Sep 17 00:00:00 2001 From: jsorg71 Date: Sat, 9 Dec 2006 20:53:48 +0000 Subject: [PATCH] removed sleep calls from xrdp_tcp --- common/os_calls.c | 25 +++++++++++++++++++++++++ common/os_calls.h | 4 ++++ libxrdp/xrdp_tcp.c | 4 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index c48fe99e..bd2480e8 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -459,6 +459,31 @@ g_tcp_can_send(int sck, int millis) return 0; } +/*****************************************************************************/ +/* wait 'millis' milliseconds for the socket to be able to receive */ +/* returns boolean */ +int +g_tcp_can_recv(int sck, int millis) +{ + fd_set rfds; + struct timeval time; + int rv; + + time.tv_sec = millis / 1000; + time.tv_usec = (millis * 1000) % 1000000; + FD_ZERO(&rfds); + if (sck > 0) + { + FD_SET(((unsigned int)sck), &rfds); + rv = select(sck + 1, &rfds, 0, 0, &time); + if (rv > 0) + { + return 1; + } + } + return 0; +} + /*****************************************************************************/ int g_tcp_select(int sck1, int sck2) diff --git a/common/os_calls.h b/common/os_calls.h index a833569a..caabd1e8 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -76,6 +76,10 @@ g_tcp_send(int sck, const void* ptr, int len, int flags); int g_tcp_last_error_would_block(int sck); int +g_tcp_can_send(int sck, int millis); +int +g_tcp_can_recv(int sck, int millis); +int g_tcp_select(int sck1, int sck2); void g_sleep(int msecs); diff --git a/libxrdp/xrdp_tcp.c b/libxrdp/xrdp_tcp.c index c3629a46..1d1effc2 100644 --- a/libxrdp/xrdp_tcp.c +++ b/libxrdp/xrdp_tcp.c @@ -72,7 +72,7 @@ xrdp_tcp_recv(struct xrdp_tcp* self, struct stream* s, int len) { if (g_tcp_last_error_would_block(self->sck)) { - g_sleep(1); + g_tcp_can_recv(self->sck, 10); } else { @@ -121,7 +121,7 @@ xrdp_tcp_send(struct xrdp_tcp* self, struct stream* s) { if (g_tcp_last_error_would_block(self->sck)) { - g_sleep(1); + g_tcp_can_send(self->sck, 10); } else {