From 60a2ece48f11349f3e9006cb802d9bed2ded68ee Mon Sep 17 00:00:00 2001 From: Brian Hinz Date: Wed, 14 Mar 2012 04:15:17 +0000 Subject: [PATCH] pass correct timeout value to selector. limit pixel depth to 24 (OS X defaults to 32). Increase write buffer size to match CXX value. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4867 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- java/com/tigervnc/network/SocketDescriptor.java | 8 +++++++- java/com/tigervnc/rdr/FdInStream.java | 6 +++--- java/com/tigervnc/rdr/FdOutStream.java | 11 +++++------ java/com/tigervnc/vncviewer/PixelBufferImage.java | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/java/com/tigervnc/network/SocketDescriptor.java b/java/com/tigervnc/network/SocketDescriptor.java index 2a4c6d81..cb478127 100644 --- a/java/com/tigervnc/network/SocketDescriptor.java +++ b/java/com/tigervnc/network/SocketDescriptor.java @@ -83,10 +83,16 @@ public class SocketDescriptor extends SocketChannel synchronized public int select(int interestOps, int timeout) throws Exception { int n; try { - n = selector.select(timeout); + if (timeout == 0) { + n = selector.selectNow(); + } else { + n = selector.select(timeout); + } } catch (java.io.IOException e) { throw new Exception(e.toString()); } + if (n == 0) + return -1; Set keys = selector.selectedKeys(); Iterator iter = keys.iterator(); while (iter.hasNext()) { diff --git a/java/com/tigervnc/rdr/FdInStream.java b/java/com/tigervnc/rdr/FdInStream.java index 245a6340..ea81388f 100644 --- a/java/com/tigervnc/rdr/FdInStream.java +++ b/java/com/tigervnc/rdr/FdInStream.java @@ -136,7 +136,7 @@ public class FdInStream extends InStream { protected int readWithTimeoutOrCallback(byte[] buf, int bufPtr, int len, boolean wait) { long before = 0; - long timeout; + int timeout; if (timing) before = System.nanoTime(); @@ -146,13 +146,13 @@ public class FdInStream extends InStream { if (!wait) { timeout = 0; } else if (timeoutms != -1) { - timeout = (long)timeoutms; + timeout = timeoutms; } else { timeout = 0; } try { - n = fd.select(SelectionKey.OP_READ, timeoutms); + n = fd.select(SelectionKey.OP_READ, timeout); } catch (Exception e) { throw new SystemException("select:"+e.toString()); } diff --git a/java/com/tigervnc/rdr/FdOutStream.java b/java/com/tigervnc/rdr/FdOutStream.java index d2e95ea0..c7767245 100644 --- a/java/com/tigervnc/rdr/FdOutStream.java +++ b/java/com/tigervnc/rdr/FdOutStream.java @@ -24,7 +24,7 @@ import java.nio.channels.SelectionKey; public class FdOutStream extends OutStream { - static final int defaultBufSize = 8192; + static final int defaultBufSize = 16384; static final int minBulkSize = 1024; public FdOutStream(FileDescriptor fd_, boolean blocking_, int timeoutms_, int bufSize_) @@ -79,7 +79,7 @@ public class FdOutStream extends OutStream { } // Proper timeout - //throw TimedOut(); + throw new TimedOut(); } sentUpTo += n; @@ -93,19 +93,19 @@ public class FdOutStream extends OutStream { private int writeWithTimeout(byte[] data, int dataPtr, int length, int timeoutms) { - long timeout; + int timeout; int n; do { if (timeoutms != -1) { - timeout = (long)timeoutms; + timeout = timeoutms; } else { timeout = 0; } try { - n = fd.select(SelectionKey.OP_WRITE, timeoutms); + n = fd.select(SelectionKey.OP_WRITE, timeout); } catch (java.lang.Exception e) { System.out.println(e.toString()); throw new Exception(e.toString()); @@ -116,7 +116,6 @@ public class FdOutStream extends OutStream { try { n = fd.write(data, dataPtr, length); } catch (java.lang.Exception e) { - System.out.println("read:"+e.toString()); throw new Exception(e.toString()); } diff --git a/java/com/tigervnc/vncviewer/PixelBufferImage.java b/java/com/tigervnc/vncviewer/PixelBufferImage.java index 5f666487..e77f460e 100644 --- a/java/com/tigervnc/vncviewer/PixelBufferImage.java +++ b/java/com/tigervnc/vncviewer/PixelBufferImage.java @@ -74,7 +74,7 @@ public class PixelBufferImage extends PixelBuffer PixelFormat pf; cm = tk.getColorModel(); if (cm.getColorSpace().getType() == java.awt.color.ColorSpace.TYPE_RGB) { - int depth = cm.getPixelSize(); + int depth = ((cm.getPixelSize() > 24) ? 24 : cm.getPixelSize()); int bpp = (depth > 16 ? 32 : (depth > 8 ? 16 : 8)); ByteOrder byteOrder = ByteOrder.nativeOrder(); boolean bigEndian = (byteOrder == ByteOrder.BIG_ENDIAN ? true : false); -- 2.39.5