diff options
author | Brian Hinz <bphinz@users.sourceforge.net> | 2012-02-08 04:21:43 +0000 |
---|---|---|
committer | Brian Hinz <bphinz@users.sourceforge.net> | 2012-02-08 04:21:43 +0000 |
commit | 8d37f2054b6da02957b12d02aaf96dd5eecc89c7 (patch) | |
tree | 8ff59055186d4e92c68d7e2cc1e624399bf0cdc8 /java/com/tigervnc/network/SocketDescriptor.java | |
parent | 4a611ce4d656bd1a3c9c6bdf6073459c1044a022 (diff) | |
download | tigervnc-8d37f2054b6da02957b12d02aaf96dd5eecc89c7.tar.gz tigervnc-8d37f2054b6da02957b12d02aaf96dd5eecc89c7.zip |
corrected return value for read function to match unix socket read. updated exception handling to match C code.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4846 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java/com/tigervnc/network/SocketDescriptor.java')
-rw-r--r-- | java/com/tigervnc/network/SocketDescriptor.java | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/java/com/tigervnc/network/SocketDescriptor.java b/java/com/tigervnc/network/SocketDescriptor.java index 375b0335..1998ca5b 100644 --- a/java/com/tigervnc/network/SocketDescriptor.java +++ b/java/com/tigervnc/network/SocketDescriptor.java @@ -19,7 +19,6 @@ package com.tigervnc.network; import java.io.IOException; -import java.lang.Exception; import java.net.SocketAddress; import java.nio.*; @@ -29,6 +28,8 @@ import java.nio.channels.spi.SelectorProvider; import java.util.Set; import java.util.Iterator; +import com.tigervnc.rdr.Exception; + public class SocketDescriptor extends SocketChannel implements FileDescriptor { @@ -38,7 +39,7 @@ public class SocketDescriptor extends SocketChannel channel = SocketChannel.open(); channel.configureBlocking(false); selector = Selector.open(); - } catch (java.io.IOException e) { + } catch (IOException e) { throw new Exception(e.toString()); } try { @@ -54,11 +55,10 @@ public class SocketDescriptor extends SocketChannel try { n = channel.read(b); } catch (java.io.IOException e) { - System.out.println(e.toString()); throw new Exception(e.toString()); } - //if (n == 0) - // throw new Exception; + if (n <= 0) + return (n == 0) ? -1 : 0; b.flip(); b.get(buf, bufPtr, n); b.clear(); @@ -74,7 +74,6 @@ public class SocketDescriptor extends SocketChannel try { n = channel.write(b); } catch (java.io.IOException e) { - System.out.println(e.toString()); throw new Exception(e.toString()); } b.clear(); @@ -85,8 +84,7 @@ public class SocketDescriptor extends SocketChannel int n; try { n = selector.select(timeout); - } catch (Exception e) { - System.out.println(e.toString()); + } catch (java.io.IOException e) { throw new Exception(e.toString()); } Set keys = selector.selectedKeys(); @@ -104,13 +102,12 @@ public class SocketDescriptor extends SocketChannel return n; } - public int write(ByteBuffer buf) throws IOException { + public int write(ByteBuffer buf) throws Exception { int n = 0; try { n = channel.write(buf); } catch (java.io.IOException e) { - System.out.println(e.toString()); - throw e; + throw new Exception(e.toString()); } return n; } @@ -122,7 +119,7 @@ public class SocketDescriptor extends SocketChannel try { n = channel.write(buf, offset, length); } catch (java.io.IOException e) { - System.out.println(e.toString()); + throw new Exception(e.toString()); } return n; } @@ -132,8 +129,7 @@ public class SocketDescriptor extends SocketChannel try { n = channel.read(buf); } catch (java.io.IOException e) { - System.out.println(e.toString()); - throw e; + throw new Exception(e.toString()); } return n; } @@ -145,7 +141,7 @@ public class SocketDescriptor extends SocketChannel try { n = channel.read(buf, offset, length); } catch (java.io.IOException e) { - System.out.println(e.toString()); + throw new Exception(e.toString()); } return n; } |