From 8bb6c031b251f74afba13fbfc1ad6d2da16ef174 Mon Sep 17 00:00:00 2001 From: Petr Stetiar Date: Wed, 20 Jul 2011 10:36:00 +0200 Subject: libfreerdp-core: use portable usleep instead of nanosleep Signed-off-by: Petr Stetiar --- include/freerdp/utils/usleep.h | 25 ++++++++++++++++++++++ libfreerdp-core/crypto/openssl.c | 11 +++------- libfreerdp-utils/usleep.c | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 include/freerdp/utils/usleep.h create mode 100644 libfreerdp-utils/usleep.c diff --git a/include/freerdp/utils/usleep.h b/include/freerdp/utils/usleep.h new file mode 100644 index 0000000..75ff5a9 --- /dev/null +++ b/include/freerdp/utils/usleep.h @@ -0,0 +1,25 @@ +/* + FreeRDP: A Remote Desktop Protocol client. + usleep implementation + + Copyright 2011 Petr Stetiar + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef __UTILS_USLEEP_H +#define __UTILS_USLEEP_H + +void freerdp_usleep(uint32 delay); + +#endif /* __UTILS_USLEEP_H */ diff --git a/libfreerdp-core/crypto/openssl.c b/libfreerdp-core/crypto/openssl.c index 507288c..e85b4a0 100644 --- a/libfreerdp-core/crypto/openssl.c +++ b/libfreerdp-core/crypto/openssl.c @@ -21,8 +21,8 @@ #include "crypto.h" #include #include +#include #include -#include #include "tls.h" #include "crypto/openssl.h" @@ -351,7 +351,6 @@ struct rdp_tls { SSL_CTX * ctx; SSL * ssl; - struct timespec ts; }; RD_BOOL @@ -431,10 +430,6 @@ tls_new(void) SSL_CTX_set_options(tls->ctx, SSL_OP_ALL); - /* a small 0.1ms delay when network blocking happens. */ - tls->ts.tv_sec = 0; - tls->ts.tv_nsec = 100000; - return tls; } @@ -522,7 +517,7 @@ tls_write(rdpTls * tls, char* b, int length) break; case SSL_ERROR_WANT_WRITE: - nanosleep(&tls->ts, NULL); + freerdp_usleep(1000); break; default: @@ -551,7 +546,7 @@ tls_read(rdpTls * tls, char* b, int length) break; case SSL_ERROR_WANT_READ: - nanosleep(&tls->ts, NULL); + freerdp_usleep(1000); break; default: diff --git a/libfreerdp-utils/usleep.c b/libfreerdp-utils/usleep.c new file mode 100644 index 0000000..efc13fc --- /dev/null +++ b/libfreerdp-utils/usleep.c @@ -0,0 +1,45 @@ +/* + FreeRDP: A Remote Desktop Protocol client. + usleep implementation + + Copyright 2011 Petr Stetiar + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifdef _WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include +#endif + +#include + +#include +#include + +void freerdp_usleep(uint32 delay) +{ +#ifdef WIN32 + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = delay; + select(0, NULL, NULL, NULL, &tv); +#else + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = delay * 1000; + nanosleep(&ts, NULL); +#endif +} -- cgit v1.2.3