libfreerdp-utils: started sleep utils
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Tue, 16 Aug 2011 20:04:28 +0000 (16:04 -0400)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Tue, 16 Aug 2011 20:04:28 +0000 (16:04 -0400)
include/freerdp/utils/sleep.h [new file with mode: 0644]
libfreerdp-core/transport.c
libfreerdp-core/transport.h
libfreerdp-utils/CMakeLists.txt
libfreerdp-utils/sleep.c [new file with mode: 0644]
libfreerdp-utils/thread.c

diff --git a/include/freerdp/utils/sleep.h b/include/freerdp/utils/sleep.h
new file mode 100644 (file)
index 0000000..914f87b
--- /dev/null
@@ -0,0 +1,27 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Client
+ * Sleep Utils
+ *
+ * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * 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 __SLEEP_UTILS_H
+#define __SLEEP_UTILS_H
+
+#include <freerdp/types.h>
+
+void freerdp_usleep(uint32 useconds);
+
+#endif /* __SLEEP_UTILS_H */
index b6abd1e..3631a82 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <freerdp/utils/sleep.h>
 #include <freerdp/utils/stream.h>
 #include <freerdp/utils/memory.h>
 #include <freerdp/utils/hexdump.h>
@@ -135,7 +136,7 @@ int transport_read(rdpTransport* transport, STREAM* s)
 
                if (status == 0 && transport->blocking)
                {
-                       nanosleep(&transport->ts, NULL);
+                       freerdp_usleep(transport->usleep_interval);
                        continue;
                }
 
@@ -198,7 +199,7 @@ int transport_write(rdpTransport* transport, STREAM* s)
                if (status == 0)
                {
                        /* blocking while sending */
-                       nanosleep(&transport->ts, NULL);
+                       freerdp_usleep(transport->usleep_interval);
 
                        /* when sending is blocked in nonblocking mode, the receiving buffer should be checked */
                        if (!transport->blocking)
@@ -302,8 +303,7 @@ rdpTransport* transport_new(rdpSettings* settings)
                transport->settings = settings;
 
                /* a small 0.1ms delay when transport is blocking. */
-               transport->ts.tv_sec = 0;
-               transport->ts.tv_nsec = 100000;
+               transport->usleep_interval = 100;
 
                /* receive buffer for non-blocking read. */
                transport->recv_buffer = stream_new(BUFFER_SIZE);
index 0f591ab..9b02426 100644 (file)
@@ -59,7 +59,7 @@ struct rdp_transport
        struct rdp_tls* tls;
        struct rdp_settings* settings;
        struct rdp_credssp* credssp;
-       struct timespec ts;
+       uint32 usleep_interval;
        void* recv_extra;
        STREAM* recv_buffer;
        TransportRecv recv_callback;
index bde53bb..d944623 100644 (file)
@@ -33,6 +33,7 @@ set(FREERDP_UTILS_SRCS
        profiler.c
        rail.c
        semaphore.c
+       sleep.c
        stopwatch.c
        stream.c
        svc_plugin.c
diff --git a/libfreerdp-utils/sleep.c b/libfreerdp-utils/sleep.c
new file mode 100644 (file)
index 0000000..8fd004e
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Client
+ * Sleep Utils
+ *
+ * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
+ *
+ * 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.
+ */
+
+#include <freerdp/utils/sleep.h>
+
+#define _XOPEN_SOURCE 500
+
+#include <time.h>
+#include <unistd.h>
+
+void freerdp_usleep(uint32 useconds)
+{
+       usleep(useconds);
+}
index 0964b3b..cfa4328 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
+#include <freerdp/utils/sleep.h>
 #include <freerdp/utils/memory.h>
 #include <freerdp/utils/thread.h>
 
-#ifdef _WIN32
-#include <Windows.h>
-
-struct timespec
-{
-       uint64 tv_sec;
-       uint64 tv_nsec;
-};
-#endif
-
 freerdp_thread* freerdp_thread_new(void)
 {
        freerdp_thread* thread;
@@ -69,25 +60,12 @@ void freerdp_thread_stop(freerdp_thread* thread)
 {
        int i = 0;
 
-#ifndef _WIN32
-       struct timespec ts;
-       ts.tv_sec = 0;
-       ts.tv_nsec = 10000000;
-#else
-       DWORD dwMilliseconds;
-       dwMilliseconds = 10000;
-#endif
-
        wait_obj_set(thread->signals[0]);
 
        while (thread->status > 0 && i < 1000)
        {
                i++;
-#ifndef _WIN32
-               nanosleep(&ts, NULL);
-#else
-               SleepEx(dwMilliseconds, 0);
-#endif
+               freerdp_usleep(100);
        }
 
        for (i = 0; i < thread->num_signals; i++)