From 6803bfe9d5b9f52215c2aecc25cd9ab9a22c07e3 Mon Sep 17 00:00:00 2001 From: Vic Lee Date: Tue, 9 Feb 2010 22:05:13 +0800 Subject: [PATCH] Avoid 100% CPU usage when calling ReadFromRFBServer and no available bytes to read Signed-off-by: Vic Lee Signed-off-by: Christian Beier --- libvncclient/sockets.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c index e9a4b53..a4caaa5 100644 --- a/libvncclient/sockets.c +++ b/libvncclient/sockets.c @@ -150,6 +150,11 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) errno=WSAGetLastError(); #endif if (errno == EWOULDBLOCK || errno == EAGAIN) { +#ifndef WIN32 + usleep (10000); +#else + Sleep (10); +#endif /* TODO: ProcessXtEvents(); */ @@ -191,6 +196,11 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) errno=WSAGetLastError(); #endif if (errno == EWOULDBLOCK || errno == EAGAIN) { +#ifndef WIN32 + usleep (10000); +#else + Sleep (10); +#endif /* TODO: ProcessXtEvents(); */