diff options
author | Petr Stetiar <ynezz@true.cz> | 2011-07-20 12:36:00 +0400 |
---|---|---|
committer | Petr Stetiar <ynezz@true.cz> | 2011-07-20 12:44:38 +0400 |
commit | 8bb6c031b251f74afba13fbfc1ad6d2da16ef174 (patch) | |
tree | 1561ce91587a830492bddee6734d270834b35e6e | |
parent | b05747b55ccea8d2f2b830f89d3c0eb622d66784 (diff) |
libfreerdp-core: use portable usleep instead of nanosleep
Signed-off-by: Petr Stetiar <ynezz@true.cz>
-rw-r--r-- | include/freerdp/utils/usleep.h | 25 | ||||
-rw-r--r-- | libfreerdp-core/crypto/openssl.c | 11 | ||||
-rw-r--r-- | libfreerdp-utils/usleep.c | 45 |
3 files changed, 73 insertions, 8 deletions
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 <ynezz@true.cz> + + 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 <freerdp/types/base.h> #include <freerdp/utils/memory.h> +#include <freerdp/utils/usleep.h> #include <freerdp/constants/constants.h> -#include <time.h> #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 <ynezz@true.cz> + + 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 <winsock2.h> +#endif + +#include <time.h> + +#include <freerdp/types/base.h> +#include <freerdp/utils/usleep.h> + +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 +} |