[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

Re: rdesktop X Windows patches




I have made some patches to reduce the latency in the system.
Previously, tcp_recv timed out on select after 1 second so it
could process the X events. I have changed the select to return
on both the RDP and the X sockets. Performance is (in my opinion)
much improved.

the patch is below. it's kinda messy because i'm not good at making patches.
it is patched on the 1.0.0 sources after applying the 16bit display patch
(the first one only, as far as i can recall).

tim

--- rdesktop-1.0.0/tcp.c        Sat Sep 16 13:07:55 2000
+++ tcp.c       Mon Oct 23 12:55:39 2000
@@ -72,6 +72,7 @@
        int ret, rcvd = 0;
        struct timeval tv;
        fd_set rfds;
+       int uisocket,maxsocket;
 
        if (length > in.size)
        {
@@ -83,28 +84,42 @@
 
        while (length > 0)
        {
-               ui_process_events();
 
+               maxsocket = sock;
                FD_ZERO(&rfds);
                FD_SET(sock, &rfds);
-               tv.tv_sec = 0;
-               tv.tv_usec = 100;
+               if ((uisocket = ui_select_fd()) != -1) {                  
+                 FD_SET(uisocket,&rfds);
+                 if (uisocket > sock)
+                   maxsocket = uisocket;
+               }
+               tv.tv_sec = 100;
+               tv.tv_usec = 50000; 
 
-               ret = select(sock+1, &rfds, NULL, NULL, &tv);
+               ret = select(maxsocket+1, &rfds, NULL, NULL, &tv);
 
-               if (ret)
+               if (ret == -1) {
+                 STATUS("tcp_recv: select: %s\n",strerror(errno));
+               }
+
+               else if (ret)
                {
+                   if (FD_ISSET(sock,&rfds)) {
                        rcvd = read(sock, in.end, length);
 
                        if (rcvd <= 0)
                        {
-                               STATUS("read: %s\n", strerror(errno));
-                               return NULL;
+                         STATUS("tcp_recv: read: %s\n",strerror(errno));
+                         return NULL;
                        }
 
                        in.end += rcvd;
                        length -= rcvd;
-               }
+                   }
+                   else if (uisocket != -1 && FD_ISSET(uisocket,&rfds)) {
+                     ui_process_events();
+                   }
+               }
        }
 
        return &in;
--- rdesktop-1.0.0/xwin.c       Wed Oct 18 15:19:17 2000
+++ xwin.c      Mon Oct 23 12:35:32 2000
@@ -51,6 +51,16 @@
 }
 
 
+int ui_select_fd() {
+  if (display==NULL) {
+    return -1;
+  }
+  else {
+    return XConnectionNumber(display);
+  }
+}
+
+
 BOOL ui_create_window(char *title)
 {
        Screen *screen;


--- rdesktop-1.0.0/proto.h      Wed Oct 18 15:19:17 2000
+++ proto.h     Mon Oct 23 12:36:29 2000
@@ -67,6 +67,7 @@
 void cache_put_desktop(uint32 offset, int cx, int cy, int scanline, int
bytes_per_pixel, uint8 *data);
 
 /* xwin.c */
+int ui_select_fd();
 BOOL ui_create_window(char *title);
 void ui_destroy_window(void);
 void ui_process_events(void);